Initialize the UnixConsole. Parameters: - f_in (int or file-like object): Input file descriptor or object. - f_out (int or file-like object): Output file descriptor or object. - term (str): Terminal name. - encoding (str): Encoding to use for I/O ope
(
self,
f_in: IO[bytes] | int = 0,
f_out: IO[bytes] | int = 1,
term: str = "",
encoding: str = "",
)
| 142 | |
| 143 | class UnixConsole(Console): |
| 144 | def __init__( |
| 145 | self, |
| 146 | f_in: IO[bytes] | int = 0, |
| 147 | f_out: IO[bytes] | int = 1, |
| 148 | term: str = "", |
| 149 | encoding: str = "", |
| 150 | ): |
| 151 | """ |
| 152 | Initialize the UnixConsole. |
| 153 | |
| 154 | Parameters: |
| 155 | - f_in (int or file-like object): Input file descriptor or object. |
| 156 | - f_out (int or file-like object): Output file descriptor or object. |
| 157 | - term (str): Terminal name. |
| 158 | - encoding (str): Encoding to use for I/O operations. |
| 159 | """ |
| 160 | super().__init__(f_in, f_out, term, encoding) |
| 161 | |
| 162 | self.pollob = poll() |
| 163 | self.pollob.register(self.input_fd, select.POLLIN) |
| 164 | self.terminfo = terminfo.TermInfo(term or None) |
| 165 | self.term = term |
| 166 | self.is_apple_terminal = ( |
| 167 | platform.system() == "Darwin" |
| 168 | and os.getenv("TERM_PROGRAM") == "Apple_Terminal" |
| 169 | ) |
| 170 | |
| 171 | try: |
| 172 | self.__input_fd_set(tcgetattr(self.input_fd), ignore=frozenset()) |
| 173 | except _error as e: |
| 174 | raise RuntimeError(f"termios failure ({e.args[1]})") |
| 175 | |
| 176 | @overload |
| 177 | def _my_getstr( |
| 178 | cap: str, optional: Literal[False] = False |
| 179 | ) -> bytes: ... |
| 180 | |
| 181 | @overload |
| 182 | def _my_getstr(cap: str, optional: bool) -> bytes | None: ... |
| 183 | |
| 184 | def _my_getstr(cap: str, optional: bool = False) -> bytes | None: |
| 185 | r = self.terminfo.get(cap) |
| 186 | if not optional and r is None: |
| 187 | raise InvalidTerminal( |
| 188 | f"terminal doesn't have the required {cap} capability" |
| 189 | ) |
| 190 | return r |
| 191 | |
| 192 | self._bel = _my_getstr("bel") |
| 193 | self._civis = _my_getstr("civis", optional=True) |
| 194 | self._clear = _my_getstr("clear") |
| 195 | self._cnorm = _my_getstr("cnorm", optional=True) |
| 196 | self._cub = _my_getstr("cub", optional=True) |
| 197 | self._cub1 = _my_getstr("cub1", optional=True) |
| 198 | self._cud = _my_getstr("cud", optional=True) |
| 199 | self._cud1 = _my_getstr("cud1", optional=True) |
| 200 | self._cuf = _my_getstr("cuf", optional=True) |
| 201 | self._cuf1 = _my_getstr("cuf1", optional=True) |
nothing calls this directly
no test coverage detected