8dece7800f
Testing / remote-protocol-compat (0.9.3) (push) Successful in 52s
Testing / test (push) Successful in 1m2s
Testing / remote-protocol-compat (0.9.5) (push) Successful in 1m0s
Package Extension / package-extension (push) Successful in 1m11s
Build & Publish Package / publish (push) Successful in 1m7s
- Add browser source grouping metadata to SDK-created tabs, groups, list results, and aggregate count results. - Render grouped local/remote browser tables consistently for clients, tabs, groups, windows, sessions, and remote status output. - Document remote control, auth, HTTP gateway usage, and the refreshed project structure in the README. - Add coverage for grouped output and BrowserCounts browser_groups. - Bump the Python package, extension manifest, and lockfile to 0.15.6. - Add a just publish helper for building and publishing release artifacts.
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
import click
|
|
from browser_cli.commands import client_from_ctx, handle_errors
|
|
from browser_cli.commands.rendering import build_windows_tree, print_browser_grouped_table_rows, print_tree
|
|
from rich.console import Console
|
|
|
|
console = Console()
|
|
|
|
def _print_windows(windows: list[dict], *, show_browser: bool = False) -> None:
|
|
columns = [
|
|
("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_browser_grouped_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 ""))
|