feat: improve remote browser tree routing
Testing / remote-protocol-compat (0.9.3) (push) Successful in 43s
Testing / test (push) Successful in 1m1s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 39s
Build & Publish Package / publish (push) Successful in 58s
Package Extension / package-extension (push) Successful in 1m15s
Testing / remote-protocol-compat (0.9.3) (push) Successful in 43s
Testing / test (push) Successful in 1m1s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 39s
Build & Publish Package / publish (push) Successful in 58s
Package Extension / package-extension (push) Successful in 1m15s
- Allow remote host aliases passed via --browser to fan out for read-only multi-browser SDK paths while preserving strict routing for mutating commands. - Add remote host grouping and scoped profile labels to tabs tree output so global views avoid repeated host prefixes. - Carry browser family metadata through remote targets, tabs, and groups and style tree browser labels by family. - Split CLI rendering helpers into a typed rendering package with dedicated common, label, tabs-tree, and windows-tree modules. - Bump browser-cli and extension versions to 0.15.5. - Cover the new routing and rendering behavior with unit and CLI tests.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""Windows tree renderer."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable, Mapping
|
||||
|
||||
from rich.console import Console
|
||||
from rich.tree import Tree
|
||||
|
||||
from browser_cli.commands.rendering.common import Row, int_value, item_value, text_value, tree_title_limit, tree_url_limit
|
||||
from browser_cli.commands.rendering.labels import tab_tree_label
|
||||
|
||||
WindowRow = Mapping[str, object]
|
||||
|
||||
def build_windows_tree(windows: Iterable[WindowRow], tabs: Iterable[Row], *, console: Console) -> Tree:
|
||||
"""Build a window → tab tree from window and tab responses."""
|
||||
windows = list(windows)
|
||||
tabs = list(tabs)
|
||||
title_limit = tree_title_limit(console=console, show_browser=any("browser" in w for w in windows), show_urls=True)
|
||||
url_limit = tree_url_limit(title_limit, console=console)
|
||||
root = Tree("[bold]Windows[/bold]")
|
||||
for window in sorted(windows, key=lambda item: (text_value(item.get("browser")), int_value(item.get("id")))):
|
||||
window_id = int_value(window.get("id"))
|
||||
label = f"Window {window_id}"
|
||||
alias = text_value(window.get("alias"))
|
||||
browser = text_value(window.get("browser"))
|
||||
if alias:
|
||||
label += f" ({alias})"
|
||||
if browser:
|
||||
label = f"{browser}: " + label
|
||||
node = root.add(label)
|
||||
window_tabs = [
|
||||
tab for tab in tabs
|
||||
if int_value(item_value(tab, "window_id", item_value(tab, "windowId"))) == window_id
|
||||
and (not browser or text_value(item_value(tab, "browser")) == browser)
|
||||
]
|
||||
for tab in sorted(window_tabs, key=lambda item: int_value(item_value(item, "index", 0))):
|
||||
node.add(tab_tree_label(tab, title_limit=title_limit, show_urls=True, url_limit=url_limit))
|
||||
return root
|
||||
Reference in New Issue
Block a user