Coverage for aipyapp/cli/command/cmd_display.py: 0%

1 from rich import print

2 from rich.table import Table

3

4 from ... import T

5 from .base_parser import ParserCommand

6 from .utils import print_table

7

8 class DisplayCommand(ParserCommand):

9 name = 'display'

10 description = T('Display style operations')

11

12 def add_subcommands(self, subparsers):

13 subparsers.add_parser('list', help=T('List available display styles'))

14

15 # 为 set 子命令添加参数

16 ctx = self.manager.context

17 set_parser = subparsers.add_parser('use', help=T('Set display style'))

18 set_parser.add_argument('style', choices=ctx.tm.display_manager.get_available_styles(), help='Display style to set')

19

20 def cmd_list(self, args, ctx):

21 """列出可用的显示风格"""

22 styles = ctx.tm.display_manager.get_available_styles()

23 info = ctx.tm.display_manager.get_plugin_info()

24

25 rows = []

26 for style in styles:

27 description = info.get(style, '')

28 rows.append([style, description])

29

30 print_table(rows, headers=[T('Style'), T('Description')], title=T('Available Display Styles'))

31

32 def cmd_use(self, args, ctx):

33 """设置显示风格"""

34 success = ctx.tm.display_manager.set_style(args.style)

35 if success:

36 print(f"[green]{T('Display style changed to')}: {T(args.style)}[/green]")

37 else:

38 print(f"[red]{T('Invalid display style')}: {T(args.style)}[/red]")

39 print(f"[yellow]{T('Use /display list to see available styles')}[/yellow]")

40

41 def cmd(self, args, ctx):

42 self.cmd_list(args, ctx)