Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-138122: Integrate live profiler TUI with _colorize theming system#142360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
b024e50b1f1a935ccaa252e42a815bd5b75214a3394d32658d3fff021ac9a481b4c1eae5b702bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,7 +9,7 @@ | ||
| # types | ||
| if False: | ||
| from typing import IO, Self, ClassVar | ||
| from typing import IO, Literal, Self, ClassVar | ||
| _theme: Theme | ||
| @@ -74,6 +74,19 @@ class ANSIColors: | ||
| setattr(NoColors, attr, "") | ||
| class CursesColors: | ||
| """Curses color constants for terminal UI theming.""" | ||
| BLACK = 0 | ||
| RED = 1 | ||
| GREEN = 2 | ||
| YELLOW = 3 | ||
| BLUE = 4 | ||
| MAGENTA = 5 | ||
| CYAN = 6 | ||
| WHITE = 7 | ||
| DEFAULT = -1 | ||
| # | ||
| # Experimental theming support (see gh-133346) | ||
| # | ||
| @@ -187,6 +200,114 @@ class Difflib(ThemeSection): | ||
| reset: str = ANSIColors.RESET | ||
| @dataclass(frozen=True, kw_only=True) | ||
| class LiveProfiler(ThemeSection): | ||
pablogsal marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| """Theme section for the live profiling TUI (Tachyon profiler). | ||
| Colors use CursesColors constants (BLACK, RED, GREEN, YELLOW, | ||
| BLUE, MAGENTA, CYAN, WHITE, DEFAULT). | ||
| """ | ||
| # Header colors | ||
| title_fg: int = CursesColors.CYAN | ||
| title_bg: int = CursesColors.DEFAULT | ||
| # Status display colors | ||
| pid_fg: int = CursesColors.CYAN | ||
| uptime_fg: int = CursesColors.GREEN | ||
| time_fg: int = CursesColors.YELLOW | ||
| interval_fg: int = CursesColors.MAGENTA | ||
| # Thread view colors | ||
| thread_all_fg: int = CursesColors.GREEN | ||
| thread_single_fg: int = CursesColors.MAGENTA | ||
| # Progress bar colors | ||
| bar_good_fg: int = CursesColors.GREEN | ||
| bar_bad_fg: int = CursesColors.RED | ||
| # Stats colors | ||
| on_gil_fg: int = CursesColors.GREEN | ||
| off_gil_fg: int = CursesColors.RED | ||
| waiting_gil_fg: int = CursesColors.YELLOW | ||
| gc_fg: int = CursesColors.MAGENTA | ||
| # Function display colors | ||
| func_total_fg: int = CursesColors.CYAN | ||
| func_exec_fg: int = CursesColors.GREEN | ||
| func_stack_fg: int = CursesColors.YELLOW | ||
| func_shown_fg: int = CursesColors.MAGENTA | ||
| # Table header colors (for sorted column highlight) | ||
| sorted_header_fg: int = CursesColors.BLACK | ||
| sorted_header_bg: int = CursesColors.CYAN | ||
| # Normal header colors (non-sorted columns) - use reverse video style | ||
| normal_header_fg: int = CursesColors.BLACK | ||
| normal_header_bg: int = CursesColors.WHITE | ||
| # Data row colors | ||
| samples_fg: int = CursesColors.CYAN | ||
| file_fg: int = CursesColors.GREEN | ||
| func_fg: int = CursesColors.YELLOW | ||
| # Trend indicator colors | ||
| trend_up_fg: int = CursesColors.GREEN | ||
| trend_down_fg: int = CursesColors.RED | ||
| # Medal colors for top functions | ||
| medal_gold_fg: int = CursesColors.RED | ||
| medal_silver_fg: int = CursesColors.YELLOW | ||
| medal_bronze_fg: int = CursesColors.GREEN | ||
| # Background style: 'dark' or 'light' | ||
pablogsal marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| background_style: Literal["dark", "light"] = "dark" | ||
| LiveProfilerLight = LiveProfiler( | ||
| # Header colors | ||
| title_fg=CursesColors.BLUE, # Blue is more readable than cyan on light bg | ||
| # Status display colors - darker colors for light backgrounds | ||
| pid_fg=CursesColors.BLUE, | ||
| uptime_fg=CursesColors.BLACK, | ||
| time_fg=CursesColors.BLACK, | ||
| interval_fg=CursesColors.BLUE, | ||
| # Thread view colors | ||
| thread_all_fg=CursesColors.BLACK, | ||
| thread_single_fg=CursesColors.BLUE, | ||
| # Stats colors | ||
| waiting_gil_fg=CursesColors.RED, | ||
| gc_fg=CursesColors.BLUE, | ||
| # Function display colors | ||
| func_total_fg=CursesColors.BLUE, | ||
| func_exec_fg=CursesColors.BLACK, | ||
| func_stack_fg=CursesColors.BLACK, | ||
| func_shown_fg=CursesColors.BLUE, | ||
| # Table header colors (for sorted column highlight) | ||
| sorted_header_fg=CursesColors.WHITE, | ||
| sorted_header_bg=CursesColors.BLUE, | ||
| # Normal header colors (non-sorted columns) | ||
| normal_header_fg=CursesColors.WHITE, | ||
| normal_header_bg=CursesColors.BLACK, | ||
| # Data row colors - use dark colors readable on white | ||
| samples_fg=CursesColors.BLACK, | ||
| file_fg=CursesColors.BLACK, | ||
| func_fg=CursesColors.BLUE, # Blue is more readable than magenta on light bg | ||
| # Medal colors for top functions | ||
| medal_silver_fg=CursesColors.BLUE, | ||
| # Background style | ||
| background_style="light", | ||
| ) | ||
| @dataclass(frozen=True, kw_only=True) | ||
| class Syntax(ThemeSection): | ||
| prompt: str = ANSIColors.BOLD_MAGENTA | ||
| @@ -232,6 +353,7 @@ class Theme: | ||
| """ | ||
| argparse: Argparse = field(default_factory=Argparse) | ||
| difflib: Difflib = field(default_factory=Difflib) | ||
| live_profiler: LiveProfiler = field(default_factory=LiveProfiler) | ||
| syntax: Syntax = field(default_factory=Syntax) | ||
| traceback: Traceback = field(default_factory=Traceback) | ||
| unittest: Unittest = field(default_factory=Unittest) | ||
| @@ -241,6 +363,7 @@ def copy_with( | ||
| *, | ||
| argparse: Argparse | None = None, | ||
| difflib: Difflib | None = None, | ||
| live_profiler: LiveProfiler | None = None, | ||
| syntax: Syntax | None = None, | ||
| traceback: Traceback | None = None, | ||
| unittest: Unittest | None = None, | ||
| @@ -253,6 +376,7 @@ def copy_with( | ||
| return type(self)( | ||
| argparse=argparse or self.argparse, | ||
| difflib=difflib or self.difflib, | ||
| live_profiler=live_profiler or self.live_profiler, | ||
| syntax=syntax or self.syntax, | ||
| traceback=traceback or self.traceback, | ||
| unittest=unittest or self.unittest, | ||
| @@ -269,6 +393,7 @@ def no_colors(cls) -> Self: | ||
| return cls( | ||
| argparse=Argparse.no_colors(), | ||
| difflib=Difflib.no_colors(), | ||
| live_profiler=LiveProfiler.no_colors(), | ||
| syntax=Syntax.no_colors(), | ||
| traceback=Traceback.no_colors(), | ||
| unittest=Unittest.no_colors(), | ||
| @@ -338,6 +463,9 @@ def _safe_getenv(k: str, fallback: str | None = None) -> str | None: | ||
| default_theme = Theme() | ||
| theme_no_color = default_theme.no_colors() | ||
| # Convenience theme with light profiler colors (for white/light terminal backgrounds) | ||
| light_profiler_theme = default_theme.copy_with(live_profiler=LiveProfilerLight) | ||
| def get_theme( | ||
| *, | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.