xa.panes¶
Pane providers: where a session’s terminal lives (tmux on a server, iTerm on a Mac).
Everything xa does with a session’s terminal is four verbs: create a pane running a
command, capture its text, address it later, tear it down. A
PaneProvider is that, and a PaneAddress (provider + ref) is the
provider-neutral way to name a pane, so Session need not carry tmux-shaped fields.
TmuxPanes: the default; a thin layer overxa.tmux. Itsrefis the tmux session name or a full pane ref (session:@window.%pane). Panes survive disconnection.ITermPanes: an iTerm2 tab on a Mac, driven through an injectedosascriptrunner. Itsrefis the iTerm session id, valid while iTerm runs. Every value reaches AppleScript throughon run argv, never spliced into the script text, so a directory or name containing a quote cannot break out.
>>> TmuxPanes().address("work").ref, TmuxPanes().address("work").provider
('work', 'tmux')
>>> str(PaneAddress("iterm", "ABC-1"))
'iterm:ABC-1'
Module Attributes
runs AppleScript with |
|
What |
|
Provider name -> factory (keyword arguments are the provider's own options). |
Functions
|
A |
|
The provider called |
Classes
|
iTerm2 tabs on a Mac. |
|
Provider-neutral name of one pane: which provider, and its own reference. |
|
Where panes live. |
|
tmux panes, through |
Exceptions
The provider cannot do this (e.g. stream a pane to a file). |
- class xa.panes.ITermPanes(*, profile='Default', run=None, known_profiles=None, ps=None)[source]¶
Bases:
objectiTerm2 tabs on a Mac.
runis the AppleScript runner (default:osascript_runner());known_profilesoptionally lists the profile names iTerm has, so a typo is an error before the GUI is touched (a typo otherwise opens a Default tab and looks like it worked).
- xa.panes.NO_GUI_SESSION = ('-609', '-600', 'Connection is invalid')¶
What
osascriptsays when the caller is outside the GUI’s launchd namespace (an SSH login): only then is thelaunchctl asuserretry made, so a failure that already did something (a tab opened, then an error) is never repeated.
- xa.panes.PROVIDERS: Mapping[str, Callable[..., PaneProvider]] = {'iterm': <class 'xa.panes.ITermPanes'>, 'tmux': <class 'xa.panes.TmuxPanes'>}¶
Provider name -> factory (keyword arguments are the provider’s own options).
- class xa.panes.PaneAddress(provider, ref)[source]¶
Bases:
objectProvider-neutral name of one pane: which provider, and its own reference.
- class xa.panes.PaneProvider(*args, **kwargs)[source]¶
Bases:
ProtocolWhere panes live. Implementations:
TmuxPanes,ITermPanes.- address(ref)[source]¶
The
PaneAddressof a pane of this provider.- Return type:
- capture(ref, *, lines=200)[source]¶
The last
linesof the pane’s text, or “” when it cannot be read.- Return type:
- create(name, *, command, cwd=None)[source]¶
Start a pane named
namerunning the shellcommand; return its address.- Return type:
- pane_pids(ref)[source]¶
The pids of the programs running in the pane (a root of each process tree; the claude process is one of them or below one).
[]when the pane is gone.
- stream_to_file(ref, path)[source]¶
Append the pane’s output to
pathas it appears (may raisePaneUnsupported).- Return type:
- exception xa.panes.PaneUnsupported[source]¶
Bases:
RuntimeErrorThe provider cannot do this (e.g. stream a pane to a file).
- xa.panes.Runner¶
runs AppleScript with
argsasargv.- Type:
Runner(script, args) -> stdout
- class xa.panes.TmuxPanes(*, binary='tmux')[source]¶
Bases:
objecttmux panes, through
xa.tmux(binaryis the tmux executable).
- xa.panes.osascript_runner(*, run=<function run>, uid=None, osascript='osascript', timeout=30.0)[source]¶
A
Runnerforosascript: directly first, and throughlaunchctl asuser <uid>(which needs root) only when the direct call says the caller has no GUI session (NO_GUI_SESSION).runis the subprocess seam.