def get_window_size(self): """ Get the size to be used for the DynamicBody. This will be the smallest size of all clients. """ def active_window_for_app(app): with set_app(app): return self.arrangement.get_active_window() active_window = self.arrangement.get_active_window() # Get sizes for connections watching the same window. apps = [ client_state.app for client_state in self._client_states.values() if active_window_for_app(client_state.app) == active_window ] sizes = [app.output.get_size() for app in apps] rows = [s.rows for s in sizes] columns = [s.columns for s in sizes] if rows and columns: return Size(rows=min(rows) - (1 if self.enable_status else 0), columns=min(columns)) else: return Size(rows=20, columns=80)
def get_window_size(self, cli): """ Get the size to be used for the DynamicBody. This will be the smallest size of all clients. """ get_active_window = self.arrangement.get_active_window active_window = get_active_window(cli) # Get connections watching the same window. connections = [ c for c in self.connections if c.cli and get_active_window(c.cli) == active_window ] rows = [c.size.rows for c in connections] columns = [c.size.columns for c in connections] if self._runs_standalone: r, c = _get_size(sys.stdout.fileno()) rows.append(r) columns.append(c) if rows and columns: return Size(rows=min(rows) - (1 if self.enable_status else 0), columns=min(columns)) else: return Size(rows=20, columns=80)
def _get_size(self): """ Callable that returns the current `Size`, required by Vt100_Output. """ if self._chan is None: return Size(rows=20, columns=79) else: width, height, pixwidth, pixheight = self._chan.get_terminal_size() return Size(rows=height, columns=width)
def get_size(self): """ This seems not needed intuitively (must an output file have a size? can't we avoid it?) """ return Size(rows=40, columns=80)
def _process(self, data): """ Process packet received from client. """ packet = json.loads(data.decode('utf-8')) # Handle commands. if packet['cmd'] == 'run-command': self._run_command(packet) # Handle stdin. elif packet['cmd'] == 'in': self._inputstream.feed(packet['data']) elif packet['cmd'] == 'flush-input': self._inputstream.flush() # Flush escape key. # Set size. (The client reports the size.) elif packet['cmd'] == 'size': data = packet['data'] self.size = Size(rows=data[0], columns=data[1]) self.pymux.invalidate() # Start GUI. (Create CommandLineInterface front-end for pymux.) elif packet['cmd'] == 'start-gui': detach_other_clients = bool(packet['detach-others']) true_color = bool(packet['true-color']) if detach_other_clients: for c in self.pymux.connections: c.detach_and_close() self._create_cli(true_color=true_color)
def __init__(self, reader, writer, shell, loop): super(ShellConnection, self).__init__(reader, writer) self._shell = shell self._loop = loop self._cli = None self._cb = None self._size = Size(rows=40, columns=79) self.encoding = 'utf-8'
def get_size(): # If terminal (incorrectly) reports its size as 0, pick a # reasonable default. See # https://github.com/ipython/ipython/issues/10071 rows, columns = (None, None) if isatty: rows, columns = _get_size(stdout.fileno()) return Size(rows=rows or 24, columns=columns or 80)
def __init__(self, pymux, connection, client_address): self.pymux = pymux self.connection = connection self.client_address = client_address self.size = Size(rows=20, columns=80) self._closed = False self._recv_buffer = b'' self.cli = None self._inputstream = InputStream( lambda key: self.cli.input_processor.feed_key(key)) pymux.eventloop.add_reader(connection.fileno(), self._recv)
def __init__(self, conn, addr, interact, server, encoding, style): assert isinstance(addr, tuple) # (addr, port) tuple assert callable(interact) assert isinstance(server, TelnetServer) assert isinstance(encoding, text_type) # e.g. 'utf-8' assert isinstance(style, BaseStyle) self.conn = conn self.addr = addr self.interact = interact self.server = server self.encoding = encoding self.style = style self._closed = False # Execution context. self._context_id = None # Create "Output" object. self.size = Size(rows=40, columns=79) # Initialize. _initialize_telnet(conn) # Create input. self.vt100_input = PipeInput() # Create output. def get_size(): return self.size self.stdout = _ConnectionStdout(conn, encoding=encoding) self.vt100_output = Vt100_Output(self.stdout, get_size, write_binary=False) def data_received(data): """ TelnetProtocolParser 'data_received' callback """ assert isinstance(data, binary_type) self.vt100_input.send_bytes(data) def size_received(rows, columns): """ TelnetProtocolParser 'size_received' callback """ self.size = Size(rows=rows, columns=columns) get_app()._on_resize() self.parser = TelnetProtocolParser(data_received, size_received)
def __init__(self, pymux, pipe_connection): self.pymux = pymux self.pipe_connection = pipe_connection self.size = Size(rows=20, columns=80) self._closed = False self._recv_buffer = b'' self.client_state = None def feed_key(key): self.client_state.app.key_processor.feed(key) self.client_state.app.key_processor.process_keys() self._inputstream = Vt100Parser(feed_key) self._pipeinput = _ClientInput(self._send_packet) ensure_future(self._start_reading())
def _process(self, data): """ Process packet received from client. """ try: packet = json.loads(data.decode('utf-8')) except ValueError: # So far, this never happened. But it would be good to have some # protection. logger.warning('Received invalid JSON from client. Ignoring.') return # Handle commands. if packet['cmd'] == 'run-command': self._run_command(packet) # Handle stdin. elif packet['cmd'] == 'in': self._inputstream.feed(packet['data']) elif packet['cmd'] == 'flush-input': self._inputstream.flush() # Flush escape key. # Set size. (The client reports the size.) elif packet['cmd'] == 'size': data = packet['data'] self.size = Size(rows=data[0], columns=data[1]) self.pymux.invalidate() # Start GUI. (Create CommandLineInterface front-end for pymux.) elif packet['cmd'] == 'start-gui': detach_other_clients = bool(packet['detach-others']) true_color = bool(packet['true-color']) ansi_colors_only = bool(packet['ansi-colors-only']) term = packet['term'] if detach_other_clients: for c in self.pymux.connections: c.detach_and_close() self._create_cli(true_color=true_color, ansi_colors_only=ansi_colors_only, term=term)
def _process(self, data): """ Process packet received from client. """ try: packet = json.loads(data) except ValueError: # So far, this never happened. But it would be good to have some # protection. logger.warning('Received invalid JSON from client. Ignoring.') return # Handle commands. if packet['cmd'] == 'run-command': self._run_command(packet) # Handle stdin. elif packet['cmd'] == 'in': self._pipeinput.send_text(packet['data']) # elif packet['cmd'] == 'flush-input': # self._inputstream.flush() # Flush escape key. # XXX: I think we no longer need this. # Set size. (The client reports the size.) elif packet['cmd'] == 'size': data = packet['data'] self.size = Size(rows=data[0], columns=data[1]) self.pymux.invalidate() # Start GUI. (Create CommandLineInterface front-end for pymux.) elif packet['cmd'] == 'start-gui': detach_other_clients = bool(packet['detach-others']) color_depth = packet['color-depth'] term = packet['term'] if detach_other_clients: for c in self.pymux.connections: c.detach_and_close() print('Create app...') self._create_app(color_depth=color_depth, term=term)
def __init__(self, conn, addr, application, server, encoding): assert isinstance(addr, tuple) # (addr, port) tuple assert isinstance(application, TelnetApplication) assert isinstance(server, TelnetServer) assert isinstance(encoding, text_type) # e.g. 'utf-8' self.conn = conn self.addr = addr self.application = application self.closed = False self.handling_command = True self.server = server self.encoding = encoding self.callback = None # Function that handles the CLI result. # Create "Output" object. self.size = Size(rows=40, columns=79) # Initialize. _initialize_telnet(conn) # Create output. def get_size(): return self.size self.stdout = _ConnectionStdout(conn, encoding=encoding) self.vt100_output = Vt100_Output(self.stdout, get_size, write_binary=False) # Create an eventloop (adaptor) for the CommandLineInterface. self.eventloop = _TelnetEventLoopInterface(server) # Set default CommandLineInterface. self.set_application(create_prompt_application()) # Call client_connected application.client_connected(self) # Draw for the first time. self.handling_command = False self.cli._redraw()
def get_size(self): from prompt_toolkit.layout.screen import Size info = self.get_win32_screen_buffer_info() # We take the width of the *visible* region as the size. Not the width # of the complete screen buffer. (Unless use_complete_width has been # set.) if self.use_complete_width: width = info.dwSize.X else: width = info.srWindow.Right - info.srWindow.Left height = info.srWindow.Bottom - info.srWindow.Top + 1 # We avoid the right margin, windows will wrap otherwise. maxwidth = info.dwSize.X - 1 width = min(maxwidth, width) # Create `Size` object. return Size(rows=height, columns=width)
def get_size(): if isatty: rows, columns = _get_size(stdout.fileno()) return Size(rows=rows, columns=columns) else: return Size(rows=24, columns=80)
def size_received(rows, columns): """ TelnetProtocolParser 'size_received' callback """ self.size = Size(rows=rows, columns=columns) cb.terminal_size_changed()
def size_received(rows, columns): """ TelnetProtocolParser 'size_received' callback """ self.size = Size(rows=rows, columns=columns) get_app()._on_resize()
def get_size(): rows, columns = _get_size(stdout.fileno()) return Size(rows=rows, columns=columns)
def window_size_changed(self, columns, rows): self._size = Size(rows=rows, columns=columns) self._cb.terminal_size_changed()
def get_size(): rows, columns = _get_size(stdout.fileno()) # If terminal (incorrectly) reports its size as 0, pick a reasonable default. # See https://github.com/ipython/ipython/issues/10071 return Size(rows=(rows or 24), columns=(columns or 80))
def setUp(self): self.screen = Screen(Size(rows=10, columns=80))
def window_size_changed(self, columns, rows): self._size = Size(rows=rows, columns=columns) self._cb.terminal_size_changed() if self._window_size_changed_callback: yield from self._window_size_changed_callback(columns, rows)
def get_size(self): return Size(rows=40, columns=80)
def get_size(): width, height, _, _ = process.get_terminal_size() return Size(rows=height, columns=width)