コード例 #1
0
def _run(socket_name):
    f = asyncio.Future()

    output_transport, output_protocol = yield from loop.connect_write_pipe(
                    BaseProtocol, os.fdopen(0, 'wb', 0))

    # Establish server connection
    def factory():
        return ClientProtocol(output_transport, lambda: f.set_result(None))

    s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    s.connect(socket_name)
    transport, protocol = yield from loop.create_connection(factory, sock=s)

    # Input
    input_transport, input_protocol = yield from loop.connect_read_pipe(
                    lambda:InputProtocol(protocol.send_input), os.fdopen(0, 'rb', 0))

    # Send terminal size to server when it changes
    def sigwinch_handler():
        loop.call_soon(protocol.send_size)
    loop.add_signal_handler(signal.SIGWINCH, sigwinch_handler)

    with alternate_screen(output_transport.write):
        with raw_mode(0):
            # Tell the server that we want to attach to the session
            yield from protocol.call_remote(AttachClient)

            # Run loop and wait for detach command
            yield from f
コード例 #2
0
def run():
    # Output transport/protocol
    output_transport, output_protocol = yield from loop.connect_write_pipe(BaseProtocol, os.fdopen(0, 'wb'))

    with raw_mode(sys.stdin.fileno()):
        # Enter alternate screen buffer
        with alternate_screen(output_transport.write):
            # Create session and renderer
            session = Session()
            renderer = Rot13Renderer(output_transport.write)
            session.add_renderer(renderer)

            # Setup layout
            window = Window()
            session.add_window(window)
            pane = BashPane()
            window.add_pane(pane)

            # handle resize events
            call_on_sigwinch(session.update_size)

            # Input transport/protocol
            input_transport, input_protocol = yield from loop.connect_read_pipe(
                                lambda:InputProtocol(session), sys.stdin)

            # Wait for everything to finish
            yield from pane.run()
コード例 #3
0
def run():
    finish_f = asyncio.Future()

    # Output transport/protocol
    output_transport, output_protocol = yield from loop.connect_write_pipe(BaseProtocol, os.fdopen(0, 'wb'))

    with raw_mode(sys.stdin.fileno()):
        # Enter alternate screen buffer
        with alternate_screen(output_transport.write):
            # Create session and renderer
            session = Session()
            renderer = PipeRenderer(output_transport.write)
            session.add_renderer(renderer)

            # Setup layout
            window = Window()
            session.add_window(window)
            pane1 = PythonPane()
            pane2 = PythonPane()
            window.add_pane(pane1)
            window.add_pane(pane2, vsplit=True)

            # handle resize events
            call_on_sigwinch(session.update_size)

            # Input transport/protocol
            done = lambda: finish_f.set_result(None)
            yield from loop.connect_read_pipe(lambda:OurInputProtocol(session, done), sys.stdin)

            # Run panes
            asyncio.async(pane1.run())
            asyncio.async(pane2.run())

            # Wait for any key press to exit.
            yield from finish_f
コード例 #4
0
def run():
    # Output transport/protocol
    output_transport, output_protocol = yield from loop.connect_write_pipe(BaseProtocol, os.fdopen(0, 'wb'))

    with raw_mode(sys.stdin.fileno()):
        # Enter alternate screen buffer
        with alternate_screen(output_transport.write):
            # Create session and renderer
            session = PyMuxSession()
            renderer = PipeRenderer(output_transport.write)
            session.add_renderer(renderer)

            # handle resize events
            call_on_sigwinch(session.update_size)

            # Input transport/protocol
            input_transport, input_protocol = yield from loop.connect_read_pipe(
                                lambda:PyMuxInputProtocol(session), sys.stdin)

            yield from session.run()
コード例 #5
0
def run():
    # Output transport/protocol
    output_transport, output_protocol = yield from loop.connect_write_pipe(
        BaseProtocol, os.fdopen(0, 'wb'))

    with raw_mode(sys.stdin.fileno()):
        # Enter alternate screen buffer
        with alternate_screen(output_transport.write):
            # Create session and renderer
            session = PyMuxSession()
            renderer = PipeRenderer(output_transport.write)
            session.add_renderer(renderer)

            # handle resize events
            call_on_sigwinch(session.update_size)

            # Input transport/protocol
            input_transport, input_protocol = yield from loop.connect_read_pipe(
                lambda: PyMuxInputProtocol(session), sys.stdin)

            yield from session.run()
コード例 #6
0
def run(filenames):
    # Output transport/protocol
    output_transport, output_protocol = yield from loop.connect_write_pipe(BaseProtocol, os.fdopen(0, 'wb'))

    with raw_mode(sys.stdin.fileno()):
        # Enter alternate screen buffer
        with alternate_screen(output_transport.write):
            # Create session and renderer
            session = Session()
            renderer = PipeRenderer(output_transport.write)
            session.add_renderer(renderer)

            # Setup layout
            window = Window()
            session.add_window(window)
            panes = []

            for filename in filenames:
                pane = TailPane(filename)
                window.add_pane(pane, vsplit=False)
                panes.append(pane)

            # handle resize events
            call_on_sigwinch(session.update_size)

            # Input transport/protocol
            input_transport, input_protocol = yield from loop.connect_read_pipe(
                                lambda:OurInputProtocol(session), sys.stdin)

            @asyncio.coroutine
            def run_pane(p):
                yield from p.run()
                window.remove_pane(p)

            # Wait for everything to finish
            yield from asyncio.gather(* [ asyncio.async(run_pane(p)) for p in panes ])
コード例 #7
0
def run():
    # Output transport/protocol
    output_transport, output_protocol = yield from loop.connect_write_pipe(BaseProtocol, os.fdopen(0, 'wb'))

    with raw_mode(sys.stdin.fileno()):
        # Enter alternate screen buffer
        with alternate_screen(output_transport.write):
            # Create session and renderer
            session = Session()
            renderer = PipeRenderer(output_transport.write)
            session.add_renderer(renderer)

            # Setup layout
            window = Window()
            session.add_window(window)
            pane1 = BashPane()
            pane2 = BashPane()
            window.add_pane(pane1)
            window.add_pane(pane2, vsplit=True)

            # handle resize events
            call_on_sigwinch(session.update_size)

            # Input transport/protocol
            input_transport, input_protocol = yield from loop.connect_read_pipe(
                                lambda:OurInputProtocol(session), sys.stdin)

            @asyncio.coroutine
            def run_pane(p):
                yield from p.run()
                window.remove_pane(p)

            # Wait for everything to finish
            yield from asyncio.gather(
                    asyncio.async(run_pane(pane1)),
                    asyncio.async(run_pane(pane2))) # XXX: if we call pane1.run() twice. We get very weird errors!!!