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 go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield ui_open_simple_pane(StrIdent('two')) yield TS.modify(minimize_layout('right')) yield simple_render() yield all_panes().state self._wait(1)
def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield ui_open_simple_pane(StrIdent('two')) yield open_simple_pane(StrIdent('three')) yield TS.modify(minimize_layout('sub')) yield simple_render() yield all_panes().state
def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield ui_open_simple_pane(StrIdent('two')) yield open_simple_pane(StrIdent('three')) panes = yield all_panes().state positions = panes / _.position yield TS.from_maybe(positions.lift_all(0, 1, 2), 'invalid number of panes')
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 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 open_simple_pane(ident: Ident) -> Do: yield ui_open_simple_pane(ident) yield simple_render() yield TS.write('display-panes')
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 ui_open_simple_pane(spec: IdentSpec) -> Do: yield TS.modify_e(ui_open_pane(spec)).zoom(lens.layout)
def simple_render() -> Do: layout = yield TS.inspect(_.layout) yield render(P=SimplePane, L=SimpleLayout)(StrIdent('main'), StrIdent('main'), layout).transform_s_lens(lens.views)
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 pane_id_fatal(pane: Pane) -> TS[D, str]: return TS.from_either(pane.id.to_either(lambda: f'pane has no id: {pane}'))
def window_by_ident(ident: Ident) -> TS[Views, Window]: return TS.inspect_either(lambda a: a.window_by_ident(ident))
def pane_by_ident(ident: Ident) -> TS[Views, Pane]: return TS.inspect_either(__.pane_by_ident(ident))
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))
def tracked_window(self, win: TrackedWindow) -> Do: ref = yield TS.from_either(find_pane(win.pane.ident)(win.layout)) width, height = int(win.native_window.width), int(win.native_window.height) measure_tree = measure_view_tree(self.bindings)(win.layout, width, height) yield pack_tree(self.session, self.window, self.principal)(measure_tree, ref)
def layout_node(self, node: MeasuredLayoutNode) -> Do: layout_reference = yield reference_pane(node) reference = yield TS.from_either(layout_reference) yield resize_view_with(node.data, reference.ident, self.vertical)
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 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'))
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_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 go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield open_simple_pane(StrIdent('two')) yield all_panes().state yield TS.lift(pdata())
def pane_by_id(id: str) -> TS[Views, Either[str, Pane]]: return TS.inspect(__.panes.find(__.id.contains(id)).to_either(lambda: f'no tmux pane for `{id}`'))