def create_pane_from_data(window: Window, pane: Pane, dir: Path) -> Do: target_window = yield TmuxIO.from_maybe(window.id, lambda: f'{window} has no id') args = List('-t', window_id(target_window), '-d', '-P', '-c', dir) panes = yield tmux_data_cmd('split-window', args, cmd_data_pane) yield TmuxIO.from_maybe( panes.head, lambda: f'no output when creating pane in {window}')
def discover_pane_by_pid(target_pid: int) -> Do: panes = yield all_panes() indicators = yield TmuxIO.from_io( panes.traverse(lambda a: contains_child_pid(target_pid, a), IO)) candidate = panes.zip(indicators).find_map(lambda a: a[1].m(a[0])) yield TmuxIO.from_maybe(candidate, f'could not find pane with pid `{target_pid}`')
def existing_window(session: Session, window: Window) -> Do: sid = yield TmuxIO.from_maybe(session.id, 'session has no id') wid = yield TmuxIO.from_maybe(window.id, 'window has no id') e = yield session_window(sid, wid) yield TmuxIO.from_either(e)
def simple_tmux_cmd_attr(cmd: str, args: List[str], attr: str) -> Do: attrs = yield simple_tmux_cmd_attrs(cmd, args, List(attr)) yield TmuxIO.from_maybe(attrs.traverse(lambda a: a.lift(attr), Maybe), f'attr `{attr}` missing in output')
def create_window(target_session: int, ident: str) -> Do: args = List('-t', f'{session_id(target_session)}:', '-n', ident, '-P') windows = yield tmux_data_cmd('new-window', args, cmd_data_window) yield TmuxIO.from_maybe(windows.head, f'no output when creating window `{ident}`')
def pane(pane_id: int) -> Do: panes = yield all_panes() yield TmuxIO.from_maybe(panes.find(_.id == pane_id), f'no pane with id `{pane_id}`')
def window_pane(wid: int, pane_id: int) -> Do: panes = yield window_panes(wid) yield TmuxIO.from_maybe(panes.find(_.id == pane_id), f'no pane with id `{pane_id}`')
def create_session(name: str) -> Do: sessions = yield tmux_data_cmd('new-session', List('-s', name, '-P'), cmd_data_session) yield TmuxIO.from_maybe(sessions.head, f'no output when creating session `{name}`')
def from_maybe(self, a: Maybe[B], err: CallByName) -> 'TmuxIOState[S, B]': return TmuxIOState.lift(TmuxIO.from_maybe(a, err))
def inspect_maybe(self, f: Callable[[S], Maybe[A]], err: CallByName) -> 'TmuxIOState[S, A]': return TmuxIOState.inspect_f(lambda s: TmuxIO.from_maybe(f(s), err))