Coverage for aipyapp/display/base_rich.py: 0%

1#! /usr/bin/env python3

2# -*- coding: utf-8 -*-

3#

4# Copyright (c) 2025, Aipy.

5#

6# This program is free software: you can redistribute it and/or modify

7# it under the terms of the GNU General Public License as published by

8# the Free Software Foundation, either version 3 of the License, or

9# (at your option) any later version.

10

11 from .base import DisplayPlugin

12 from .. import T

13

14 class RichDisplayPlugin(DisplayPlugin):

15 def save(self, path: str, clear: bool = False, code_format: str = None):

16 """保存输出"""

17 if self.console.record:

18 self.console.save_html(path, clear=clear, code_format=code_format)

19

20 # 新增：输入输出相关方法

21 def print(self, message: str, style: str = None):

22 """显示消息"""

23 if style:

24 self.console.print(message, style=style)

25 else:

26 self.console.print(message)

27

28 def input(self, prompt: str) -> str:

29 """获取用户输入"""

30 return self.console.input(prompt)

31

32 def confirm(self, prompt, default="n", auto=None):

33 """确认操作"""

34 if auto in (True, False):

35 self.print(f"✅ {T('Auto confirm')}")

36 return auto

37 while True:

38 response = self.input(prompt).strip().lower()

39 if not response:

40 response = default

41 if response in ["y", "n"]:

42 break

43 return response == "y"