From a49b95acd86ec9eb69c45f2e8d8ccfbae970b348 Mon Sep 17 00:00:00 2001 From: nicolargo Date: Wed, 13 May 2026 15:33:08 +0200 Subject: [PATCH] =?UTF-8?q?fix(v5):=20load=20plugin=20=E2=80=94=20align=20?= =?UTF-8?q?corecount=20with=20load-average=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The header used '{:3}core' (7 chars) while load-average values used '{:>6.2f}' (6 chars), so '16core' overhung the right edge by 1 character compared to '0.96'/'0.81'/'0.83'. Drop the int padding and rjust the whole corecount cell to the same width as the value cells (6 chars), keeping right edges aligned across all four rows of the block. Two new tests pin the invariant: every value cell shares the same width, and every rendered line has the same total width. Co-Authored-By: Claude Opus 4.7 (1M context) --- glances/plugins/load/render_curses_v5.py | 8 ++++++-- tests/test_plugin_load_render_curses_v5.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/glances/plugins/load/render_curses_v5.py b/glances/plugins/load/render_curses_v5.py index ef6d8ee8..6cdc32ae 100644 --- a/glances/plugins/load/render_curses_v5.py +++ b/glances/plugins/load/render_curses_v5.py @@ -73,11 +73,15 @@ def render(payload: dict[str, Any], fields_desc: dict[str, dict[str, Any]]) -> l return [Row(cells=[Cell(text="LOAD", color=ColorRole.HEADER)])] # Line 1: title + cpucore suffix. + # The value cell width must match the body load-average value width + # (`_LOAD_VALUE_WIDTH = 6`) so the right edges of every line in the + # block align. v4 padded the int with `{:3}core` (7 chars), which + # made the corecount cell 1 char wider than the load-average values + # and produced a visible 1-char overhang. header_cells: list[Cell] = [Cell(text="LOAD".ljust(_LOAD_LABEL_WIDTH), color=ColorRole.HEADER)] cores = payload.get("cpucore") if isinstance(cores, (int, float)) and cores > 0: - # v4 format: `{:3}core` — `' 4core'` for 4 cores. - header_cells.append(Cell(text=f"{int(cores):>3}core".rjust(_LOAD_VALUE_WIDTH))) + header_cells.append(Cell(text=f"{int(cores)}core".rjust(_LOAD_VALUE_WIDTH))) else: header_cells.append(Cell(text="".rjust(_LOAD_VALUE_WIDTH))) rows: list[Row] = [Row(cells=header_cells)] diff --git a/tests/test_plugin_load_render_curses_v5.py b/tests/test_plugin_load_render_curses_v5.py index c6329e23..3f41d4d4 100644 --- a/tests/test_plugin_load_render_curses_v5.py +++ b/tests/test_plugin_load_render_curses_v5.py @@ -130,3 +130,19 @@ def test_render_columns_align(load_payload, load_fields): rows = render(load_payload, load_fields) label_widths = {len(r.cells[0].text) for r in rows if r.cells} assert len(label_widths) == 1 + + +def test_render_value_cells_share_width_across_header_and_body(load_payload, load_fields): + """The corecount cell (header) and the load-average cells (body) must + have the same width so right edges align. Earlier bug: `{:3}core` + produced 7-char header value vs 6-char body values → 1-char overhang.""" + rows = render(load_payload, load_fields) + widths = {len(r.cells[1].text) for r in rows if len(r.cells) >= 2} + assert len(widths) == 1, f"value cells not uniform: {widths}" + + +def test_render_total_line_width_matches_across_rows(load_payload, load_fields): + """Each line's total rendered width (cells joined with 1 space) is identical.""" + rows = render(load_payload, load_fields) + totals = {sum(len(c.text) for c in r.cells) + max(0, len(r.cells) - 1) for r in rows} + assert len(totals) == 1, f"line widths differ: {totals}"