def _get_size(self) -> Size: """ 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 __init__( self, stdout: TextIO, default_color_depth: Optional[ColorDepth] = None ) -> None: self.win32_output = Win32Output(stdout, default_color_depth=default_color_depth) self.vt100_output = Vt100_Output( stdout, lambda: Size(0, 0), default_color_depth=default_color_depth )
def __init__( self, stdout: TextIO, default_color_depth: Optional[ColorDepth] = None ) -> None: self.win32_output = Win32Output(stdout, default_color_depth=default_color_depth) self.vt100_output = Vt100_Output( stdout, lambda: Size(0, 0), default_color_depth=default_color_depth ) self._hconsole = HANDLE(windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE))
def get_size() -> 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, conn: socket.socket, addr: Tuple[str, int], interact: Callable[["TelnetConnection"], Awaitable[None]], server: "TelnetServer", encoding: str, style: Optional[BaseStyle], ) -> None: self.conn = conn self.addr = addr self.interact = interact self.server = server self.encoding = encoding self.style = style self._closed = False self._ready = asyncio.Event() self.vt100_output = None # Create "Output" object. self.size = Size(rows=40, columns=79) # Initialize. _initialize_telnet(conn) # Create input. self.vt100_input = create_pipe_input() # Create output. def get_size() -> Size: return self.size self.stdout = cast(TextIO, _ConnectionStdout(conn, encoding=encoding)) def data_received(data: bytes) -> None: """ TelnetProtocolParser 'data_received' callback """ self.vt100_input.send_bytes(data) def size_received(rows: int, columns: int) -> None: """ TelnetProtocolParser 'size_received' callback """ self.size = Size(rows=rows, columns=columns) if self.vt100_output is not None: get_app()._on_resize() def ttype_received(ttype: str) -> None: """ TelnetProtocolParser 'ttype_received' callback """ self.vt100_output = Vt100_Output(self.stdout, get_size, term=ttype, write_binary=False) self._ready.set() self.parser = TelnetProtocolParser(data_received, size_received, ttype_received) self.context: Optional[contextvars.Context] = None
def get_size() -> 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) # It is possible that `stdout` is no longer a TTY device at this # point. In that case we get an `OSError` in the ioctl call in # `get_size`. See: # https://github.com/prompt-toolkit/python-prompt-toolkit/pull/1021 try: rows, columns = _get_size(stdout.fileno()) except OSError: pass return Size(rows=rows or 24, columns=columns or 80)
def get_size(self) -> 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 __init__(self, conn, addr: Tuple[str, int], interact: Callable, server: 'TelnetServer', encoding: str, style) -> None: self.conn = conn self.addr = addr self.interact = interact self.server = server self.encoding = encoding self.style = style self._closed = False # Create "Output" object. self.size = Size(rows=40, columns=79) # Initialize. _initialize_telnet(conn) # Create input. self.vt100_input = PosixPipeInput() # Create output. def get_size(): return self.size self.stdout = cast(TextIO, _ConnectionStdout(conn, encoding=encoding)) self.vt100_output = Vt100_Output(self.stdout, get_size, write_binary=False) def data_received(data: bytes) -> None: """ TelnetProtocolParser 'data_received' callback """ 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) self.context: Optional[contextvars.Context] = None
def size_received(rows: int, columns: int) -> None: """ TelnetProtocolParser 'size_received' callback """ self.size = Size(rows=rows, columns=columns) if self.vt100_output is not None: get_app()._on_resize()
def get_size(self) -> Size: return Size(rows=40, columns=80)
def __init__(self, stdout: TextIO) -> None: self.win32_output = Win32Output(stdout) self.vt100_output = Vt100_Output(stdout, lambda: Size(0, 0)) self._hconsole = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
def __init__(self, stdout: TextIO) -> None: self.win32_output = Win32Output(stdout) self.vt100_output = Vt100_Output(stdout, lambda: Size(0, 0))
def size_received(rows, columns): """ TelnetProtocolParser 'size_received' callback """ self.size = Size(rows=rows, columns=columns) get_app()._on_resize()
def _get_terminal_size(self) -> Size: return Size(self.terminal.rows, self.terminal.cols)