Coverage for apio/common/apio_themes.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-23 03:53 +0000

1# -*- coding: utf-8 -*- 

2# -- This file is part of the Apio project 

3# -- (C) 2016-2018 FPGAwars 

4# -- Author Jesús Arroyo 

5# -- License GPLv2 

6# -- Derived from: 

7# ---- Platformio project 

8# ---- (C) 2014-2016 Ivan Kravets <me@ikravets.com> 

9# ---- License Apache v2 

10"""Apio themes definitions""" 

11 

12from dataclasses import dataclass 

13from rich.style import Style 

14from apio.common import apio_styles 

15 

16 

17@dataclass(frozen=True) 

18class ApioTheme: 

19 """Represents a theme.""" 

20 

21 # -- The theme name, as selected by the 'apio preferences' command. 

22 name: str 

23 # -- True if colors are enabled. False for monochrome. 

24 colors_enabled: bool 

25 # -- The theme styles table. All theme are expected to have the same 

26 # -- set of styles keys, even if color is disabled. 

27 styles: dict[str, str | Style] 

28 

29 

30# -- A theme that is optimized for light backgrounds. 

31THEME_LIGHT = ApioTheme( 

32 name="light", 

33 colors_enabled=True, 

34 styles={ 

35 # -- Styles that are used internally by rich library methods we 

36 # -- call. These styles are not used directly by apio and thus we don't 

37 # -- assign them abstract names. For the full list of available 

38 # -- styles see https://tinyurl.com/rich-default-styles 

39 # -- Colors: https://rich.readthedocs.io/en/stable/appendix/colors.html 

40 "bar.back": Style(color="grey23"), 

41 "bar.complete": Style(color="rgb(249,38,114)"), 

42 "bar.finished": Style(color="rgb(114,156,31)"), 

43 "table.header": "", 

44 # --Apio's abstracted style names. 

45 apio_styles.STRING: "italic", 

46 apio_styles.CODE: "dark_green", 

47 apio_styles.URL: "dark_blue", 

48 apio_styles.CMD_NAME: "dark_red bold", 

49 apio_styles.TITLE: "dark_red bold", 

50 apio_styles.BORDER: "dim", 

51 apio_styles.EMPH1: "dark_cyan", 

52 apio_styles.EMPH2: "deep_sky_blue4 bold", 

53 apio_styles.EMPH3: "magenta", 

54 apio_styles.SUCCESS: "green", 

55 apio_styles.INFO: "yellow", 

56 apio_styles.WARNING: "yellow", 

57 apio_styles.ERROR: "red", 

58 }, 

59) 

60 

61# -- A theme that is optimized for dark backgrounds. 

62THEME_DARK = ApioTheme( 

63 name="dark", 

64 colors_enabled=True, 

65 styles={ 

66 # -- Styles that are used internally by rich library. 

67 "bar.back": Style(color="grey23"), 

68 "bar.complete": Style(color="rgb(249,38,114)"), 

69 "bar.finished": Style(color="rgb(114,156,31)"), 

70 "table.header": "", 

71 # --Apio's abstracted style names. 

72 apio_styles.STRING: "italic", 

73 apio_styles.CODE: "bright_green", 

74 apio_styles.URL: "bright_blue", 

75 apio_styles.CMD_NAME: "bright_red", 

76 apio_styles.TITLE: "bright_red bold", 

77 apio_styles.BORDER: "dim", 

78 apio_styles.EMPH1: "bright_cyan", 

79 apio_styles.EMPH2: "bright_blue bold", 

80 apio_styles.EMPH3: "bright_magenta", 

81 apio_styles.SUCCESS: "bright_green", 

82 apio_styles.INFO: "bright_yellow", 

83 apio_styles.WARNING: "bright_yellow", 

84 apio_styles.ERROR: "bright_red", 

85 }, 

86) 

87 

88# -- A monochrome theme. 

89THEME_NO_COLORS = ApioTheme( 

90 name="no-colors", 

91 colors_enabled=False, 

92 # -- A fake style table that is suppressed by the flag above. 

93 styles={key: "" for key in THEME_LIGHT.styles}, 

94) 

95 

96# -- Mapping of theme name to theme object. 

97THEMES_TABLE = { 

98 THEME_LIGHT.name: THEME_LIGHT, 

99 THEME_DARK.name: THEME_DARK, 

100 THEME_NO_COLORS.name: THEME_NO_COLORS, 

101} 

102 

103# -- A list of theme names. 

104THEMES_NAMES = list(THEMES_TABLE.keys()) 

105 

106# -- The default theme. 

107DEFAULT_THEME = THEME_LIGHT