fix: guard dashboard drawing widths
This commit is contained in:
@@ -261,22 +261,32 @@ class ReactorDashboard:
|
|||||||
title: str,
|
title: str,
|
||||||
lines: list[str],
|
lines: list[str],
|
||||||
) -> int:
|
) -> int:
|
||||||
width = win.getmaxyx()[1] - 4
|
height, width = win.getmaxyx()
|
||||||
win.addstr(start_y, 2, title, curses.A_BOLD | curses.color_pair(1))
|
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):
|
for idx, line in enumerate(lines, start=start_y + 1):
|
||||||
|
if idx >= height - 1:
|
||||||
|
break
|
||||||
win.addstr(idx, 4, line[:width])
|
win.addstr(idx, 4, line[:width])
|
||||||
return start_y + len(lines) + 2
|
return start_y + len(lines) + 2
|
||||||
|
|
||||||
def _draw_health_bar(self, win: "curses._CursesWindow", start_y: int) -> None:
|
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))
|
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):
|
for idx, (name, comp) in enumerate(self.reactor.health_monitor.components.items(), start=1):
|
||||||
filled = int(bar_width * comp.integrity)
|
filled = int(bar_width * comp.integrity)
|
||||||
bar = "█" * filled + "-" * (bar_width - filled)
|
bar = "█" * filled + "-" * (bar_width - filled)
|
||||||
color = 3 if comp.integrity > 0.5 else 2 if comp.integrity > 0.2 else 4
|
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)
|
row = start_y + idx
|
||||||
win.addstr(start_y + idx, 16, bar, curses.color_pair(color))
|
if row >= height - 1:
|
||||||
win.addstr(start_y + idx, 18 + bar_width, f"{comp.integrity*100:5.1f}%", curses.color_pair(color))
|
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:
|
def _current_demand(self) -> float:
|
||||||
if self.reactor.consumer:
|
if self.reactor.consumer:
|
||||||
|
|||||||
Reference in New Issue
Block a user