fix: guard dashboard drawing widths

This commit is contained in:
Andrii Prokhorov
2025-11-21 17:31:42 +02:00
parent 8dec574ac6
commit 37fded30e6

View File

@@ -261,22 +261,32 @@ class ReactorDashboard:
title: str,
lines: list[str],
) -> int:
width = win.getmaxyx()[1] - 4
win.addstr(start_y, 2, title, curses.A_BOLD | curses.color_pair(1))
height, width = win.getmaxyx()
width -= 4
if start_y >= height - 2:
return height - 2
win.addstr(start_y, 2, title[:width], curses.A_BOLD | curses.color_pair(1))
for idx, line in enumerate(lines, start=start_y + 1):
if idx >= height - 1:
break
win.addstr(idx, 4, line[:width])
return start_y + len(lines) + 2
def _draw_health_bar(self, win: "curses._CursesWindow", start_y: int) -> None:
win.addstr(start_y, 2, "Component Health", curses.A_BOLD | curses.color_pair(1))
bar_width = win.getmaxyx()[1] - 10
height, width = win.getmaxyx()
bar_width = max(10, min(width - 24, 40))
for idx, (name, comp) in enumerate(self.reactor.health_monitor.components.items(), start=1):
filled = int(bar_width * comp.integrity)
bar = "" * filled + "-" * (bar_width - filled)
color = 3 if comp.integrity > 0.5 else 2 if comp.integrity > 0.2 else 4
win.addstr(start_y + idx, 4, f"{name:<12}", curses.A_BOLD)
win.addstr(start_y + idx, 16, bar, curses.color_pair(color))
win.addstr(start_y + idx, 18 + bar_width, f"{comp.integrity*100:5.1f}%", curses.color_pair(color))
row = start_y + idx
if row >= height - 1:
break
win.addstr(row, 4, f"{name:<12}"[:12], curses.A_BOLD)
win.addstr(row, 16, bar[:bar_width], curses.color_pair(color))
percent_col = min(width - 8, 18 + bar_width)
win.addstr(row, percent_col, f"{comp.integrity*100:5.1f}%", curses.color_pair(color))
def _current_demand(self) -> float:
if self.reactor.consumer: