Skip to content

Commit 4d32658

Browse files
committed
fixup! Update _colorize.py
1 parent 214a339 commit 4d32658

5 files changed

Lines changed: 39 additions & 24 deletions

File tree

Lib/_colorize.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,13 @@ class LiveProfiler(ThemeSection):
273273
func_stack_fg: int = CursesColors.YELLOW
274274
func_shown_fg: int = CursesColors.MAGENTA
275275

276-
# Table header colors
276+
# Table header colors (for sorted column highlight)
277277
sorted_header_fg: int = CursesColors.BLACK
278-
sorted_header_bg: int = CursesColors.YELLOW
278+
sorted_header_bg: int = CursesColors.CYAN
279+
280+
# Normal header colors (non-sorted columns)
281+
normal_header_fg: int = CursesColors.WHITE
282+
normal_header_bg: int = CursesColors.BLUE
279283

280284
# Data row colors
281285
samples_fg: int = CursesColors.CYAN
@@ -303,7 +307,7 @@ class LiveProfiler(ThemeSection):
303307
# Status display colors
304308
pid_fg=CursesColors.BLUE,
305309
uptime_fg=CursesColors.GREEN,
306-
time_fg=CursesColors.YELLOW,
310+
time_fg=CursesColors.RED, # Use red instead of yellow for better visibility on light bg
307311
interval_fg=CursesColors.MAGENTA,
308312

309313
# Thread view colors
@@ -317,23 +321,27 @@ class LiveProfiler(ThemeSection):
317321
# Stats colors
318322
on_gil_fg=CursesColors.GREEN,
319323
off_gil_fg=CursesColors.RED,
320-
waiting_gil_fg=CursesColors.YELLOW,
324+
waiting_gil_fg=CursesColors.RED, # Use red instead of yellow for visibility
321325
gc_fg=CursesColors.MAGENTA,
322326

323327
# Function display colors
324328
func_total_fg=CursesColors.BLUE,
325329
func_exec_fg=CursesColors.GREEN,
326-
func_stack_fg=CursesColors.YELLOW,
330+
func_stack_fg=CursesColors.RED, # Use red instead of yellow
327331
func_shown_fg=CursesColors.MAGENTA,
328332

329-
# Table header colors
333+
# Table header colors (for sorted column highlight)
330334
sorted_header_fg=CursesColors.WHITE,
331-
sorted_header_bg=CursesColors.BLUE,
335+
sorted_header_bg=CursesColors.MAGENTA,
336+
337+
# Normal header colors (non-sorted columns)
338+
normal_header_fg=CursesColors.WHITE,
339+
normal_header_bg=CursesColors.BLUE,
332340

333341
# Data row colors
334342
samples_fg=CursesColors.BLUE,
335343
file_fg=CursesColors.GREEN,
336-
func_fg=CursesColors.MAGENTA,
344+
func_fg=CursesColors.MAGENTA, # Use magenta instead of yellow
337345

338346
# Trend indicator colors
339347
trend_up_fg=CursesColors.GREEN,

Lib/profiling/sampling/live_collector/collector.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,12 @@ def _setup_colors(self):
540540
self.display.init_color_pair(2, profiler_theme.file_fg, default_bg)
541541
self.display.init_color_pair(3, profiler_theme.func_fg, default_bg)
542542

543-
header_bg = 2 if profiler_theme.background_style == "dark" else 4
544-
self.display.init_color_pair(COLOR_PAIR_HEADER_BG, 0, header_bg)
543+
# Normal header background color pair
544+
self.display.init_color_pair(
545+
COLOR_PAIR_HEADER_BG,
546+
profiler_theme.normal_header_fg,
547+
profiler_theme.normal_header_bg,
548+
)
545549

546550
self.display.init_color_pair(COLOR_PAIR_CYAN, profiler_theme.pid_fg, default_bg)
547551
self.display.init_color_pair(COLOR_PAIR_YELLOW, profiler_theme.time_fg, default_bg)
@@ -567,7 +571,7 @@ def _setup_colors(self):
567571
"magenta": self.display.get_color_pair(COLOR_PAIR_MAGENTA) | A_BOLD,
568572
"red": self.display.get_color_pair(COLOR_PAIR_RED) | A_BOLD,
569573
"sorted_header": self.display.get_color_pair(COLOR_PAIR_SORTED_HEADER) | A_BOLD,
570-
"normal_header": A_REVERSE | A_BOLD,
574+
"normal_header": self.display.get_color_pair(COLOR_PAIR_HEADER_BG) | A_BOLD,
571575
"color_samples": self.display.get_color_pair(1),
572576
"color_file": self.display.get_color_pair(2),
573577
"color_func": self.display.get_color_pair(3),
@@ -576,6 +580,7 @@ def _setup_colors(self):
576580
"trend_stable": A_NORMAL,
577581
}
578582

583+
# Fallback for no-color mode
579584
return {
580585
"header": A_REVERSE | A_BOLD,
581586
"cyan": A_BOLD,

Lib/profiling/sampling/live_collector/display.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ def get_dimensions(self):
7474
return self.stdscr.getmaxyx()
7575

7676
def clear(self):
77-
self.stdscr.clear()
77+
# Use erase() instead of clear() to avoid flickering
78+
# clear() forces a complete screen redraw, erase() just clears the buffer
79+
self.stdscr.erase()
7880

7981
def refresh(self):
8082
self.stdscr.refresh()
8183

8284
def redraw(self):
83-
self.stdscr.redrawwin()
85+
# Use noutrefresh + doupdate for smoother updates
86+
self.stdscr.noutrefresh()
87+
curses.doupdate()
8488

8589
def add_str(self, line, col, text, attr=0):
8690
try:

Lib/profiling/sampling/live_collector/widgets.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,7 @@ def draw_stats_rows(self, line, height, width, stats_list, column_flags):
729729
column_flags
730730
)
731731

732-
# Get color attributes from the colors dict (already initialized)
733-
color_samples = self.colors.get("color_samples", curses.A_NORMAL)
732+
# Get color attributes
734733
color_file = self.colors.get("color_file", curses.A_NORMAL)
735734
color_func = self.colors.get("color_func", curses.A_NORMAL)
736735

@@ -759,18 +758,18 @@ def draw_stats_rows(self, line, height, width, stats_list, column_flags):
759758
else 0
760759
)
761760

762-
# Helper function to get trend color for a specific column
761+
# Helper function to get trend color
763762
def get_trend_color(column_name):
764763
trend = trends.get(column_name, "stable")
765-
if trend_tracker is not None:
764+
if trend_tracker is not None and trend_tracker.enabled:
766765
return trend_tracker.get_color(trend)
767766
return curses.A_NORMAL
768767

769768
filename, lineno, funcname = func[0], func[1], func[2]
770769
samples_str = f"{direct_calls}/{cumulative_calls}"
771770
col = 0
772771

773-
# Samples column - apply trend color based on nsamples trend
772+
# Samples column - apply trend color
774773
nsamples_color = get_trend_color("nsamples")
775774
self.add_str(line, col, f"{samples_str:>13}", nsamples_color)
776775
col += 15
@@ -819,9 +818,7 @@ def get_trend_color(column_name):
819818
simplified_path = self.collector.simplify_path(filename)
820819
file_line = f"{simplified_path}:{lineno}"
821820
remaining_width = width - col - 1
822-
self.add_str(
823-
line, col, file_line[:remaining_width], color_file
824-
)
821+
self.add_str(line, col, file_line[:remaining_width], color_file)
825822

826823
line += 1
827824

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
The Tachyon profiler's live TUI now integrates with the experimental
2-
:mod:`!_colorize` theming system, allowing users to customize colors via
3-
:func:`!_colorize.set_theme`. A :class:`!LiveProfilerLight` theme is provided
4-
for light terminal backgrounds. Patch by Pablo Galindo.
2+
:mod:`!_colorize` theming system. Users can customize colors via
3+
:func:`!_colorize.set_theme` (experimental API, subject to change).
4+
A :class:`!LiveProfilerLight` theme is provided for light terminal backgrounds.
5+
Patch by Pablo Galindo.

0 commit comments

Comments
 (0)