def ensure_session(session: Session) -> Do: exists = yield TS.lift(session.id.map(session_exists) | TmuxIO.pure(false)) yield TS.pure(session) if exists else create_and_update_session(session)
def recurse() -> Do: result = yield thunk() done = check(result) yield (TmuxIO.pure(result) if done else TmuxIO.error(error) if time.time() - start > timeout else wait_and_recurse())
def pure(self, a: A) -> TmuxIO[A]: return TmuxIO.pure(a)
def simple_tmux_cmd_attrs(cmd: str, args: List[str], attrs: List[str]) -> Do: output = yield TmuxIO.read(cmd, '-F', tmux_fmt_attrs(attrs), *args) yield TmuxIO.pure(output / L(tmux_attr_map)(attrs, _))
def capture_pane(id: int) -> Do: output = yield TmuxIO.read(*pane_cmd(id, 'capture-pane', '-p')) yield TmuxIO.pure(output.reversed.drop_while(_ == '').reversed)
def pane_from_data(window: Window, pane: Pane) -> Do: yield (pane_loc(window, pane) / pane_from_loc).value_or(lambda e: TmuxIO.pure(Left(e)))
def tmux_pane_open(pane: Ident) -> Do: tpane = yield pane_by_ident(pane) yield TS.lift(tpane.id.cata(pane_open, lambda: TmuxIO.pure(false)))
def from_id(self, st: State[S, A]) -> 'TmuxIOState[S, A]': return st.transform_f(TmuxIOState, lambda s: TmuxIO.pure(s.value))