Skip to content

Commit db34ca9

Browse files
committed
Moved call to patch_stdout() right before creating the prompt.
1 parent 73a6d9c commit db34ca9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

cmd2/cmd2.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,7 +3200,8 @@ def _read_raw_input(
32003200
"""Read input from either an interactive terminal session or a redirected stream."""
32013201
# _build_session() sets session.input to a DummyInput when not in a TTY.
32023202
if not isinstance(session.input, DummyInput):
3203-
return session.prompt(prompt, completer=completer, **prompt_kwargs) # type: ignore[arg-type]
3203+
with patch_stdout():
3204+
return session.prompt(prompt, completer=completer, **prompt_kwargs) # type: ignore[arg-type]
32043205

32053206
# We're not at a terminal, so we're likely reading from a file or a pipe.
32063207
# We wait for a line of data before we print anything.
@@ -3311,13 +3312,12 @@ def get_prompt() -> ANSI | str:
33113312
if prompt == self.prompt:
33123313
prompt_to_use = get_prompt
33133314

3314-
with patch_stdout():
3315-
return self._read_raw_input(
3316-
prompt=prompt_to_use,
3317-
session=self.session,
3318-
completer=self.completer,
3319-
pre_run=self.pre_prompt,
3320-
)
3315+
return self._read_raw_input(
3316+
prompt=prompt_to_use,
3317+
session=self.session,
3318+
completer=self.completer,
3319+
pre_run=self.pre_prompt,
3320+
)
33213321
except EOFError:
33223322
return constants.EOF
33233323

0 commit comments

Comments
 (0)