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 pane_node(self, node: PaneNode[LO, P]) -> Do: pane = node.data tpane = yield find_or_create_pane(node.data.ident).tmux tpane1 = yield TS.lift(pane_from_data(self.window, tpane)) dir = yield TS.lift(pane_dir(pane)) yield ( ensure_pane_open(self.window, tpane, tpane1, dir) if pane.open else ensure_pane_closed(self.window, tpane, tpane1) )
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_window(session: Session, window: Window, window_ident: Ident, layout: ViewTree) -> Do: @do(TS[Views, Window]) def create(error: str) -> Do: log.debug(f'creating missing tmux window {window} ({window_ident}) because {error}') yield create_tmux_window(session, window_ident) io = existing_window(session, window).map(TS.pure).recover_error(create) window_data = yield TS.lift(io).join yield sync_principal(window_ident, layout) return Window.cons(window_ident, window_data.id)
def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield open_simple_pane(StrIdent('two')) yield all_panes().state yield TS.lift(pdata())
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 create_and_update_session(session: Session) -> Do: session_data = yield TS.lift(create_session(session.ident.str)) updated_session = session.set.id(Just(session_data.id)) yield TS.modify(__.update_session(updated_session)) return updated_session
def create_tmux_window(session: Session, ident: Ident) -> Do: sid = yield TS.from_maybe(session.id, 'no session id') yield TS.lift(create_window(sid, ident.str))
def resize_view_with(mview: MeasuredView[A], pane_ident: Ident, vertical: bool) -> Do: size = mview.measures.size tpane = yield pane_by_ident(pane_ident) id = yield pane_id_fatal(tpane) log.debug(f'resize {mview.view} to {size} ({vertical})') yield TS.lift(resize_pane(id, vertical, size))
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 create_tmux_pane(window: Window, pane: Pane, dir: Path) -> Do: log.debug(f'creating tmux pane {pane} in {window}') data = yield TS.lift(create_pane_from_data(window, pane, dir)) yield TS.modify(__.set_pane_id(pane, data.id))