ianux 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ianux/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """ianux — spin up a named tmux development session with multiple panes."""
2
+
3
+ __version__ = "0.2.0"
ianux/__main__.py ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env python3.11
2
+ """Entry point for `python -m ianux`.
3
+
4
+ main() accepts an optional argv list so callers (tests, scripts) can drive
5
+ the tool without touching sys.argv. entrypoint() wraps main() with error
6
+ handling and is what the shell shim and __name__ == "__main__" both call.
7
+ """
8
+
9
+ import sys
10
+
11
+ from .attacher import SessionAttacher
12
+ from .cli import build_resolver, parse_args
13
+ from .config import AttachConfig, DumpConfig, KillConfig, LoadConfig, RunConfig, ListConfig
14
+ from .dumper import SessionDumper
15
+ from .exceptions import AppError
16
+ from .killer import SessionKiller
17
+ from .loader import load_session_config
18
+ from .runner import SessionRunner
19
+ from .session import SessionManager
20
+ from .tmux import TmuxClient
21
+ from .lister import SessionLister
22
+
23
+
24
+ def main(argv: list[str] | None = None) -> int:
25
+ """Parse *argv*, dispatch to the matching manager, and return its exit code."""
26
+ config = parse_args(argv)
27
+ client = TmuxClient()
28
+
29
+ if isinstance(config, AttachConfig):
30
+ return SessionAttacher(client).attach(config)
31
+
32
+ if isinstance(config, KillConfig):
33
+ return SessionKiller(client).kill(config)
34
+
35
+ if isinstance(config, RunConfig):
36
+ return SessionRunner(client).run(config)
37
+
38
+ if isinstance(config,ListConfig):
39
+ return SessionLister(client).list(config)
40
+
41
+ if isinstance(config, DumpConfig):
42
+ return SessionDumper(client).dump(config)
43
+
44
+ if isinstance(config, LoadConfig):
45
+ config = load_session_config(config)
46
+ # Falls through to the SessionConfig flow below.
47
+
48
+ # SessionConfig — existing multi-pane dev session flow.
49
+ resolver = build_resolver(config)
50
+ return SessionManager(client).setup(config, resolver)
51
+
52
+
53
+ def entrypoint() -> int:
54
+ """Run main(), converting an AppError into a printed message and exit code 1."""
55
+ try:
56
+ return main()
57
+ except AppError as exc:
58
+ print(f"Error: {exc}", file=sys.stderr)
59
+ return 1
60
+
61
+
62
+ if __name__ == "__main__":
63
+ raise SystemExit(entrypoint())
ianux/attacher.py ADDED
@@ -0,0 +1,65 @@
1
+ """SessionAttacher — list open sessions and attach to one interactively.
2
+
3
+ Two usage modes:
4
+
5
+ Interactive (session_name is None)
6
+ Lists all open tmux sessions with numeric IDs (1-based, matching the
7
+ 'list' subcommand), prompts the user to choose one, then attaches.
8
+
9
+ Direct (session_name is provided)
10
+ Accepts a tmux-style address: ``SESSION``, ``SESSION:WINDOW`` or
11
+ ``SESSION:WINDOW.PANE`` (mirrors the 'kill' subcommand's target
12
+ format). SESSION may be a literal name or one of the numeric IDs
13
+ shown by 'list'/the picker; WINDOW and PANE are tmux's own indices,
14
+ as displayed in 'list'. Validates the session exists and attaches
15
+ immediately, skipping the picker.
16
+ """
17
+
18
+ from typing import Callable
19
+
20
+ from .config import AttachConfig
21
+ from .exceptions import AppError
22
+ from .killer import _Target, _parse_target, resolve_session_id
23
+ from .picker import pick_session
24
+ from .tmux import TmuxClient
25
+
26
+
27
+ class SessionAttacher:
28
+ """Handles the 'attach' subcommand: direct-target and interactive modes."""
29
+
30
+ def __init__(
31
+ self,
32
+ client: TmuxClient,
33
+ prompt_fn: Callable[[str], str] = input,
34
+ ) -> None:
35
+ self._client = client
36
+ self._prompt = prompt_fn
37
+
38
+ def attach(self, config: AttachConfig) -> int:
39
+ if config.session_name is not None:
40
+ return self._attach_direct(config.session_name)
41
+ return self._attach_interactive()
42
+
43
+ # ------------------------------------------------------------------
44
+ # Internals
45
+ # ------------------------------------------------------------------
46
+
47
+ def _attach_direct(self, address: str) -> int:
48
+ t = _parse_target(address)
49
+ session = resolve_session_id(self._client, t.session)
50
+ if not self._client.session_exists(session):
51
+ raise AppError(f"Session '{session}' does not exist.")
52
+ self._client.attach(self._build_target(session, t))
53
+ return 0
54
+
55
+ def _build_target(self, session: str, t: _Target) -> str:
56
+ """Combine the resolved session name with the window/pane part of *t*."""
57
+ if t.kind == "pane":
58
+ return f"{session}:{t.window}.{t.pane}"
59
+ if t.kind in ("window", "panes_all"):
60
+ return f"{session}:{t.window}"
61
+ return session
62
+
63
+ def _attach_interactive(self) -> int:
64
+ self._client.attach(pick_session(self._client, self._prompt))
65
+ return 0