Force local terminal ``stream`` be character, not line, buffered. Only applies to Unix-based systems; on Windows this is a no-op. .. versionadded:: 1.0
(
stream: IO,
)
| 176 | |
| 177 | @contextmanager |
| 178 | def character_buffered( |
| 179 | stream: IO, |
| 180 | ) -> Generator[None, None, None]: |
| 181 | """ |
| 182 | Force local terminal ``stream`` be character, not line, buffered. |
| 183 | |
| 184 | Only applies to Unix-based systems; on Windows this is a no-op. |
| 185 | |
| 186 | .. versionadded:: 1.0 |
| 187 | """ |
| 188 | if ( |
| 189 | WINDOWS |
| 190 | or not isatty(stream) |
| 191 | or not stdin_is_foregrounded_tty(stream) |
| 192 | or cbreak_already_set(stream) |
| 193 | ): |
| 194 | yield |
| 195 | else: |
| 196 | old_settings = termios.tcgetattr(stream) |
| 197 | tty.setcbreak(stream) |
| 198 | try: |
| 199 | yield |
| 200 | finally: |
| 201 | termios.tcsetattr(stream, termios.TCSADRAIN, old_settings) |
| 202 | |
| 203 | |
| 204 | def ready_for_reading(input_: IO) -> bool: |
no test coverage detected
searching dependent graphs…