def get_size(self): from prompt_toolkit.layout.screen import Size info = self._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 # 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 __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) # 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 _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']) 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 get_size(self): return Size(rows=40, 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 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(): if isatty: rows, columns = _get_size(stdout.fileno()) return Size(rows=rows, columns=columns) else: return Size(rows=24, columns=80)
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 get_size(): width, height, _, _ = process.get_terminal_size() return Size(rows=height, columns=width)