MCPcopy Create free account
hub / github.com/pyinvoke/invoke / cbreak_already_set

Function cbreak_already_set

invoke/terminals.py:155–174  ·  view source on GitHub ↗
(stream: IO)

Source from the content-addressed store, hash-verified

153
154
155def 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

Callers 1

character_bufferedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…