Coverage for src / library_skills / ui.py: 100%

96 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-11-23 00:26 +0000

1from pathlib import Path 1KLMNOPQRSTU

2 

3from rich.console import Console 1KLMNOPQRSTU

4from rich.table import Table 1KLMNOPQRSTU

5from rich.theme import Theme 1KLMNOPQRSTU

6from rich_toolkit import RichToolkit 1KLMNOPQRSTU

7from rich_toolkit.styles import MinimalStyle 1KLMNOPQRSTU

8 

9RICH_THEME = { 1KLMNOPQRSTU

10 "active": "green", 

11 "badge.action.install": "bold white on green", 

12 "badge.action.remove": "bold white on red", 

13 "badge.action.repair": "bold white on blue", 

14 "badge.attention": "bold white on red", 

15 "badge.context": "bold white on dark_cyan", 

16 "badge.hint": "black on yellow", 

17 "badge.result": "bold white on green", 

18 "badge.status": "bold white on blue", 

19 "badge.warning": "bold white on dark_orange", 

20 "cancelled": "red italic", 

21 "error": "red", 

22 "hint": "dim", 

23 "placeholder": "grey62", 

24 "placeholder.cancelled": "indian_red strike", 

25 "progress": "on green", 

26 "result": "white", 

27 "selected": "green", 

28 "status.broken": "red", 

29 "status.hand-authored": "dim", 

30 "status.name-mismatch": "yellow", 

31 "status.new": "green", 

32 "status.orphaned": "red", 

33 "status.outdated": "yellow", 

34 "status.up-to-date": "dim", 

35 "success": "green", 

36 "tag": "bold", 

37 "tag.title": "bold", 

38 "text": "white", 

39 "title.cancelled": "white", 

40 "title.error": "white", 

41 "warning": "yellow", 

42} 

43 

44console = Console(theme=Theme(RICH_THEME)) 1KLMNOPQRSTU

45 

46 

47def _console(override: Console | None = None) -> Console: 1KLMNOPQRSTU

48 return override or console 2@ [ B H . m d a e ( y f 4b,brb~ abbb5bcb{b|b}bdbeb~bNb) V Qb6b7b8byczcW X / Tb-bC ub{ Y p q r Z 0 1 2 ] ^ D I : n g b h * z i 9b.bsbfbgbhb!bibacbcccjbkbdcOb+ 3 Rb#b$b%bAcBc4 5 ; Ub/bE vb| 6 s t u 7 8 _ ` F J = o j c k , A l 'b:btblbmbnb(bobecfcgcpbqbhcPb- 9 Sb)b*b+bCcDc! # ? Vb;bG wb} $ v w x % '

49 

50 

51def get_toolkit(*, console: Console | None = None) -> RichToolkit: 1KLMNOPQRSTU

52 style = MinimalStyle(theme=RICH_THEME) 2,b-bicjckclc.b/bmcnc:b;bocpc

53 style.console = _console(console) 2,b-bicjckclc.b/bmcnc:b;bocpc

54 return RichToolkit(style=style) 2,b-bicjckclc.b/bmcnc:b;bocpc

55 

56 

57def print_line(*, console: Console | None = None) -> None: 1KLMNOPQRSTU

58 _console(console).print() 2@ [ B H . m d a e ( y f rb~ abbbcb) V W X / C { Y p q r Z 0 1 2 ] ^ D I : n g b h * z i sbfbgbhbib+ 3 4 5 ; E | 6 s t u 7 8 _ ` F J = o j c k , A l tblbmbnbob- 9 ! # ? G } $ v w x % '

59 

60 

61def print_title( 1KLMNOPQRSTU

62 title: str, 

63 *, 

64 console: Console | None = None, 

65 before: bool = True, 

66) -> None: 

67 target_console = _console(console) 1@[BH.mdae(yf)VWX/CYpqrZ012]^DI:ngbh*zi+345;E6stu78_`FJ=ojck,Al-9!#?G$vwx%'

68 if before: 1@[BH.mdae(yf)VWX/CYpqrZ012]^DI:ngbh*zi+345;E6stu78_`FJ=ojck,Al-9!#?G$vwx%'

69 target_console.print() 1@[BH.mdae(yf)VWX/CYpqrZ012]^DI:ngbh*zi+345;E6stu78_`FJ=ojck,Al-9!#?G$vwx%'

70 target_console.print(_badge(title, title)) 1@[BH.mdae(yf)VWX/CYpqrZ012]^DI:ngbh*zi+345;E6stu78_`FJ=ojck,Al-9!#?G$vwx%'

71 

72 

73def print_warning(message: str, *, console: Console | None = None) -> None: 1KLMNOPQRSTU

74 _console(console).print(f"{_badge('warning', 'Warning:')} {message}") 2. 4b/ { p q r xbybzbAb: 9b; | s t u BbCb= 'b? } v w x DbEb

75 

76 

77def print_hint(message: str, *, console: Console | None = None) -> None: 1KLMNOPQRSTU

78 _console(console).print(f"{_badge('hint', 'Tip:')} {message}") 2d a ~ abbbcb{ p q r xbybzbAbg b fbgbhbib| s t u BbCbj c lbmbnbob} v w x DbEb

79 

80 

81def print_message(message: str, *, console: Console | None = None) -> None: 1KLMNOPQRSTU

82 _console(console).print(message) 2@ [ H . m d a ( y rb~ abbbcb{b|b}b~b) Qbyczc/ C { p q r xbybzbAb] ^ I : n g b * z sbfbgbhbibacbcccdc+ RbAcBc; E | s t u BbCb_ ` J = o j c , A tblbmbnbobecfcgchc- SbCcDc? G } v w x DbEb

83 

84 

85def print_action_header( 1KLMNOPQRSTU

86 action: str, *, console: Console | None = None, before: bool = True 

87) -> None: 

88 target_console = _console(console) 2QbTb=b?b@b[bRbUb]b^bSbVb_b`b

89 if before: 2QbTb=b?b@b[bRbUb]b^bSbVb_b`b

90 target_console.print() 2QbTb=b?b@b[bRbUb]b^bSbVb_b`b

91 target_console.print(f"{_badge(f'action.{action}', action)}") 2QbTb=b?b@b[bRbUb]b^bSbVb_b`b

92 

93 

94def print_warnings(warnings: list[str], *, console: Console | None = None) -> None: 1KLMNOPQRSTU

95 for warning in warnings: 2@ [ B H . m d a e ( y f rb~ abbbcb{b|b}bdbeb~bNb) V W X / C { Y p q r Z xb0 yb1 zb2 Ab] ^ D I : n g b h * z i sbfbgbhbibacbcccjbkbdcOb+ 3 4 5 ; E | 6 s t u 7 Bb8 Cb_ ` F J = o j c k , A l tblbmbnbobecfcgcpbqbhcPb- 9 ! # ? G } $ v w x % Db' Eb

96 print_warning(warning, console=console) 2. / { xbybzbAb: ; | BbCb= ? } DbEb

97 

98 

99def context_table(rows: list[tuple[str, str]]) -> Table: 1KLMNOPQRSTU

100 table = Table.grid(padding=(0, 2), pad_edge=False) 1@[BH.mdae(yf)VWX/CYpqrZ012]^DI:ngbh*zi+345;E6stu78_`FJ=ojck,Al-9!#?G$vwx%'

101 table.add_column("Field", style="bold") 1@[BH.mdae(yf)VWX/CYpqrZ012]^DI:ngbh*zi+345;E6stu78_`FJ=ojck,Al-9!#?G$vwx%'

102 table.add_column("Value") 1@[BH.mdae(yf)VWX/CYpqrZ012]^DI:ngbh*zi+345;E6stu78_`FJ=ojck,Al-9!#?G$vwx%'

103 for label, value in rows: 1@[BH.mdae(yf)VWX/CYpqrZ012]^DI:ngbh*zi+345;E6stu78_`FJ=ojck,Al-9!#?G$vwx%'

104 table.add_row(label, value) 1@[BH.mdae(yf)VWX/CYpqrZ012]^DI:ngbh*zi+345;E6stu78_`FJ=ojck,Al-9!#?G$vwx%'

105 return table 1@[BH.mdae(yf)VWX/CYpqrZ012]^DI:ngbh*zi+345;E6stu78_`FJ=ojck,Al-9!#?G$vwx%'

106 

107 

108def skills_table(rows: list[tuple[str, str, str, str]]) -> Table: 1KLMNOPQRSTU

109 table = Table(show_header=True, header_style="bold", box=None) 2NbV W X Y Z 0 1 2 Ob3 4 5 6 7 8 Pb9 ! # $ % '

110 table.add_column("Skill", style="bold") 2NbV W X Y Z 0 1 2 Ob3 4 5 6 7 8 Pb9 ! # $ % '

111 table.add_column("Package") 2NbV W X Y Z 0 1 2 Ob3 4 5 6 7 8 Pb9 ! # $ % '

112 table.add_column("Version") 2NbV W X Y Z 0 1 2 Ob3 4 5 6 7 8 Pb9 ! # $ % '

113 table.add_column("Description") 2NbV W X Y Z 0 1 2 Ob3 4 5 6 7 8 Pb9 ! # $ % '

114 for row in rows: 2NbV W X Y Z 0 1 2 Ob3 4 5 6 7 8 Pb9 ! # $ % '

115 table.add_row(*row) 2NbV W X Y Z 0 1 2 Ob3 4 5 6 7 8 Pb9 ! # $ % '

116 return table 2NbV W X Y Z 0 1 2 Ob3 4 5 6 7 8 Pb9 ! # $ % '

117 

118 

119def status_table(rows: list[tuple[str, str, str, str, str]]) -> Table: 1KLMNOPQRSTU

120 table = Table(show_header=True, header_style="bold", box=None) 2B m d a e y f dbebp q r FbGbHbIbD n g b h z i jbkbs t u JbKbF o j c k A l pbqbv w x LbMb

121 table.add_column("Target") 2B m d a e y f dbebp q r FbGbHbIbD n g b h z i jbkbs t u JbKbF o j c k A l pbqbv w x LbMb

122 table.add_column("Skill", style="bold") 2B m d a e y f dbebp q r FbGbHbIbD n g b h z i jbkbs t u JbKbF o j c k A l pbqbv w x LbMb

123 table.add_column("Status") 2B m d a e y f dbebp q r FbGbHbIbD n g b h z i jbkbs t u JbKbF o j c k A l pbqbv w x LbMb

124 table.add_column("Path") 2B m d a e y f dbebp q r FbGbHbIbD n g b h z i jbkbs t u JbKbF o j c k A l pbqbv w x LbMb

125 table.add_column("Source") 2B m d a e y f dbebp q r FbGbHbIbD n g b h z i jbkbs t u JbKbF o j c k A l pbqbv w x LbMb

126 for target, skill, status, path, source in rows: 2B m d a e y f dbebp q r FbGbHbIbD n g b h z i jbkbs t u JbKbF o j c k A l pbqbv w x LbMb

127 table.add_row(target, skill, _styled_status(status), path, source) 2B m d a e y f dbebp q r FbGbHbIbD n g b h z i jbkbs t u JbKbF o j c k A l pbqbv w x LbMb

128 return table 2B m d a e y f dbebp q r FbGbHbIbD n g b h z i jbkbs t u JbKbF o j c k A l pbqbv w x LbMb

129 

130 

131def tool_skill_status_table(rows: list[tuple[str, str, str]]) -> Table: 1KLMNOPQRSTU

132 table = Table(show_header=True, header_style="bold", box=None) 2H a e f C WbXbYbZbI b h i E 0b1bJ c k l G 2b3b

133 table.add_column("Target") 2H a e f C WbXbYbZbI b h i E 0b1bJ c k l G 2b3b

134 table.add_column("Status") 2H a e f C WbXbYbZbI b h i E 0b1bJ c k l G 2b3b

135 table.add_column("Path") 2H a e f C WbXbYbZbI b h i E 0b1bJ c k l G 2b3b

136 for target, status, path in rows: 2H a e f C WbXbYbZbI b h i E 0b1bJ c k l G 2b3b

137 table.add_row(target, _styled_status(status), path) 2H a e f C WbXbYbZbI b h i E 0b1bJ c k l G 2b3b

138 return table 2H a e f C WbXbYbZbI b h i E 0b1bJ c k l G 2b3b

139 

140 

141def print_table(table: Table, *, console: Console | None = None) -> None: 1KLMNOPQRSTU

142 _console(console).print(table) 2@ [ B H . m d a e ( y f dbebNb) V W X / C Y p q r Z 0 1 2 ] ^ D I : n g b h * z i jbkbOb+ 3 4 5 ; E 6 s t u 7 8 _ ` F J = o j c k , A l pbqbPb- 9 ! # ? G $ v w x % '

143 

144 

145def print_result( 1KLMNOPQRSTU

146 action: str, 

147 name: str, 

148 target: str, 

149 path: Path | str, 

150 *, 

151 console: Console | None = None, 

152) -> None: 

153 _console(console).print( 2m d a e rb~ abbbcb6b7b8bC { p q r xbybzbAbn g b h sbfbgbhbib#b$b%bE | s t u BbCbo j c k tblbmbnbob)b*b+bG } v w x DbEb

154 f"{_badge('result', action + ':')} [bold]{name}[/bold] ({target}) -> {path}" 

155 ) 

156 

157 

158def print_skipped(name: str, reason: str, *, console: Console | None = None) -> None: 1KLMNOPQRSTU

159 _console(console).print( 2f 5bMcNcOcPci !bQcRcl (bScTc

160 f"{_badge('warning', 'Skipped:')} [bold]{name}[/bold]: {reason}" 

161 ) 

162 

163 

164def _badge(kind: str, label: str) -> str: 1KLMNOPQRSTU

165 style = f"badge.{kind}" 2@ [ B H . m d a e ( y f 4brb~ abbb5bcb) V Qb6b7b8bW X / TbC ub{ Y p q r Z 0 1 2 ] ^ D I : n g b h * z i 9bsbfbgbhb!bib+ 3 Rb#b$b%b4 5 ; UbE vb| 6 s t u 7 8 _ ` F J = o j c k , A l 'btblbmbnb(bob- 9 Sb)b*b+b! # ? VbG wb} $ v w x % '

166 if style not in RICH_THEME: 2@ [ B H . m d a e ( y f 4brb~ abbb5bcb) V Qb6b7b8bW X / TbC ub{ Y p q r Z 0 1 2 ] ^ D I : n g b h * z i 9bsbfbgbhb!bib+ 3 Rb#b$b%b4 5 ; UbE vb| 6 s t u 7 8 _ ` F J = o j c k , A l 'btblbmbnb(bob- 9 Sb)b*b+b! # ? VbG wb} $ v w x % '

167 style = "tag" 2ubqcrcsctcvbucvcwbwcxc

168 return f"[{style}] {label} [/]" 2@ [ B H . m d a e ( y f 4brb~ abbb5bcb) V Qb6b7b8bW X / TbC ub{ Y p q r Z 0 1 2 ] ^ D I : n g b h * z i 9bsbfbgbhb!bib+ 3 Rb#b$b%b4 5 ; UbE vb| 6 s t u 7 8 _ ` F J = o j c k , A l 'btblbmbnb(bob- 9 Sb)b*b+b! # ? VbG wb} $ v w x % '

169 

170 

171def _styled_status(status: str) -> str: 1KLMNOPQRSTU

172 style = { 2B H m d a e y f dbebC ubp q r FbGbHbIbD I n g b h z i jbkbE vbs t u JbKbF J o j c k A l pbqbG wbv w x LbMb

173 "broken": "status.broken", 

174 "hand-authored": "status.hand-authored", 

175 "name mismatch": "status.name-mismatch", 

176 "new": "status.new", 

177 "orphaned": "status.orphaned", 

178 "outdated": "status.outdated", 

179 "up to date": "status.up-to-date", 

180 }.get(status) 

181 if style is None: 2B H m d a e y f dbebC ubp q r FbGbHbIbD I n g b h z i jbkbE vbs t u JbKbF J o j c k A l pbqbG wbv w x LbMb

182 return status 2H a e f C ubWbXbYbZbI b h i E vb0b1bJ c k l G wb2b3b

183 return f"[{style}]{status}[/]" 2B m d a e y f dbebp q r FbGbHbIbD n g b h z i jbkbs t u JbKbF o j c k A l pbqbv w x LbMb

184 

185 

186def print_summary(items: dict[str, int], *, console: Console | None = None) -> None: 1KLMNOPQRSTU

187 non_zero = {name: count for name, count in items.items() if count} 2m d a ( rb~ abbbcb) ub{ xbybzbAbn g b * sbfbgbhbib+ vb| BbCbo j c , tblbmbnbob- wb} DbEb

188 if not non_zero: 2m d a ( rb~ abbbcb) ub{ xbybzbAbn g b * sbfbgbhbib+ vb| BbCbo j c , tblbmbnbob- wb} DbEb

189 print_message("No changes needed.", console=console) 2( ) EcFcGcHc* + IcJc, - KcLc

190 return 2( ) EcFcGcHc* + IcJc, - KcLc

191 if set(non_zero) == {"installed skill targets"}: 2m d a rb~ abbbcbub{ xbybzbAbn g b sbfbgbhbibvb| BbCbo j c tblbmbnbobwb} DbEb

192 count = non_zero["installed skill targets"] 2m d a rb~ abbbcb{ xbybzbAbn g b sbfbgbhbib| BbCbo j c tblbmbnbob} DbEb

193 print_message(f"Installed {count} skill target(s).", console=console) 2m d a rb~ abbbcb{ xbybzbAbn g b sbfbgbhbib| BbCbo j c tblbmbnbob} DbEb

194 return 2m d a rb~ abbbcb{ xbybzbAbn g b sbfbgbhbib| BbCbo j c tblbmbnbob} DbEb

195 summary = ", ".join(f"{name}: {count}" for name, count in non_zero.items()) 2ubqcrcsctcvbucvcwbwcxc

196 _console(console).print(f"{_badge('result', 'Summary:')} {summary}") 2ubqcrcsctcvbucvcwbwcxc