(stream: IO)
| 153 | |
| 154 | |
| 155 | def cbreak_already_set(stream: IO) -> bool: |
| 156 | # Explicitly not docstringed to remain private, for now. Eh. |
| 157 | # Checks whether tty.setcbreak appears to have already been run against |
| 158 | # ``stream`` (or if it would otherwise just not do anything). |
| 159 | # Used to effect idempotency for character-buffering a stream, which also |
| 160 | # lets us avoid multiple capture-then-restore cycles. |
| 161 | attrs = termios.tcgetattr(stream) |
| 162 | lflags, cc = attrs[3], attrs[6] |
| 163 | echo = bool(lflags & termios.ECHO) |
| 164 | icanon = bool(lflags & termios.ICANON) |
| 165 | # setcbreak sets ECHO and ICANON to 0/off, CC[VMIN] to 1-ish, and CC[VTIME] |
| 166 | # to 0-ish. If any of that is not true we can reasonably assume it has not |
| 167 | # yet been executed against this stream. |
| 168 | sentinels = ( |
| 169 | not echo, |
| 170 | not icanon, |
| 171 | cc[termios.VMIN] in [1, b"\x01"], |
| 172 | cc[termios.VTIME] in [0, b"\x00"], |
| 173 | ) |
| 174 | return all(sentinels) |
| 175 | |
| 176 | |
| 177 | @contextmanager |
no outgoing calls
no test coverage detected
searching dependent graphs…