Contacts: opens on who's out there now, not a roll call
The list's question is who is on the mesh right now, and a freshest-first order answers it on sight — an A→Z roll call makes you read every row. Open the Contacts screen (and the CLI's default) on heard, ascending age; the Ctrl+arrows still steer from there. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7b3fdff84e
commit
e99e6cf238
2 files changed
+37
-2
No files matched your search
@@ -56,7 +56,10 @@ class ContactsTool(Tool):
|
||||
|
||||
self_name = str(info.get("name") or "this node")
|
||||
self_key = str(info.get("public_key") or "")
|
||||
sort_name = str(params.get("sort") or "name")
|
||||
# Opens most-recently-heard first: the list's job is "who's out there right now",
|
||||
# and a freshest-first order answers that on sight — an A→Z roll call doesn't. The
|
||||
# Ctrl+arrows re-sort from there (and ``--sort`` picks the CLI's order).
|
||||
sort_name = str(params.get("sort") or "heard")
|
||||
|
||||
# In the menu, hand the list to the interactive screen so the Ctrl+arrows re-sort it
|
||||
# live — its ring spans the shared contact list's four columns (hash included); on the
|
||||
@@ -84,7 +87,7 @@ class ContactsTool(Tool):
|
||||
@app.command(name=self.name, help=self.help)
|
||||
def _contacts(
|
||||
sort: str = typer.Option(
|
||||
"name", "--sort", "-s", help="Order contacts by: name, heard, packets"
|
||||
"heard", "--sort", "-s", help="Order contacts by: heard, name, packets"
|
||||
),
|
||||
) -> None:
|
||||
run_tool_command(self, {"sort": sort})
|
||||
@@ -205,6 +205,38 @@ def test_contacts_table_breaks_metric_ties_by_name_ascending() -> None:
|
||||
assert order(ascending=False) == ["Bob", "Alice", "Charlie"]
|
||||
|
||||
|
||||
async def test_contacts_tool_opens_sorted_by_heard(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""The Contacts list opens most-recently-heard first — who's out there now, not a roll call."""
|
||||
from meshterm.tools.contacts import ContactsTool
|
||||
from meshterm.ui import widgets
|
||||
|
||||
captured: dict = {}
|
||||
|
||||
def fake_table(self_name, self_key, contacts, prefix_bytes, counts, sort):
|
||||
captured["sort"] = sort
|
||||
return ""
|
||||
|
||||
monkeypatch.setattr(widgets, "contacts_table", fake_table)
|
||||
|
||||
class _Devstate:
|
||||
async def self_info(self) -> dict:
|
||||
return {"name": "Us", "public_key": "aa" * 32}
|
||||
|
||||
async def contacts(self) -> list:
|
||||
return []
|
||||
|
||||
async def path_hash_mode(self) -> int:
|
||||
return 0
|
||||
|
||||
class _Ctx:
|
||||
devstate = _Devstate()
|
||||
repo = type("R", (), {"heard_nodes": staticmethod(lambda: [])})()
|
||||
ui = type("U", (), {"show": staticmethod(lambda *r: None)})()
|
||||
|
||||
await ContactsTool().run(_Ctx(), {}) # type: ignore[arg-type]
|
||||
assert (captured["sort"].column, captured["sort"].ascending) == ("heard", True)
|
||||
|
||||
|
||||
def _contacts_sort(name: str = "name"):
|
||||
"""The interactive Contacts screen's sort: the shared contact list's four-column ring."""
|
||||
from meshterm.ui.contactlist import SORT_COLUMNS, SORT_OPENS_ASCENDING
|
||||
|
||||
Reference in new issue
Block a user