^N shows the places of a path's nodes on the Trophy case, TX sweep, Mesh walk, and path composer
Each screen keeps its own PlaceToggle and opens with node names. The record page and the board rows, the sweep route line, the walk trail, and the composer's route preview go through placemode.placed. The hint and the lane chip show ^N only where a path line has a node that can change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
07c8bc1d23
commit
c3174b6fbb
8 files changed
+431
-50
No files matched your search
@@ -83,8 +83,12 @@ from ..services.topology import (
|
||||
render_custom_spec,
|
||||
render_forced_spec,
|
||||
)
|
||||
from .menus import HINT_CELLS
|
||||
from .pathline import PathLine, cut_to, path_line
|
||||
from .placemode import ACTION as PLACES_ACTION
|
||||
from .placemode import PlaceToggle, node_of, placed, places_of_session
|
||||
from .theme import snr_style
|
||||
from .tui.frame import fit_hint
|
||||
from .tui.render import query_line, render_lines, render_to_ansi
|
||||
from .tui.screen import ListWindow, Screen
|
||||
from .widgets import NodeResolver, age_seconds, format_age, identity_label, path_text
|
||||
@@ -172,9 +176,31 @@ class PathComposerScreen(Screen):
|
||||
press will do. This is the filter rule for all the app: the map, the mesh walk, and
|
||||
each select list show the same.
|
||||
"""
|
||||
if not self._entry:
|
||||
return self._HINT
|
||||
return self._HINT.replace("Esc cancel", "Esc clear")
|
||||
hint = self._HINT
|
||||
if self._places_apply:
|
||||
hint = hint.replace("Esc cancel", f"{self._places.hint} · Esc cancel")
|
||||
if self._entry:
|
||||
hint = hint.replace("Esc cancel", "Esc clear")
|
||||
return fit_hint(hint, HINT_CELLS, shed_first=self.spare_hint_atoms)
|
||||
|
||||
#: The atom that goes first when ^N makes the hint longer than the limit: Backspace
|
||||
#: removes a hop without a hint, as it does in each text field.
|
||||
spare_hint_atoms = ("⌫ remove",)
|
||||
|
||||
@property
|
||||
def picocalc_lyra_lane(self):
|
||||
"""The shared pager, and the ^N change of the route preview on F1 when it can change."""
|
||||
from .tui.fkeys import FPair
|
||||
|
||||
lane = list(super().picocalc_lyra_lane)
|
||||
if self._places_apply:
|
||||
lane[0] = FPair(self._places.chip, PLACES_ACTION)
|
||||
return lane
|
||||
|
||||
@property
|
||||
def _places_apply(self) -> bool:
|
||||
"""Whether the route preview has a node that ^N can change: a hop or the target."""
|
||||
return bool(self._hops) or self._mirrored
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -234,6 +260,8 @@ class PathComposerScreen(Screen):
|
||||
self._device_hash = (device_hash or "").lower().removeprefix("0x")
|
||||
self._topology = topology
|
||||
self._resolve = resolve
|
||||
#: ^N: the route preview shows the node names, or the places of the nodes.
|
||||
self._places = PlaceToggle()
|
||||
#: The resolved names to show, by node id (refer to :meth:`_resolve_entry`).
|
||||
self._names: dict[str, str] = {}
|
||||
#: The graph ids that are the same node as each node (refer to :meth:`_aliases`).
|
||||
@@ -557,7 +585,7 @@ class PathComposerScreen(Screen):
|
||||
entries.append(self._path_entry(self._target_id))
|
||||
entries.extend(self._path_entry(hop) for hop in reversed(self._hops))
|
||||
entries.append(None)
|
||||
return path_line(
|
||||
line = path_line(
|
||||
entries,
|
||||
self._resolve_entry,
|
||||
prefix_bytes=self._width_bytes,
|
||||
@@ -570,6 +598,9 @@ class PathComposerScreen(Screen):
|
||||
# is rendered-hop index k + 1.
|
||||
cursor=self._cursor + 1,
|
||||
)
|
||||
if self._places.on:
|
||||
line = placed(line, places_of_session(), node_of(self._resolve))
|
||||
return line
|
||||
|
||||
def _suggestion_text(self, suggestion) -> Text: # noqa: ANN001
|
||||
"""One suggestion row: the node, then the evidence of its link."""
|
||||
@@ -765,6 +796,8 @@ class PathComposerScreen(Screen):
|
||||
self._index = 0
|
||||
elif action == "enter":
|
||||
self._commit_row()
|
||||
elif action == PLACES_ACTION:
|
||||
self._places.flip()
|
||||
elif action == "backspace":
|
||||
if self._entry:
|
||||
self._entry = self._entry[:-1]
|
||||
|
||||
+134
-28
@@ -50,12 +50,16 @@ from ..persistence.repository import DiscoveredPath
|
||||
from ..services import trace_runner
|
||||
from ..services.records import CATEGORIES, CATEGORY_BY_ID, Category, local_xy
|
||||
from .mapcanvas import RGB, MapCanvas
|
||||
from .menus import fit_cells, icon_lane, marked_label, section_heading
|
||||
from .menus import HINT_CELLS, fit_cells, icon_lane, marked_label, section_heading
|
||||
from .pathgraph import PathLayer, render_path_graph
|
||||
from .pathline import path_line
|
||||
from .pathline import PathLine, path_line
|
||||
from .placemode import ACTION as PLACES_ACTION
|
||||
from .placemode import PlaceToggle, node_of, placed, places_of_session
|
||||
from .theme import glyph, name_style, snr_style
|
||||
from .tui.frame import fit_hint
|
||||
from .tui.render import render_hanging, render_lines, render_to_ansi
|
||||
from .tui.screen import Screen
|
||||
from .tui.select import SelectScreen, splice_hint
|
||||
from .widgets import (
|
||||
NodeResolver,
|
||||
TypeOf,
|
||||
@@ -319,6 +323,8 @@ class RecordScreen(Screen):
|
||||
self._record = record
|
||||
self._category = category
|
||||
self._resolve = resolve
|
||||
#: ^N: the path lines show the node names, or the places of the nodes.
|
||||
self._places = PlaceToggle()
|
||||
self._device_label = device_label
|
||||
self._device_hash = device_hash
|
||||
self._far_label = far_label
|
||||
@@ -373,9 +379,25 @@ class RecordScreen(Screen):
|
||||
from .tui.fkeys import FPair, default_lane
|
||||
|
||||
lane = list(default_lane(nav=self._tab != _TAB_AREA and self.content_overflows))
|
||||
if self._tab != _TAB_AREA: # the Area tab has no path line, so the slot stays empty
|
||||
lane[0] = FPair(self._places.chip, PLACES_ACTION, enabled=self._has_path_line)
|
||||
lane[2] = FPair(self._tabs[(self._tab_index + 1) % len(self._tabs)], "tab")
|
||||
return lane
|
||||
|
||||
@property
|
||||
def _has_path_line(self) -> bool:
|
||||
"""Whether the active tab draws a path line: the route, or the longest leg of Info."""
|
||||
if self._tab == _TAB_ROUTE:
|
||||
return True
|
||||
link = self._record.stats.get("leg_link") if self._tab == _TAB_INFO else None
|
||||
return bool(link) and len(link) == 2
|
||||
|
||||
def _placed(self, line: PathLine) -> PathLine:
|
||||
"""The path line, with each node name changed to its place while ^N has that choice."""
|
||||
if not self._places.on:
|
||||
return line
|
||||
return placed(line, places_of_session(), node_of(self._resolve))
|
||||
|
||||
@property
|
||||
def footer_hint(self) -> str: # type: ignore[override]
|
||||
"""The hint line: the tab change, then the move, scroll, and select atoms, Esc last.
|
||||
@@ -392,8 +414,14 @@ class RecordScreen(Screen):
|
||||
parts.append("PgUp/PgDn scroll")
|
||||
if actions:
|
||||
parts.append("Enter select")
|
||||
if self._has_path_line:
|
||||
parts.append(self._places.hint)
|
||||
parts.append("Esc back")
|
||||
return " · ".join(parts)
|
||||
return fit_hint(" · ".join(parts), HINT_CELLS, shed_first=self.spare_hint_atoms)
|
||||
|
||||
#: The scroll atom goes first when ^N makes the hint longer than the limit. The user
|
||||
#: finds PgUp and PgDn without help.
|
||||
spare_hint_atoms = ("PgUp/PgDn scroll",)
|
||||
|
||||
def _switch_tab(self, delta: int) -> None:
|
||||
"""Change the active tab: its page opens at the top, with the highlight on row one."""
|
||||
@@ -417,6 +445,10 @@ class RecordScreen(Screen):
|
||||
self.resolve(None)
|
||||
elif self._tab == _TAB_AREA:
|
||||
return
|
||||
elif action == PLACES_ACTION:
|
||||
# Both caches hold the finished path lines, so they must be built again.
|
||||
self._places.flip()
|
||||
self._info_cache = self._route_cache = None
|
||||
elif action == "up":
|
||||
self._follow = True
|
||||
# The two ends clamp, they do not wrap. This is the rule of the app for a
|
||||
@@ -572,13 +604,15 @@ class RecordScreen(Screen):
|
||||
# leg that starts or ends at home is the most usual type of leg.
|
||||
value.append(" ")
|
||||
value.append_text(
|
||||
path_line(
|
||||
list(link),
|
||||
self._resolve,
|
||||
self_name=self._device_label,
|
||||
bare_self=True,
|
||||
dim_self=False,
|
||||
show_hash=False,
|
||||
self._placed(
|
||||
path_line(
|
||||
list(link),
|
||||
self._resolve,
|
||||
self_name=self._device_label,
|
||||
bare_self=True,
|
||||
dim_self=False,
|
||||
show_hash=False,
|
||||
)
|
||||
).text()
|
||||
)
|
||||
lanes.append(self._lane("longest leg", value))
|
||||
@@ -777,16 +811,18 @@ class RecordScreen(Screen):
|
||||
# star at the two ends, and the legend under it says that the star is "you". The
|
||||
# stars keep the ``you`` white, because nothing about a walk that is already done is
|
||||
# ours to compose.
|
||||
route = path_line(
|
||||
[None, *record.route, None],
|
||||
self._resolve,
|
||||
prefix_bytes=record.width_bytes,
|
||||
self_name=self._device_label,
|
||||
show_hash=True,
|
||||
hash_bytes=record.width_bytes,
|
||||
device_hash=self._device_hash,
|
||||
bare_self=True,
|
||||
dim_self=False,
|
||||
route = self._placed(
|
||||
path_line(
|
||||
[None, *record.route, None],
|
||||
self._resolve,
|
||||
prefix_bytes=record.width_bytes,
|
||||
self_name=self._device_label,
|
||||
show_hash=True,
|
||||
hash_bytes=record.width_bytes,
|
||||
device_hash=self._device_hash,
|
||||
bare_self=True,
|
||||
dim_self=False,
|
||||
)
|
||||
)
|
||||
lines.extend(render_to_ansi(line, width, no_wrap=True) for line in route.wrapped(width))
|
||||
return lines
|
||||
@@ -868,6 +904,64 @@ def node_geo_lookup(
|
||||
return lookup
|
||||
|
||||
|
||||
class TrophyBoard(SelectScreen):
|
||||
"""The select list of the Trophy case, with ^N for the places of the nodes in each walk.
|
||||
|
||||
Each row of the list has a path line. ^N builds the rows again, through ``rebuild``, with
|
||||
the node names or with the places of the nodes. The list keeps the highlight, because
|
||||
:meth:`~meshterm.ui.tui.select.SelectScreen.replace_items` finds the row again by its
|
||||
value. A list with no record has no path line, so ^N and its hint are not there.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str,
|
||||
items: list,
|
||||
*,
|
||||
rebuild: Callable[[bool], list],
|
||||
has_paths: bool,
|
||||
**kwargs, # noqa: ANN003 - the arguments of SelectScreen
|
||||
) -> None:
|
||||
"""Build the list.
|
||||
|
||||
Args:
|
||||
title: The heading in the border.
|
||||
items: The rows, with the node names in the path lines.
|
||||
rebuild: Gives the rows again for the choice of ^N (``True`` is the places).
|
||||
has_paths: Whether any row has a path line.
|
||||
**kwargs: The other arguments of :class:`~meshterm.ui.tui.select.SelectScreen`.
|
||||
"""
|
||||
super().__init__(title, items, **kwargs)
|
||||
self._rebuild = rebuild
|
||||
self._has_paths = has_paths
|
||||
#: ^N: the path lines show the node names, or the places of the nodes.
|
||||
self._places = PlaceToggle()
|
||||
|
||||
@property
|
||||
def footer_hint(self) -> str: # type: ignore[override]
|
||||
"""The hint of the list, with the ^N atom before Esc when a row has a path line."""
|
||||
hint = super().footer_hint
|
||||
return splice_hint(hint, self._places.hint) if self._has_paths else hint
|
||||
|
||||
@property
|
||||
def picocalc_lyra_lane(self):
|
||||
"""The lane of the list, with the ^N change of the path lines on F3."""
|
||||
from .tui.fkeys import FPair
|
||||
|
||||
lane = list(super().picocalc_lyra_lane)
|
||||
if self._has_paths:
|
||||
lane[2] = FPair(self._places.chip, PLACES_ACTION)
|
||||
return lane
|
||||
|
||||
def handle(self, action: str, data: str = "") -> None:
|
||||
"""Change the path lines on ^N. Any other key is for the list."""
|
||||
if action != PLACES_ACTION:
|
||||
super().handle(action, data)
|
||||
elif self._has_paths:
|
||||
self._places.flip()
|
||||
self.replace_items(self._rebuild(self._places.on))
|
||||
|
||||
|
||||
async def open_records(ctx: AppContext) -> dict:
|
||||
"""Open the Trophy case browser and run it until the user leaves it.
|
||||
|
||||
@@ -889,7 +983,7 @@ async def open_records(ctx: AppContext) -> dict:
|
||||
"""
|
||||
from .surface import TuiUi
|
||||
from .trace_screen import open_trace_path
|
||||
from .tui import CANCEL, Choice, SelectScreen, Separator
|
||||
from .tui import CANCEL, Choice, Separator
|
||||
|
||||
if not isinstance(ctx.ui, TuiUi): # pragma: no cover - the menu caller prevents this
|
||||
raise RuntimeError("the Trophy case screen is only available in the menu")
|
||||
@@ -1034,7 +1128,7 @@ async def open_records(ctx: AppContext) -> dict:
|
||||
row.append(" ")
|
||||
return row
|
||||
|
||||
def browser_row(lanes: Text, record: DiscoveredPath) -> Text:
|
||||
def browser_row(lanes: Text, record: DiscoveredPath, *, places_on: bool = False) -> Text:
|
||||
"""One record row: its fixed lanes (:func:`browser_lanes`), then the full walk.
|
||||
|
||||
The walk draws on the only path widget, with the two ends bare
|
||||
@@ -1060,6 +1154,9 @@ async def open_records(ctx: AppContext) -> dict:
|
||||
user in the board, and gives the walk no cells that it does not already get. Thus a
|
||||
selected row and a row that is not selected are different in only one thing: the
|
||||
shift.
|
||||
|
||||
With ``places_on`` (^N), each node name in the walk is changed to the place of the
|
||||
node.
|
||||
"""
|
||||
row = lanes.copy()
|
||||
walk = path_line(
|
||||
@@ -1071,6 +1168,8 @@ async def open_records(ctx: AppContext) -> dict:
|
||||
bare_self=True,
|
||||
dim_self=False,
|
||||
)
|
||||
if places_on:
|
||||
walk = placed(walk, places_of_session(), node_of(resolve))
|
||||
row.append_text(walk.text())
|
||||
return row
|
||||
|
||||
@@ -1110,7 +1209,8 @@ async def open_records(ctx: AppContext) -> dict:
|
||||
):
|
||||
ctx.repo.delete_discoveries(category.id)
|
||||
|
||||
while True:
|
||||
def board_items(places_on: bool, total: int) -> list:
|
||||
"""The rows of the Trophy case: each board, then the delete rows (when records exist)."""
|
||||
items: list = []
|
||||
for category in CATEGORIES:
|
||||
items.extend(describe(category))
|
||||
@@ -1135,16 +1235,15 @@ async def open_records(ctx: AppContext) -> dict:
|
||||
# A finished line, not a callable that knows the width. The row does
|
||||
# not fit itself to a width, so the list cuts each row (highlighted or
|
||||
# not) in the same way (refer to browser_row). Records are frozen, so
|
||||
# the line is composed once each time the screen opens, not at each
|
||||
# paint.
|
||||
title=browser_row(lanes, record),
|
||||
# the line is composed once each time the screen opens or ^N changes
|
||||
# it, not at each paint.
|
||||
title=browser_row(lanes, record, places_on=places_on),
|
||||
value=("open", category, rank, record),
|
||||
# ←→ slide only the walk. The lanes in front of it do not move
|
||||
# (browser_row).
|
||||
hscroll_from=lanes.cell_len,
|
||||
)
|
||||
)
|
||||
total = len(ctx.repo.discoveries())
|
||||
if total:
|
||||
items.append(Separator(" "))
|
||||
items.append(
|
||||
@@ -1159,11 +1258,18 @@ async def open_records(ctx: AppContext) -> dict:
|
||||
value=("del_all", None, 0, None),
|
||||
)
|
||||
)
|
||||
browser = SelectScreen(
|
||||
return items
|
||||
|
||||
while True:
|
||||
total = len(ctx.repo.discoveries())
|
||||
items = board_items(False, total)
|
||||
browser = TrophyBoard(
|
||||
"Trophy case",
|
||||
items,
|
||||
footer_hint="↑↓ move · Enter open · Esc back",
|
||||
hscroll=True, # a long walk slides under ←→, and is not cut at the edge
|
||||
rebuild=lambda places_on, total=total: board_items(places_on, total),
|
||||
has_paths=total > 0,
|
||||
)
|
||||
# A place, not a question: the trophy case is the page of the tool itself. Thus it
|
||||
# fills the frame from each entry point. From the menu, it is the only screen, and
|
||||
|
||||
@@ -51,6 +51,8 @@ from ..services import trace_runner, tx_optimizer
|
||||
from ..services.topology import build_topology, render_custom_spec
|
||||
from .menus import icon_lane, icon_mark
|
||||
from .pathline import SELF_GLYPH, PathHop, PathLine, cut_to, path_line
|
||||
from .placemode import ACTION as PLACES_ACTION
|
||||
from .placemode import PlaceToggle, node_of, placed, places_of_session
|
||||
from .theme import name_style, snr_style
|
||||
from .trace_screen import TracingDialog, collapse_trace_width, snr_bar
|
||||
from .tui.render import render_lines, render_to_ansi
|
||||
@@ -167,6 +169,8 @@ class TxSweepScreen(Screen):
|
||||
self._device_label = device_label
|
||||
self._device_hash = device_hash
|
||||
self._resolve = resolve
|
||||
#: ^N: the path lines show the node names, or the places of the nodes.
|
||||
self._places = PlaceToggle()
|
||||
self._session = session
|
||||
self._run_sweep = run_sweep
|
||||
self._apply_winner = apply_winner
|
||||
@@ -215,8 +219,23 @@ class TxSweepScreen(Screen):
|
||||
def footer_hint(self) -> str: # type: ignore[override]
|
||||
"""The footer keys. They change when a sweep is in flight."""
|
||||
if self.running:
|
||||
return "sweeping… · PgUp/PgDn scroll · Esc back"
|
||||
return "↑↓ actions · Enter run · PgUp/PgDn scroll · Esc back"
|
||||
return f"sweeping… · PgUp/PgDn scroll · {self._places.hint} · Esc back"
|
||||
return f"↑↓ actions · Enter run · PgUp/PgDn scroll · {self._places.hint} · Esc back"
|
||||
|
||||
@property
|
||||
def picocalc_lyra_lane(self):
|
||||
"""The shared pager on F4/F5, and the ^N change of the path lines on F1."""
|
||||
from .tui.fkeys import FPair, default_lane
|
||||
|
||||
lane = list(default_lane())
|
||||
lane[0] = FPair(self._places.chip, PLACES_ACTION)
|
||||
return lane
|
||||
|
||||
def _placed(self, line: PathLine) -> PathLine:
|
||||
"""The path line, with each node name changed to its place while ^N has that choice."""
|
||||
if not self._places.on:
|
||||
return line
|
||||
return placed(line, places_of_session(), node_of(self._resolve))
|
||||
|
||||
def _can_apply(self) -> bool:
|
||||
"""Whether Apply is offered: the sweep finished, it has a winner, and it is not applied."""
|
||||
@@ -305,6 +324,8 @@ class TxSweepScreen(Screen):
|
||||
"""Move the highlight of the actions, commit the selected action, scroll, or leave."""
|
||||
if action == "enter":
|
||||
self._commit_action()
|
||||
elif action == PLACES_ACTION:
|
||||
self._places.flip()
|
||||
elif action == "up":
|
||||
# Both ends clamp and do not wrap. This is the rule of the whole app for the
|
||||
# highlight of a row. A highlight that jumps from one end to the other takes
|
||||
@@ -414,11 +435,13 @@ class TxSweepScreen(Screen):
|
||||
# in the word before them.
|
||||
text.append("Route — via ")
|
||||
text.append_text(
|
||||
path_line(
|
||||
list(self.route_hops),
|
||||
self._resolve,
|
||||
from_origin=False,
|
||||
to_destination=False,
|
||||
self._placed(
|
||||
path_line(
|
||||
list(self.route_hops),
|
||||
self._resolve,
|
||||
from_origin=False,
|
||||
to_destination=False,
|
||||
)
|
||||
).text()
|
||||
)
|
||||
else:
|
||||
@@ -463,7 +486,7 @@ class TxSweepScreen(Screen):
|
||||
(self._target_label, name_style(self._target_label, self._target_key)),
|
||||
)
|
||||
lines = [render_to_ansi(tuning, width, no_wrap=True)]
|
||||
route = self._route_line().wrapped(width, indent=9)
|
||||
route = self._placed(self._route_line()).wrapped(width, indent=9)
|
||||
first = Text("route ", style="muted")
|
||||
first.append_text(route[0])
|
||||
lines.append(render_to_ansi(first, width, no_wrap=True))
|
||||
|
||||
@@ -75,8 +75,10 @@ from ..platforms import get_platform
|
||||
from ..services.topology import Link, MeshTopology
|
||||
from .mapcanvas import RGB, MapCanvas, parse_hex
|
||||
from .marks import SELF_MARK, UNKNOWN_MARK
|
||||
from .menus import fit_cells
|
||||
from .menus import HINT_CELLS, fit_cells
|
||||
from .pathline import ELIDE_HEAD, ELIDE_TAIL, SELF_GLYPH, PathHop, PathLine, cut_mark
|
||||
from .placemode import ACTION as PLACES_ACTION
|
||||
from .placemode import PlaceToggle, placed_hops, places_of_session
|
||||
from .theme import mark_rgb, name_style, snr_style
|
||||
from .trace_screen import snr_bar
|
||||
from .tui.render import crop_cells, query_line, render_to_ansi
|
||||
@@ -264,6 +266,7 @@ class WalkScreen(Screen):
|
||||
from .tui.fkeys import FPair, default_lane
|
||||
|
||||
lane = list(default_lane(nav=len(self._rows()) > 1))
|
||||
lane[0] = FPair(self._places.chip, PLACES_ACTION, enabled=len(self._trail) > 1)
|
||||
lane[2] = FPair("You", "locate", enabled=len(self._trail) > 1 or bool(self._filter))
|
||||
return lane
|
||||
|
||||
@@ -310,6 +313,8 @@ class WalkScreen(Screen):
|
||||
#: ``((width, trail) → the furthest that can scroll)``, set at render (refer to
|
||||
#: :meth:`_trail_max_scroll`). Thus a key press can clamp itself without a width.
|
||||
self._trail_fit: tuple[tuple, int] | None = None
|
||||
#: ^N: the trail shows the node names, or the places of the nodes.
|
||||
self._places = PlaceToggle()
|
||||
#: The width of the last render of the trail, for that same clamp.
|
||||
self._trail_width = 0
|
||||
#: The index of the highlighted row in the current list (neighbours or matches).
|
||||
@@ -453,8 +458,17 @@ class WalkScreen(Screen):
|
||||
atoms += ["Enter focus", "⌫ back", "^L you"]
|
||||
if not scrolls:
|
||||
atoms.append("type to find")
|
||||
if len(self._trail) > 1:
|
||||
atoms.append(self._places.hint) # the trail has a node that has a place
|
||||
atoms.append("Esc back")
|
||||
return " · ".join(atoms)
|
||||
from .tui.frame import fit_hint
|
||||
|
||||
return fit_hint(" · ".join(atoms), HINT_CELLS, shed_first=self.spare_hint_atoms)
|
||||
|
||||
#: The atoms that go first when ^N makes the hint longer than the limit. The find teaches
|
||||
#: itself at the first letter. A trail that scrolls has no find atom, so the ⌫ atom goes
|
||||
#: then. The user finds ⌫ without help.
|
||||
spare_hint_atoms = ("type to find", "⌫ back")
|
||||
|
||||
def handle(self, action: str, data: str = "") -> None:
|
||||
"""Move the highlight, walk, step back, find, or close.
|
||||
@@ -464,6 +478,10 @@ class WalkScreen(Screen):
|
||||
not a position in this list. Refer to :attr:`picocalc_lyra_lane`.
|
||||
"""
|
||||
rows = self._rows()
|
||||
if action == PLACES_ACTION:
|
||||
self._places.flip()
|
||||
self._trail_scroll = 0 # the trail changes its length, so the focus shows again
|
||||
return
|
||||
if action == "escape":
|
||||
if self._filter:
|
||||
self._filter = ""
|
||||
@@ -680,9 +698,7 @@ class WalkScreen(Screen):
|
||||
move from there.
|
||||
"""
|
||||
self._trail_width = width
|
||||
full = PathLine(
|
||||
[self._trail_hop(node) for node in self._trail], separator=_TRAIL_SEP
|
||||
).text()
|
||||
full = PathLine(self._trail_hops(), separator=_TRAIL_SEP).text()
|
||||
total = full.cell_len
|
||||
# The scroll is clamped before the fit is read. Thus, when a line fits its width
|
||||
# again (a wider terminal, a step back), no slide stays behind a complete line.
|
||||
@@ -718,11 +734,10 @@ class WalkScreen(Screen):
|
||||
The result is cached on ``(width, trail)``: it costs a render, and the answer
|
||||
changes only when the walk or the terminal changes.
|
||||
"""
|
||||
key = (width, tuple(self._trail))
|
||||
key = (width, tuple(self._trail), self._places.on)
|
||||
if self._trail_fit is not None and self._trail_fit[0] == key:
|
||||
return self._trail_fit[1]
|
||||
hops = [self._trail_hop(node) for node in self._trail]
|
||||
total = PathLine(hops, separator=_TRAIL_SEP).text().cell_len
|
||||
total = PathLine(self._trail_hops(), separator=_TRAIL_SEP).text().cell_len
|
||||
limit = 0
|
||||
if total > width:
|
||||
steps = -(-(total - (width - 1)) // _HSCROLL_STEP)
|
||||
@@ -730,6 +745,13 @@ class WalkScreen(Screen):
|
||||
self._trail_fit = (key, limit)
|
||||
return limit
|
||||
|
||||
def _trail_hops(self) -> list[PathHop]:
|
||||
"""The hops of the trail, with the places of the nodes while ^N has that choice."""
|
||||
hops = [self._trail_hop(node) for node in self._trail]
|
||||
if self._places.on:
|
||||
hops = placed_hops(hops, places_of_session())
|
||||
return hops
|
||||
|
||||
def _trail_hop(self, node: str) -> PathHop:
|
||||
"""One walked step as a path hop: its display name in the colour of its identity.
|
||||
|
||||
|
||||
@@ -1253,6 +1253,41 @@ def test_sweep_screen_opens_armed_and_idle_on_sweep() -> None:
|
||||
assert ran == [True]
|
||||
|
||||
|
||||
def test_sweep_screen_places_change_the_route_line(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""^N flips the route line between the node names and the places of the nodes."""
|
||||
from meshterm.core.places import Place
|
||||
from meshterm.services import places
|
||||
|
||||
class _Places:
|
||||
def get(self, node: str | None) -> Place:
|
||||
return Place("Villeray", None, "tiles")
|
||||
|
||||
monkeypatch.setattr(places, "_CURRENT", _Places())
|
||||
session = _FakeSession()
|
||||
screen = TxSweepScreen(
|
||||
admin_label="Repeater",
|
||||
target_label="Alice",
|
||||
admin_key="aa" * 32,
|
||||
target_key="bb" * 32,
|
||||
device_label="us",
|
||||
device_hash="00" * 32,
|
||||
resolve=lambda h: h,
|
||||
session=session,
|
||||
tx_min=12,
|
||||
tx_max=28,
|
||||
step=3,
|
||||
samples=3,
|
||||
run_sweep=lambda: None,
|
||||
apply_winner=lambda: None,
|
||||
)
|
||||
assert "^N places" in screen.footer_hint and "Villeray" not in _plain(screen.render_body(100))
|
||||
screen.handle("places")
|
||||
assert "^N names" in screen.footer_hint and "Villeray" in _plain(screen.render_body(100))
|
||||
assert screen.picocalc_lyra_lane[0].label == "Names"
|
||||
screen.handle("places")
|
||||
assert "Villeray" not in _plain(screen.render_body(100))
|
||||
|
||||
|
||||
def test_sweep_screen_quotes_the_transmission_budget() -> None:
|
||||
"""The worst case on the Sweep row follows the window, the step, and the samples."""
|
||||
screen, _ = _sweep_screen()
|
||||
|
||||
@@ -555,13 +555,57 @@ def test_record_footer_names_only_what_each_tab_answers() -> None:
|
||||
assert "PgUp/PgDn scroll" in screen.footer_hint
|
||||
screen.handle("tab")
|
||||
screen.note_metrics(10, 24)
|
||||
assert screen.footer_hint == "Tab/⇧Tab switch · Enter select · Esc back"
|
||||
assert screen.footer_hint == "Tab/⇧Tab switch · Enter select · ^N places · Esc back"
|
||||
screen.handle("tab")
|
||||
assert screen.footer_hint == "Tab/⇧Tab switch · Esc back"
|
||||
screen.handle("down") # inert on the Area tab
|
||||
assert screen._index == 0
|
||||
|
||||
|
||||
class _FakePlaces:
|
||||
"""The places of the session: every node is in Villeray."""
|
||||
|
||||
def get(self, node: str | None): # noqa: ANN201
|
||||
from meshterm.core.places import Place
|
||||
|
||||
return Place("Villeray", None, "tiles")
|
||||
|
||||
|
||||
def test_record_route_tab_places_change_the_route_line(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""^N flips the route line between the node names and the places of the nodes."""
|
||||
from meshterm.services import places
|
||||
|
||||
monkeypatch.setattr(places, "_CURRENT", _FakePlaces())
|
||||
screen = _dialog(_record(), shape=_loop_shape())
|
||||
assert "^N" not in screen.footer_hint # the Info tab has no path line without a leg
|
||||
assert not screen.picocalc_lyra_lane[0].enabled
|
||||
screen.handle("tab")
|
||||
assert "^N places" in screen.footer_hint and len(screen.footer_hint) <= 72
|
||||
assert screen.picocalc_lyra_lane[0].enabled
|
||||
assert "Hilltop-Repeater" in _plain(screen.render_body(60))
|
||||
screen.handle("places")
|
||||
assert "^N names" in screen.footer_hint and screen.picocalc_lyra_lane[0].label == "Names"
|
||||
route = _plain(screen.render_body(60))
|
||||
assert "Villeray" in route and "Hilltop-Repeater" not in route
|
||||
screen.handle("places")
|
||||
assert "Hilltop-Repeater" in _plain(screen.render_body(60))
|
||||
screen.handle("tab") # the Area tab has no path line: its lane slot is empty
|
||||
assert screen.picocalc_lyra_lane[0] is None
|
||||
|
||||
|
||||
def test_record_info_tab_places_change_the_longest_leg(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""The longest leg of the Info tab is a path line too, so ^N changes it."""
|
||||
from meshterm.services import places
|
||||
|
||||
monkeypatch.setattr(places, "_CURRENT", _FakePlaces())
|
||||
record = _record(stats={**_record().stats, "leg_km": 2.0, "leg_link": (HUB_ID, FAR_ID)})
|
||||
screen = _dialog(record)
|
||||
assert "^N places" in screen.footer_hint
|
||||
screen.handle("places")
|
||||
info = _plain(screen.render_body(60))
|
||||
assert "Villeray" in info and "Hilltop-Repeater" not in info
|
||||
|
||||
|
||||
def test_record_dialog_scrolls_free_of_the_action_cursor() -> None:
|
||||
"""PgUp, PgDn, Home, and End scroll the card. The highlight of the actions does not follow."""
|
||||
dialog = _dialog(_record(), shape=_loop_shape())
|
||||
@@ -942,3 +986,70 @@ async def test_browser_cuts_every_row_the_way_it_cuts_the_highlighted_one(tui_ct
|
||||
finally:
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
|
||||
|
||||
async def test_the_board_places_change_the_walk_of_each_row(
|
||||
tui_ctx, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""^N builds the rows again with the places of the nodes, and the highlight stays."""
|
||||
from meshterm.core.models import Observation
|
||||
from meshterm.services import places
|
||||
|
||||
monkeypatch.setattr(places, "_CURRENT", _FakePlaces())
|
||||
ctx = tui_ctx
|
||||
session = ctx.ui.session
|
||||
run = ctx.repo.start_run("monitor", {})
|
||||
ctx.repo.record_observation(run, Observation(node=HUB_ID, kind="advert", name="Hilltop"))
|
||||
ctx.repo.record_discovery(
|
||||
"grand_tour",
|
||||
1,
|
||||
"3d,f2",
|
||||
(HUB_ID, FAR_ID),
|
||||
score=2.0,
|
||||
stats={"hop_count": 2, "distinct_nodes": 2},
|
||||
app_version="0.1.0",
|
||||
)
|
||||
|
||||
def walk(browser) -> str: # noqa: ANN001
|
||||
return next(
|
||||
choice.label.plain
|
||||
for choice in browser._choices()
|
||||
if isinstance(choice.value, tuple) and choice.value[0] == "open"
|
||||
)
|
||||
|
||||
task = asyncio.ensure_future(open_records(ctx))
|
||||
try:
|
||||
browser = await _step_until(lambda: _trophy_case(session))
|
||||
assert browser is not None
|
||||
assert "^N places" in browser.footer_hint and "Hilltop" in walk(browser)
|
||||
assert browser.picocalc_lyra_lane[2].label == "Places"
|
||||
browser.handle("down")
|
||||
browser.handle("places")
|
||||
assert "^N names" in browser.footer_hint and browser.picocalc_lyra_lane[2].label == "Names"
|
||||
assert "Villeray" in walk(browser) and "Hilltop" not in walk(browser)
|
||||
assert browser._current_choice().value[0] == "del_cat" # the highlight stays on its row
|
||||
browser.handle("places")
|
||||
assert "Hilltop" in walk(browser)
|
||||
browser.handle("escape")
|
||||
await task
|
||||
finally:
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
|
||||
|
||||
async def test_an_empty_board_has_no_places_key(tui_ctx) -> None:
|
||||
"""With no record, no row has a path line, so the hint and the lane do not offer ^N."""
|
||||
ctx = tui_ctx
|
||||
session = ctx.ui.session
|
||||
task = asyncio.ensure_future(open_records(ctx))
|
||||
try:
|
||||
browser = await _step_until(lambda: _trophy_case(session))
|
||||
assert browser is not None
|
||||
assert "^N" not in browser.footer_hint
|
||||
assert browser.picocalc_lyra_lane[2] is None
|
||||
browser.handle("places") # nothing to change
|
||||
browser.handle("escape")
|
||||
await task
|
||||
finally:
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
@@ -501,6 +501,30 @@ def test_composer_suggests_from_tail_and_appends_on_enter() -> None:
|
||||
assert all(s.node != "f2c24f54551e" for s in screen._suggestions())
|
||||
|
||||
|
||||
def test_composer_places_change_the_route_preview(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""^N flips the route preview between the node names and the places of the nodes."""
|
||||
from meshterm.core.places import Place
|
||||
from meshterm.services import places
|
||||
|
||||
class _Places:
|
||||
def get(self, node: str | None) -> Place:
|
||||
return Place("Villeray", None, "tiles")
|
||||
|
||||
monkeypatch.setattr(places, "_CURRENT", _Places())
|
||||
screen = _composer(_topo(), hops=["3d63c6429436"])
|
||||
assert "^N places" in screen.footer_hint and len(screen.footer_hint) <= 72
|
||||
assert "Far" in _rows_plain(screen) and "Villeray" not in _rows_plain(screen)
|
||||
screen.handle("places")
|
||||
assert "^N names" in screen.footer_hint and len(screen.footer_hint) <= 72
|
||||
body = _rows_plain(screen)
|
||||
assert "Villeray" in body and "Far" not in screen._route_preview().text().plain
|
||||
assert screen.picocalc_lyra_lane[0].label == "Names"
|
||||
screen.handle("places")
|
||||
assert "Far" in screen._route_preview().text().plain
|
||||
# A path with no hop and no target has nothing for ^N to change, so no hint shows it.
|
||||
assert "^N" not in _composer(_topo(), target=False).footer_hint
|
||||
|
||||
|
||||
def test_composer_windows_rows_under_the_pinned_route_preview() -> None:
|
||||
"""A short dialog shows a window of the rows. The route preview and highlight stay visible."""
|
||||
import re
|
||||
|
||||
+28
-1
@@ -11,6 +11,8 @@ from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
from meshterm.core.models import Contact, utcnow
|
||||
from meshterm.services.topology import MeshTopology
|
||||
from meshterm.ui.pathline import (
|
||||
@@ -372,6 +374,30 @@ def test_walk_trail_names_carry_their_node_hues() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_walk_places_change_the_trail(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""^N flips the trail between the node names and the places, and the lane shows the chip."""
|
||||
from meshterm.core.places import Place
|
||||
from meshterm.services import places
|
||||
|
||||
class _Places:
|
||||
def get(self, node: str | None) -> Place:
|
||||
return Place("Villeray", None, "tiles")
|
||||
|
||||
monkeypatch.setattr(places, "_CURRENT", _Places())
|
||||
screen = _screen(_topo())
|
||||
assert "^N" not in screen.footer_hint # the trail is only our node: ^N has no effect
|
||||
screen._trail = [screen._topo.self_id, screen._topo.canonical(Hub.public_key)]
|
||||
assert "^N places" in screen.footer_hint and len(screen.footer_hint) <= 72
|
||||
assert "Hilltop-Repeater" in screen._trail_text(80).plain
|
||||
screen.handle("places")
|
||||
assert "^N names" in screen.footer_hint
|
||||
assert screen.picocalc_lyra_lane[0].label == "Names"
|
||||
plain = screen._trail_text(80).plain
|
||||
assert "Villeray" in plain and "Hilltop-Repeater" not in plain
|
||||
screen.handle("places")
|
||||
assert "Hilltop-Repeater" in screen._trail_text(80).plain
|
||||
|
||||
|
||||
def test_walk_locate_refocuses_us_and_home_end_walk_the_list() -> None:
|
||||
"""^L resets the walk to our own node from anywhere. Home and End go to the ends of the list."""
|
||||
# A hub with spokes from one of our neighbours: a focus away from us, with a list to move in.
|
||||
@@ -441,12 +467,13 @@ def test_walk_fkey_lane_gives_you_its_own_slot_over_the_pagers_ends() -> None:
|
||||
lane = screen.picocalc_lyra_lane
|
||||
|
||||
assert [pair.label if pair else None for pair in lane] == [
|
||||
None,
|
||||
"Places", # ^N, dim while the trail is only our node
|
||||
None,
|
||||
"You",
|
||||
"Page ↓",
|
||||
"Page ↑",
|
||||
]
|
||||
assert not lane[0].enabled
|
||||
assert PICOCALC_LYRA_DECK.action_for(lane, 3) == "locate"
|
||||
assert lane[2].opp_label == "" # nothing is the opposite of going home
|
||||
# Also, the Shift bank of the pager has the same meaning as on each other screen: the
|
||||
|
||||
Reference in new issue
Block a user