Skip to content
Snippets Groups Projects
Commit eb7de3e6 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(COOKED): Removed.

(_saved_mode): New variable.
(_save): New function.  Arrange to call _restore via the atexit module.
(_restore): New function.
(user.__init__): Default to not modifying the termios setting.
	Call _save before changing them.
(user.close): Use _restore to restore the settings.
parent 51dbc0ea
No related branches found
No related tags found
No related merge requests found
import atexit
import sys
import tty
import termios
......@@ -8,25 +9,42 @@ __all__ = [
"user",
"RAW",
"CBREAK",
"COOKED",
]
RAW = 0
CBREAK = 1
COOKED = 2
_saved_mode = None
def _save():
global _saved_mode
if _saved_mode is None:
_saved_mode = termios.tcgetattr(sys.stdin.fileno())
atexit.register(_restore)
def _restore():
global _saved_mode
if _saved_mode is not None:
termios.tcsetattr(sys.stdin.fileno(), termios.TCSAFLUSH, _saved_mode)
_saved_mode = None
class user(pcl_expect.expectable):
def __init__(self, mode = CBREAK):
def __init__(self, mode = None):
fd = sys.stdin.fileno()
self.__mode = termios.tcgetattr(fd)
if mode == COOKED:
# Let's hope the fd already is in cooked mode...
pass
elif mode == CBREAK:
if mode == CBREAK:
_save()
tty.setcbreak(fd)
elif mode == RAW:
_save()
tty.setraw(fd)
else:
elif mode != None:
raise pcl_expect.BadArgs()
pcl_expect.expectable.__init__(self, fd)
......@@ -36,4 +54,5 @@ class user(pcl_expect.expectable):
sys.stdout.flush()
def close(self):
termios.tcsetattr(self.fileno(), termios.TCSAFLUSH, self.__mode)
pcl_expect.expectable.close(self)
_restore()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment