Skip to content

Commit 03520b1

Browse files
committed
Add code to cache initial termios settings in cmd2.Cmd.__init__
1 parent f7f8a8d commit 03520b1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cmd2/cmd2.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,18 @@ def __init__(
508508
# Commands that will run at the beginning of the command loop
509509
self._startup_commands: list[str] = []
510510

511+
# Store initial termios settings to restore after each command.
512+
# This is a faster way of accomplishing what "stty sane" does.
513+
self._initial_termios_settings = None
514+
if not sys.platform.startswith('win') and self.stdin.isatty():
515+
try:
516+
import termios
517+
518+
self._initial_termios_settings = termios.tcgetattr(self.stdin.fileno())
519+
except (ImportError, termios.error):
520+
# This can happen if termios isn't available or stdin is a pseudo-TTY
521+
pass
522+
511523
# If a startup script is provided and exists, then execute it in the startup commands
512524
if startup_script:
513525
startup_script = os.path.abspath(os.path.expanduser(startup_script))

0 commit comments

Comments
 (0)