st_record.py: Better TUI display, exit on failing rich import

In TUI mode, bar displays are now hidden by default until its
diagnostic metric was received to declutter the UI.
This means that for instance the compression metrics are hidden
when this feature is not utilized in the traced program,
or all metrics are hidden if it does not call `st_diagtrace`.

The bars are now styled to not give an impression of being
a progress bar. The completed portion is colored gold while
a completed bar is indicated by red, as this usually
indicates a new maximum value.

A failing rich import in TUI mode now exits after
its error message.
This commit is contained in:
Dominic Höglinger 2025-05-17 07:57:49 +02:00
parent 1d6b1c31fc
commit 622e29872d

View File

@ -604,7 +604,7 @@ class TotalMaximumProgressUpdater:
if value > self.maximum:
self.maximum = value
self.progress.update(self.progress_task, total=self.maximum)
self.progress.update(self.progress_task, completed=value)
self.progress.update(self.progress_task, completed=value, visible=True)
def tui_record(packet_filter, vcd_sink, enable_verbose_trace):
try:
@ -616,7 +616,7 @@ def tui_record(packet_filter, vcd_sink, enable_verbose_trace):
from rich.align import Align
except:
print("error: TUI mode requires the rich package")
return
exit()
if enable_verbose_trace:
print("warning: verbose trace is not avaialble in TUI mode")
@ -628,18 +628,18 @@ def tui_record(packet_filter, vcd_sink, enable_verbose_trace):
progress_colums = [
TextColumn("[progress.description]{task.description}"),
BarColumn(bar_width=80),
BarColumn(bar_width=80, complete_style="gold3", finished_style="red"),
TaskProgressColumn(),
MofNCompleteColumn()
]
diag_progress = Progress(*progress_colums, transient=True, auto_refresh=False, refresh_per_second=1)
buffer_health = diag_progress.add_task("[green]Buffer Health", total=255)
buffer_items = diag_progress.add_task("[green]Buffer Items")
items_sent = diag_progress.add_task("[blue]Items Sent", total=1024)
render_time = diag_progress.add_task("[blue]Render Time", total=1024)
comp_lvl = diag_progress.add_task("[yellow]Compression Level", total=100)
comp_time = diag_progress.add_task("[yellow]Compression Time", total=100)
buffer_health = diag_progress.add_task("[green]Buffer Health", total=255, visible=False)
buffer_items = diag_progress.add_task("[green]Buffer Items", visible=False)
items_sent = diag_progress.add_task("[blue]Items Sent", total=1024, visible=False)
render_time = diag_progress.add_task("[blue]Render Time", total=1024, visible=False)
comp_lvl = diag_progress.add_task("[yellow]Compression Level", total=100, visible=False)
comp_time = diag_progress.add_task("[yellow]Compression Time", total=100, visible=False)
buffer_items_tm = TotalMaximumProgressUpdater(diag_progress, buffer_items)
items_sent_tm = TotalMaximumProgressUpdater(diag_progress, items_sent)
@ -647,10 +647,10 @@ def tui_record(packet_filter, vcd_sink, enable_verbose_trace):
comp_time_tm = TotalMaximumProgressUpdater(diag_progress, comp_time)
with Live(console=console, transient=True) as live_status:
vcd_sink.onvalue("ST.BufferHealth", lambda _,value,sub: diag_progress.update(buffer_health, completed=value))
vcd_sink.onvalue("ST.BufferHealth", lambda _,value,sub: diag_progress.update(buffer_health, completed=value, visible=True))
vcd_sink.onvalue("ST.BufferItems", lambda _,value,sub: buffer_items_tm.update(value))
vcd_sink.onvalue("ST.ItemsSent", lambda _,value,sub: items_sent_tm.update(value))
vcd_sink.onvalue("ST.CompressionLevel", lambda _,value,sub: diag_progress.update(comp_lvl, completed=value))
vcd_sink.onvalue("ST.CompressionLevel", lambda _,value,sub: diag_progress.update(comp_lvl, completed=value, visible=True))
vcd_sink.onvalue("ST.CompressionTime", lambda _,value,sub: comp_time_tm.update(value))
vcd_sink.onvalue("ST.RenderTime", lambda _,value,sub: render_time_tm.update(value))