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

1#!/usr/bin/env python

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

3

4"""显示主题定义"""

5

6 from rich.theme import Theme

7

8# 默认主题（适合大多数终端）

9 DEFAULT_THEME = Theme({

10 # 基础颜色

11 "info": "cyan",

12 "warning": "yellow",

13 "error": "red bold",

14 "success": "green",

15

16 # 面板和边框

17 "panel.border": "blue",

18 "panel.title": "bold cyan",

19

20 # 代码相关

21 "code": "white",

22 "syntax.keyword": "magenta bold",

23 "syntax.string": "green",

24 "syntax.number": "cyan",

25 "syntax.comment": "bright_black",

26

27 # 任务状态

28 "task.running": "yellow",

29 "task.success": "green",

30 "task.error": "red",

31

32 # 表格

33 "table.header": "bold cyan",

34 "table.cell": "white",

35})

36

37# 深色主题（针对深色背景优化）

38 DARK_THEME = Theme({

39 # 基础颜色

40 "info": "bright_cyan",

41 "warning": "bright_yellow",

42 "error": "bright_red bold",

43 "success": "bright_green",

44

45 # 面板和边框

46 "panel.border": "bright_blue",

47 "panel.title": "bold bright_cyan",

48

49 # 代码相关

50 "code": "bright_white",

51 "syntax.keyword": "bright_magenta bold",

52 "syntax.string": "bright_green",

53 "syntax.number": "bright_cyan",

54 "syntax.comment": "bright_black",

55

56 # 任务状态

57 "task.running": "bright_yellow",

58 "task.success": "bright_green",

59 "task.error": "bright_red",

60

61 # 表格

62 "table.header": "bold bright_cyan",

63 "table.cell": "bright_white",

64})

65

66# 浅色主题（针对浅色背景优化）

67 LIGHT_THEME = Theme({

68 # 基础颜色

69 "info": "blue",

70 "warning": "dark_orange",

71 "error": "red bold",

72 "success": "dark_green",

73

74 # 面板和边框

75 "panel.border": "blue",

76 "panel.title": "bold blue",

77

78 # 代码相关

79 "code": "black",

80 "syntax.keyword": "blue bold",

81 "syntax.string": "dark_green",

82 "syntax.number": "dark_cyan",

83 "syntax.comment": "bright_black",

84

85 # 任务状态

86 "task.running": "dark_orange",

87 "task.success": "dark_green",

88 "task.error": "red",

89

90 # 表格

91 "table.header": "bold blue",

92 "table.cell": "black",

93})

94

95# 单色主题（只使用基本颜色，兼容性最好）

96 MONO_THEME = Theme({

97 # 基础颜色

98 "info": "white",

99 "warning": "white",

100 "error": "white bold",

101 "success": "white",

102

103 # 面板和边框

104 "panel.border": "white",

105 "panel.title": "bold white",

106

107 # 代码相关

108 "code": "white",

109 "syntax.keyword": "white bold",

110 "syntax.string": "white",

111 "syntax.number": "white",

112 "syntax.comment": "bright_black",

113

114 # 任务状态

115 "task.running": "white",

116 "task.success": "white",

117 "task.error": "white bold",

118

119 # 表格

120 "table.header": "bold white",

121 "table.cell": "white",

122})

123

124# 主题映射表

125 THEMES = {

126 "default": DEFAULT_THEME,

127 "dark": DARK_THEME,

128 "light": LIGHT_THEME,

129 "mono": MONO_THEME,

130}

131

132 def get_theme(theme_name: str) -> Theme:

133 """获取指定名称的主题

134

135 Args:

136 theme_name: 主题名称 ("default", "dark", "light", "mono")

137

138 Returns:

139 Rich主题对象，如果主题名不存在则返回默认主题

140 """

141 return THEMES.get(theme_name, DEFAULT_THEME)