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 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 pane_id_fatal(pane: Pane) -> TS[D, str]: return TS.from_either(pane.id.to_either(lambda: f'pane has no id: {pane}'))