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

12 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-06 10:20 +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 typing import Dict, Union 

13from dataclasses import dataclass 

14from rich.style import Style 

15from apio.common import apio_styles 

16 

17 

18@dataclass(frozen=True) 

19class ApioTheme: 

20 """Represents a theme.""" 

21 

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

23 name: str 

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

25 colors_enabled: bool 

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

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

28 styles: Dict[str, Union[str, Style]] 

29 

30 

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

32THEME_LIGHT = ApioTheme( 

33 name="light", 

34 colors_enabled=True, 

35 styles={ 

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

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

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

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

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

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

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

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

44 "table.header": "", 

45 # --Apio's abstracted style names. 

46 apio_styles.STRING: "italic", 

47 apio_styles.CODE: "dark_green", 

48 apio_styles.URL: "dark_blue", 

49 apio_styles.CMD_NAME: "dark_red bold", 

50 apio_styles.TITLE: "dark_red bold", 

51 apio_styles.BORDER: "dim", 

52 apio_styles.EMPH1: "dark_cyan", 

53 apio_styles.EMPH2: "deep_sky_blue4 bold", 

54 apio_styles.EMPH3: "magenta", 

55 apio_styles.SUCCESS: "green", 

56 apio_styles.INFO: "yellow", 

57 apio_styles.WARNING: "yellow", 

58 apio_styles.ERROR: "red", 

59 }, 

60) 

61 

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

63THEME_DARK = ApioTheme( 

64 name="dark", 

65 colors_enabled=True, 

66 styles={ 

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

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

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

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

71 "table.header": "", 

72 # --Apio's abstracted style names. 

73 apio_styles.STRING: "italic", 

74 apio_styles.CODE: "bright_green", 

75 apio_styles.URL: "bright_blue", 

76 apio_styles.CMD_NAME: "bright_red", 

77 apio_styles.TITLE: "bright_red bold", 

78 apio_styles.BORDER: "dim", 

79 apio_styles.EMPH1: "bright_cyan", 

80 apio_styles.EMPH2: "bright_blue bold", 

81 apio_styles.EMPH3: "bright_magenta", 

82 apio_styles.SUCCESS: "bright_green", 

83 apio_styles.INFO: "bright_yellow", 

84 apio_styles.WARNING: "bright_yellow", 

85 apio_styles.ERROR: "bright_red", 

86 }, 

87) 

88 

89# -- A monochrome theme. 

90THEME_NO_COLORS = ApioTheme( 

91 name="no-colors", 

92 colors_enabled=False, 

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

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

95) 

96 

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

98THEMES_TABLE = { 

99 THEME_LIGHT.name: THEME_LIGHT, 

100 THEME_DARK.name: THEME_DARK, 

101 THEME_NO_COLORS.name: THEME_NO_COLORS, 

102} 

103 

104# -- A list of theme names. 

105THEMES_NAMES = list(THEMES_TABLE.keys()) 

106 

107# -- The default theme. 

108DEFAULT_THEME = THEME_LIGHT