term.py: register_cleanup() fix

This commit is contained in:
The MMGen Project 2023-04-04 16:04:09 +00:00
commit e52588b5af
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2

View file

@ -47,14 +47,7 @@ class MMGenTerm(object):
@classmethod
def register_cleanup(cls):
if gc.platform == 'linux' and not hasattr(cls,'cleanup_registered'):
import atexit
atexit.register(
lambda: termios.tcsetattr(
cls.stdin_fd,
termios.TCSADRAIN,
cls.orig_term) )
cls.cleanup_registered = True
pass
@classmethod
def init(cls,noecho=False):
@ -74,6 +67,17 @@ class MMGenTerm(object):
class MMGenTermLinux(MMGenTerm):
@classmethod
def register_cleanup(cls):
if not hasattr(cls,'cleanup_registered'):
import atexit
atexit.register(
lambda: termios.tcsetattr(
cls.stdin_fd,
termios.TCSADRAIN,
cls.orig_term) )
cls.cleanup_registered = True
@classmethod
def reset(cls):
termios.tcsetattr( cls.stdin_fd, termios.TCSANOW, cls.orig_term )
@ -159,6 +163,10 @@ class MMGenTermLinux(MMGenTerm):
class MMGenTermLinuxStub(MMGenTermLinux):
@classmethod
def register_cleanup(cls):
pass
@classmethod
def init(cls,noecho=False):
cls.stdin_fd = sys.stdin.fileno()