Coverage for apio/common/apio_themes.py: 100%
11 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 05:08 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 05:08 +0000
1# This file is part of the Apio project
2# (C) 2016-present FPGAwars
3# Project authors:
4# * Jesús Arroyo (Jesus89) (2016-2019)
5# * Juan Gonzalez (obijuan) (2019-2024)
6# * The Apio Team (2024-present)
7# License: GPLv2
9"""Apio themes definitions"""
11from dataclasses import dataclass
12from rich.style import Style
13from apio.common import apio_styles
16@dataclass(frozen=True)
17class ApioTheme:
18 """Represents a theme."""
20 # -- The theme name, as selected by the 'apio preferences' command.
21 name: str
22 # -- True if colors are enabled. False for monochrome.
23 colors_enabled: bool
24 # -- The theme styles table. All theme are expected to have the same
25 # -- set of styles keys, even if color is disabled.
26 styles: dict[str, str | Style]
29# -- A theme that is optimized for light backgrounds.
30THEME_LIGHT = ApioTheme(
31 name="light",
32 colors_enabled=True,
33 styles={
34 # -- Styles that are used internally by rich library methods we
35 # -- call. These styles are not used directly by apio and thus we don't
36 # -- assign them abstract names. For the full list of available
37 # -- styles see https://tinyurl.com/rich-default-styles
38 # -- Colors: https://rich.readthedocs.io/en/stable/appendix/colors.html
39 "bar.back": Style(color="grey23"),
40 "bar.complete": Style(color="rgb(249,38,114)"),
41 "bar.finished": Style(color="rgb(114,156,31)"),
42 "table.header": "",
43 # --Apio's abstracted style names.
44 apio_styles.STRING: "italic",
45 apio_styles.CODE: "dark_green",
46 apio_styles.URL: "dark_blue",
47 apio_styles.CMD_NAME: "dark_red bold",
48 apio_styles.TITLE: "dark_red bold",
49 apio_styles.BORDER: "dim",
50 apio_styles.EMPH1: "dark_cyan",
51 apio_styles.EMPH2: "deep_sky_blue4 bold",
52 apio_styles.EMPH3: "magenta",
53 apio_styles.SUCCESS: "green",
54 apio_styles.INFO: "yellow",
55 apio_styles.WARNING: "yellow",
56 apio_styles.ERROR: "red",
57 },
58)
60# -- A theme that is optimized for dark backgrounds.
61THEME_DARK = ApioTheme(
62 name="dark",
63 colors_enabled=True,
64 styles={
65 # -- Styles that are used internally by rich library.
66 "bar.back": Style(color="grey23"),
67 "bar.complete": Style(color="rgb(249,38,114)"),
68 "bar.finished": Style(color="rgb(114,156,31)"),
69 "table.header": "",
70 # --Apio's abstracted style names.
71 apio_styles.STRING: "italic",
72 apio_styles.CODE: "bright_green",
73 apio_styles.URL: "bright_blue",
74 apio_styles.CMD_NAME: "bright_red",
75 apio_styles.TITLE: "bright_red bold",
76 apio_styles.BORDER: "dim",
77 apio_styles.EMPH1: "bright_cyan",
78 apio_styles.EMPH2: "bright_blue bold",
79 apio_styles.EMPH3: "bright_magenta",
80 apio_styles.SUCCESS: "bright_green",
81 apio_styles.INFO: "bright_yellow",
82 apio_styles.WARNING: "bright_yellow",
83 apio_styles.ERROR: "bright_red",
84 },
85)
87# -- A monochrome theme.
88THEME_NO_COLORS = ApioTheme(
89 name="no-colors",
90 colors_enabled=False,
91 # -- A fake style table that is suppressed by the flag above.
92 styles={key: "" for key in THEME_LIGHT.styles},
93)
95# -- Mapping of theme name to theme object.
96THEMES_TABLE = {
97 THEME_LIGHT.name: THEME_LIGHT,
98 THEME_DARK.name: THEME_DARK,
99 THEME_NO_COLORS.name: THEME_NO_COLORS,
100}
102# -- A list of theme names.
103THEMES_NAMES = list(THEMES_TABLE.keys())
105# -- The default theme.
106DEFAULT_THEME = THEME_LIGHT