Wrap the key bindings bar over several lines
CI / pytest and ruff (pull_request) Successful in 4m43s
CI / pytest and ruff (push) Successful in 4m43s

Textual's Footer is a single horizontal row, so on a narrow terminal the
keys at the end were cut off. KeyBar replaces it on every screen: it reads
the same active bindings, packs them greedily into rows that fit the width,
and grows in height as needed.

Generated with AI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #33.
This commit is contained in:
DuckbootandClaude Opus 5.5 committed 2026-11-03 08:35:03 +01:00
1 parent 0df928ab11
commit 9b472e8cf6
2 files changed
+126 -5

No files matched your search

+49
View File
@@ -4,6 +4,7 @@ All cli functions are monkeypatched: cv4pve-cli is never executed.
"""
import contextlib
import itertools
import re
import subprocess
import threading
@@ -4872,3 +4873,51 @@ async def test_restore_before_the_info_screen_loaded_says_still_loading(
finally:
release.set()
await settle(app, pilot)
# --- key bar wraps instead of overflowing ---------------------------------------------
@given(st.lists(st.integers(1, 30), max_size=25), st.integers(1, 120))
def test_wrap_rows_keep_order_fit_width_and_pack_greedily(widths, width):
rows = appmod.wrap_rows(widths, width)
assert [w for row in rows for w in row] == widths
for row in rows:
assert row # no empty rows
assert sum(row) <= width or len(row) == 1 # only a lone item may overflow
for prev, nxt in itertools.pairwise(rows):
assert sum(prev) + nxt[0] > width # greedy: the next item did not fit
def keybar_text(app):
bar = app.screen.query_one(appmod.KeyBar)
return bar, "\n".join(
bar.lines(bar.size.width)[i].plain for i in range(bar.size.height)
)
async def test_keybar_wraps_on_a_narrow_terminal(fake):
app = make_app()
async with app.run_test(size=(50, 30)) as pilot:
await settle(app, pilot)
bar, text = keybar_text(app)
assert bar.size.height > 1
for desc in ("Start", "Tasks", "Updates", "Quit"):
assert desc in text
async def test_keybar_is_one_line_on_a_wide_terminal(fake):
app = make_app()
async with app.run_test(size=(400, 30)) as pilot:
await settle(app, pilot)
bar, text = keybar_text(app)
assert bar.size.height == 1
assert "Quit" in text
async def test_keybar_follows_the_info_screen_bindings(fake):
app = make_app()
async with app.run_test(size=(50, 40)) as pilot:
await open_info(app, pilot)
_bar, text = keybar_text(app)
assert "Restore backup" in text