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

Function character_buffered

invoke/terminals.py:178–201  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

176
177@contextmanager
178def 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
204def ready_for_reading(input_: IO) -> bool:

Callers 1

handle_stdinMethod · 0.85

Calls 3

isattyFunction · 0.85
cbreak_already_setFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…