Example #1
0
        def run():
            with context() as ctx_id:
                self._context_id = ctx_id

                # Set input/output for all application running in this context.
                set_default_input(self.vt100_input)
                set_default_output(self.vt100_output)

                # Add reader.
                loop = get_event_loop()
                loop.add_reader(self.conn, handle_incoming_data)

                try:
                    obj = self.interact(self)
                    if _is_coroutine(obj):
                        # Got an asyncio coroutine.
                        import asyncio
                        f = asyncio.ensure_future(obj)
                        yield From(Future.from_asyncio_future(f))
                    else:
                        # Got a prompt_toolkit coroutine.
                        yield From(obj)
                except Exception as e:
                    print('Got %s' % type(e).__name__, e)
                    import traceback
                    traceback.print_exc()
                    raise
                finally:
                    self.close()
Example #2
0
File: main.py Project: ashang/pymux
        def connection_cb(pipe_connection):
            # We have to create a new `context`, because this will be the scope for
            # a new prompt_toolkit.Application to become active.
            with context():
                connection = ServerConnection(self, pipe_connection)

            self.connections.append(connection)
Example #3
0
        def connection_cb(pipe_connection):
            # We have to create a new `context`, because this will be the scope for
            # a new prompt_toolkit.Application to become active.
            with context():
                connection = ServerConnection(self, pipe_connection)

            self.connections.append(connection)
Example #4
0
 async def aprompt(*args, **kwargs):
     nonlocal context_id
     kwargs['async_'] = True
     kwargs['input'] = vt100_input
     kwargs['output'] = vt100_output
     with context() as context_id:
         return await prompt(*args, **kwargs)
Example #5
0
 def _run_in_terminal(self, func):
     # Make sure that when an application was active for this connection,
     # that we print the text above the application.
     with context(self._context_id):
         try:
             app = get_app(raise_exception=True)
         except NoRunningApplicationError:
             func()
             return Future.succeed(None)
         else:
             return app.run_in_terminal(func)
Example #6
0
 def _run_in_terminal(self, func):
     # Make sure that when an application was active for this connection,
     # that we print the text above the application.
     with context(self._context_id):
         return run_in_terminal(func)
Example #7
0
 def size_changed(*_):
     with context(context_id):
         get_app()._on_resize()