7cb2a8b618
Testing / remote-protocol-compat (0.9.5) (push) Successful in 1m4s
Testing / test (push) Successful in 1m22s
Testing / remote-protocol-compat (0.9.3) (push) Successful in 1m7s
Package Extension / package-extension (push) Successful in 1m1s
Build & Publish Package / publish (push) Successful in 1m5s
- Split auth into focused package modules for agent keys, file keys, signing, and post-quantum transport helpers while keeping the public browser_cli.auth import surface intact. - Move transport encoding internals into a package with separate codec and binary-hoisting helpers, preserving browser_cli.transport compatibility. - Extract remote TCP auth/socket helpers and serve challenge setup out of the runtime paths to make connection handling easier to reason about. - Move the extension markdown extractor into a dedicated content/markdown folder with separate root selection, code normalization, renderer, and utils. - Centralize CLI Rich rendering helpers for tab/window tree and table output, and add rendering tests for the shared builders. - Remove local typing ignores in SDK/decorator/script plumbing and bump the package and extension version to 0.15.3.
64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
import click
|
|
from browser_cli.commands import client_from_ctx, handle_errors
|
|
from browser_cli.commands.rendering import build_windows_tree, print_table_rows, print_tree
|
|
from rich.console import Console
|
|
|
|
console = Console()
|
|
|
|
def _print_windows(windows: list[dict], *, show_browser: bool = False) -> None:
|
|
columns = []
|
|
if show_browser:
|
|
columns.append(("Browser", lambda window: window.get("browser", "")))
|
|
columns.extend([
|
|
("ID", lambda window: window.get("id", "")),
|
|
("Alias", lambda window: window.get("alias") or ""),
|
|
("Tabs", lambda window: window.get("tabCount", "")),
|
|
("State", lambda window: window.get("state") or ""),
|
|
])
|
|
print_table_rows(windows, columns, console=console, empty_message="[yellow]No windows found[/yellow]")
|
|
|
|
@click.group("windows")
|
|
def windows_group():
|
|
"""Manage browser windows."""
|
|
|
|
@windows_group.command("list")
|
|
@handle_errors
|
|
def windows_list():
|
|
"""List all browser windows."""
|
|
windows = client_from_ctx().windows.list()
|
|
_print_windows(windows, show_browser=any("browser" in w for w in windows))
|
|
|
|
@windows_group.command("tree")
|
|
@handle_errors
|
|
def windows_tree():
|
|
"""Show windows and their tabs as a tree."""
|
|
client = client_from_ctx()
|
|
root = build_windows_tree(client.windows.list(), client.tabs.list(), console=console)
|
|
print_tree(root, console=console)
|
|
|
|
@windows_group.command("rename")
|
|
@click.argument("window_id", type=int)
|
|
@click.argument("name")
|
|
@handle_errors
|
|
def windows_rename(window_id, name):
|
|
"""Give a window a local alias NAME (stored in native host)."""
|
|
client_from_ctx().windows.rename(window_id, name)
|
|
console.print(f"[green]Window {window_id} aliased as '{name}'[/green]")
|
|
|
|
@windows_group.command("close")
|
|
@click.argument("window_id", type=int)
|
|
@handle_errors
|
|
def windows_close(window_id):
|
|
"""Close a browser window."""
|
|
client_from_ctx().windows.close(window_id)
|
|
console.print(f"[green]Window {window_id} closed[/green]")
|
|
|
|
@windows_group.command("open")
|
|
@click.argument("url", required=False)
|
|
@handle_errors
|
|
def windows_open(url):
|
|
"""Open a new browser window."""
|
|
result = client_from_ctx().windows.open(url)
|
|
wid = result.get("id") if isinstance(result, dict) else result
|
|
console.print(f"[green]Opened new window[/green] (id: {wid})" + (f" with {url}" if url else ""))
|