예제 #1
0
파일: pid.py 프로젝트: tek/chiasma-py
def discover_pane_by_pid(target_pid: int) -> Do:
    panes = yield all_panes()
    indicators = yield TmuxIO.from_io(
        panes.traverse(lambda a: contains_child_pid(target_pid, a), IO))
    candidate = panes.zip(indicators).find_map(lambda a: a[1].m(a[0]))
    yield TmuxIO.from_maybe(candidate,
                            f'could not find pane with pid `{target_pid}`')
예제 #2
0
def create_pane_from_data(window: Window, pane: Pane, dir: Path) -> Do:
    target_window = yield TmuxIO.from_maybe(window.id,
                                            lambda: f'{window} has no id')
    args = List('-t', window_id(target_window), '-d', '-P', '-c', dir)
    panes = yield tmux_data_cmd('split-window', args, cmd_data_pane)
    yield TmuxIO.from_maybe(
        panes.head, lambda: f'no output when creating pane in {window}')
예제 #3
0
파일: tmux_spec.py 프로젝트: tek/chiasma-py
 def setup(self) -> None:
     self.tmux_proc = start_tmux(tmux_spec_socket, self.win_width,
                                 self.win_height, self.tmux_in_terminal())
     self.tmux = Tmux.cons(tmux_spec_socket)
     self._wait(.2)
     cmd = TmuxIO.read('list-clients -F "#{client_name}"')
     self.tmux_client = cmd.unsafe(self.tmux).head.get_or_fail('no clients')
예제 #4
0
파일: klk.py 프로젝트: tek/chiasma-py
def setup_test_tmux(config: TestConfig) -> Tuple[subprocess.Popen, str, Tmux]:
    tmux_proc = start_tmux(config.socket, config.win_width, config.win_height,
                           config.terminal)
    tmux = Tmux.cons(tmux_spec_socket)
    time.sleep(.2)
    cmd = TmuxIO.read('list-clients -F "#{client_name}"')
    tmux_client = cmd.unsafe(tmux).head.get_or_fail('no clients')
    return tmux_proc, tmux_client, tmux
예제 #5
0
파일: klk.py 프로젝트: tek/chiasma-py
def unit_test(
    io: Callable[..., TS[SpecData, Expectation]],
    config: TestConfig = TestConfig.cons(),
    *a: Any,
    **kw: Any,
) -> Expectation:
    tmux_proc, tmux_client, tmux = setup_test_tmux(config)

    @do(TmuxIO[Expectation])
    def run() -> Do:
        data = SpecData.cons(config.layout)
        yield io(*a, **kw).run_a(data)

    return run_test_io(
        TmuxIO.to_io(run(), tmux).ensure, cleanup(tmux_proc, tmux))
예제 #6
0
def tmuxio_repeat_timeout(
    thunk: Callable[[], TmuxIO[A]],
    check: Callable[[A], bool],
    error: str,
    timeout: float,
    interval: float = None,
) -> Do:
    effective_interval = .01 if interval is None else interval
    start = yield TmuxIO.simple(time.time)

    @do(TmuxIO[None])
    def wait_and_recurse() -> Do:
        yield TmuxIO.sleep(effective_interval)
        yield recurse()

    @do(TmuxIO[None])
    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())

    yield recurse()
예제 #7
0
파일: state.py 프로젝트: tek/chiasma-py
 def failed(self, e: str) -> 'TmuxIOState[S, A]':
     return TmuxIOState.lift(TmuxIO.failed(e))
예제 #8
0
def simple_tmux_cmd_attr(cmd: str, args: List[str], attr: str) -> Do:
    attrs = yield simple_tmux_cmd_attrs(cmd, args, List(attr))
    yield TmuxIO.from_maybe(attrs.traverse(lambda a: a.lift(attr), Maybe),
                            f'attr `{attr}` missing in output')
예제 #9
0
def tmux_data_cmd(cmd: str, args: List[str], cmd_data: TmuxCmdData[A]) -> Do:
    data = yield simple_tmux_cmd_attrs(cmd, args, cmd_data.attrs)
    yield TmuxIO.from_either(cons_tmux_data(data, cmd_data.cons))
예제 #10
0
파일: server.py 프로젝트: tek/chiasma-py
def kill_server() -> TmuxIO[None]:
    return TmuxIO.write('kill-server')
예제 #11
0
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, _))
예제 #12
0
def pane(pane_id: int) -> Do:
    panes = yield all_panes()
    yield TmuxIO.from_maybe(panes.find(_.id == pane_id),
                            f'no pane with id `{pane_id}`')
예제 #13
0
def create_window(target_session: int, ident: str) -> Do:
    args = List('-t', f'{session_id(target_session)}:', '-n', ident, '-P')
    windows = yield tmux_data_cmd('new-window', args, cmd_data_window)
    yield TmuxIO.from_maybe(windows.head,
                            f'no output when creating window `{ident}`')
예제 #14
0
파일: main.py 프로젝트: tek/chiasma-py
def existing_window(session: Session, window: Window) -> Do:
    sid = yield TmuxIO.from_maybe(session.id, 'session has no id')
    wid = yield TmuxIO.from_maybe(window.id, 'window has no id')
    e = yield session_window(sid, wid)
    yield TmuxIO.from_either(e)
예제 #15
0
 def pure(self, a: A) -> TmuxIO[A]:
     return TmuxIO.pure(a)
예제 #16
0
def move_pane(id: int, ref_id: int, vertical: Boolean) -> TmuxIO[None]:
    direction = '-v' if vertical else '-h'
    return TmuxIO.write('move-pane', '-d', '-s', pane_id(id), '-t',
                        pane_id(ref_id), direction)
예제 #17
0
 def wait_and_recurse() -> Do:
     yield TmuxIO.sleep(effective_interval)
     yield recurse()
예제 #18
0
def resize_pane(id: int, vertical: Boolean, size: int) -> TmuxIO[None]:
    direction = '-y' if vertical else '-x'
    return TmuxIO.write('resize-pane', '-t', pane_id(id), direction, size)
예제 #19
0
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)))
예제 #20
0
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)))
예제 #21
0
파일: tmux_spec.py 프로젝트: tek/chiasma-py
 def run(self, prog: TS[D, None], data: D) -> None:
     self._wait(.2)
     r = prog.run(data).unsafe(self.tmux)
     TmuxIO.write('display-panes', '-t', self.tmux_client).result(self.tmux)
     self._wait(.2)
     return r
예제 #22
0
def create_session(name: str) -> Do:
    sessions = yield tmux_data_cmd('new-session', List('-s', name, '-P'),
                                   cmd_data_session)
    yield TmuxIO.from_maybe(sessions.head,
                            f'no output when creating session `{name}`')
예제 #23
0
def close_pane_id(pane_id: int) -> TmuxIO[None]:
    return TmuxIO.write(*pane_cmd(pane_id, 'kill-pane'))
예제 #24
0
def window_pane(wid: int, pane_id: int) -> Do:
    panes = yield window_panes(wid)
    yield TmuxIO.from_maybe(panes.find(_.id == pane_id),
                            f'no pane with id `{pane_id}`')
예제 #25
0
 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())
예제 #26
0
def capture_pane(id: int) -> Do:
    output = yield TmuxIO.read(*pane_cmd(id, 'capture-pane', '-p'))
    yield TmuxIO.pure(output.reversed.drop_while(_ == '').reversed)
예제 #27
0
파일: main.py 프로젝트: tek/chiasma-py
def pane_dir(pane: P) -> Do:
    ui_pane = yield TmuxIO.from_either(UiPane.e_for(pane))
    yield (ui_pane.cwd(pane) / TmuxIO.pure).get_or(lambda: TmuxIO.from_io(IO.delay(Path.cwd)))
예제 #28
0
def pipe_pane(id: int, path: Path) -> TmuxIO[None]:
    return TmuxIO.write(
        *pane_cmd(id, 'pipe-pane', quote(f'{pipe_filter} > {str(path)}')))
예제 #29
0
파일: session.py 프로젝트: tek/chiasma-py
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)
예제 #30
0
def select_pane(id: int) -> TmuxIO[int]:
    return TmuxIO.write(*pane_cmd(id, 'select-pane'))