def move_tmux_pane(pane: Ident, reference: Ident, vertical: Boolean) -> Do: tpane = yield pane_by_ident(pane) ref_tpane = yield pane_by_ident(reference) id = yield pane_id_fatal(tpane) ref_id = yield pane_id_fatal(ref_tpane) is_open = yield TS.lift(pane_open(id)) yield TS.lift(move_pane(id, ref_id, vertical)) if is_open else TS.pure(None)
def window_state(ui_window: Ident, twindow: Window, layout: ViewTree) -> Do: window_id = yield TS.from_maybe(twindow.id, 'window_state: `{twindow}` has no id') native_window_e = yield TS.lift(window(window_id)) native_window = yield TS.from_either(native_window_e) panes = yield TS.lift(window_panes(window_id)) native_pane, tail = yield TS.from_maybe(panes.detach_head, 'no panes in window') reference_pane = yield pane_by_id(native_pane.id) state = ( reference_pane .map(L(TrackedWindow)(native_window, ui_window, layout, native_pane, _)) | L(PristineWindow)(native_window, ui_window, layout, native_pane) ) yield TS.pure(state)
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 reference_pane(node: MeasuredLayoutNode) -> Do: open = yield layout_panes(node).map(_.data.view).traverse(lambda p: tmux_pane_open(p.ident).map(__.m(p)), TS) yield TS.pure(open.join.head.to_either(f'no open pane in layout'))