Dashboard: start with the newest packet highlighted
The feed used to open with nothing selected, a holdover from before the list scrolled in place. That meant a single Esc after highlighting a packet only peeled the highlight, leaving a second Esc to actually leave the screen. Default the highlight to the newest packet and let Esc back out directly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7f1750df0e
commit
a52dfc7b12
2 files changed
+8
-12
No files matched your search
@@ -28,9 +28,9 @@ stacks four reads of the mesh, coarsest first:
|
||||
|
||||
The screen holds no subscriptions of its own — the opener (:func:`open_dashboard`)
|
||||
wires the hub subscription, the device-stats poll, and the once-a-second repaint, and
|
||||
tears them all down when the screen resolves. PgUp/PgDn/Home/End move the feed window
|
||||
(carrying the highlight when one is set); Esc first drops the feed highlight, then
|
||||
backs out.
|
||||
tears them all down when the screen resolves. The newest packet is highlighted from the
|
||||
moment the screen opens; PgUp/PgDn/Home/End walk that highlight, and Esc backs out
|
||||
directly.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -172,8 +172,9 @@ class DashboardScreen(Screen):
|
||||
self._feed: deque[PacketEntry] = deque(maxlen=_FEED_CAP)
|
||||
for obs in list(self._window)[-_FEED_CAP:][::-1]:
|
||||
self._feed.append(PacketEntry.from_observation(obs))
|
||||
#: The highlighted feed row (``None`` = nothing selected, window scrolls free).
|
||||
self._selected: Optional[int] = None
|
||||
#: The highlighted feed row. Starts on the newest packet (``None`` only when
|
||||
#: the feed is empty) so a lone Esc always backs straight out of the screen.
|
||||
self._selected: Optional[int] = 0 if self._feed else None
|
||||
#: The feed's window within the fixed screen (only its rows scroll).
|
||||
self._feed_window = ListWindow()
|
||||
#: The device's own numbers, refreshed by the opener's poll (Device info's
|
||||
@@ -256,11 +257,7 @@ class DashboardScreen(Screen):
|
||||
self._feed_window.to_end()
|
||||
self._session.invalidate()
|
||||
elif action == "escape":
|
||||
if self._selected is not None:
|
||||
self._selected = None # first Esc peels the highlight, second leaves
|
||||
self._session.invalidate()
|
||||
else:
|
||||
self.resolve(None)
|
||||
self.resolve(None)
|
||||
|
||||
def _move_selection(self, delta: int) -> None:
|
||||
"""Move the feed highlight (the first press lands on the newest packet)."""
|
||||
|
||||
@@ -186,8 +186,7 @@ def test_dashboard_page_keys_move_the_feed_selection() -> None:
|
||||
window = [_obs(node=f"n{i}", age_s=i) for i in range(20)]
|
||||
screen = _screen(window=window)
|
||||
screen._feed_window.page = 5 # as if the last paint settled a five-row window
|
||||
screen.handle("down") # first press lands the highlight on the newest feed row
|
||||
assert screen._selected == 0
|
||||
assert screen._selected == 0 # the newest packet is highlighted from the start
|
||||
screen.handle("pagedown")
|
||||
assert screen._selected == 5 # the selection travelled down a page, not just the view
|
||||
screen.handle("pageup")
|
||||
|
||||
Reference in new issue
Block a user