From 5e0a39f4bba6530e1ffd0f384e1056119a088367 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 29 Oct 2022 20:10:23 +0000 Subject: [PATCH] get_char(): `num_chars` -> `num_bytes` --- mmgen/mn_entry.py | 2 +- mmgen/term.py | 20 ++++++++++---------- mmgen/wallet/dieroll.py | 2 +- test/misc/term.py | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mmgen/mn_entry.py b/mmgen/mn_entry.py index 2b14c01b..acef6e7f 100755 --- a/mmgen/mn_entry.py +++ b/mmgen/mn_entry.py @@ -51,7 +51,7 @@ class MnEntryMode(object): def get_char(self,s): did_erase = False while True: - ch = get_char_raw('',num_chars=1) + ch = get_char_raw('',num_bytes=1) if s and ch in _erase_chars: s = s[:-1] did_erase = True diff --git a/mmgen/term.py b/mmgen/term.py index 050aeda3..507f887f 100755 --- a/mmgen/term.py +++ b/mmgen/term.py @@ -97,7 +97,7 @@ class MMGenTermLinux(MMGenTerm): break @classmethod - def get_char(cls,prompt='',immed_chars='',prehold_protect=True,num_chars=5): + def get_char(cls,prompt='',immed_chars='',prehold_protect=True,num_bytes=5): """ Use os.read(), not file.read(), to get a variable number of bytes without blocking. Request 5 bytes to cover escape sequences generated by F1, F2, .. Fn keys (5 bytes) @@ -111,7 +111,7 @@ class MMGenTermLinux(MMGenTerm): while True: # Protect against held-down key before read() key = select([sys.stdin], [], [], timeout)[0] - s = os.read(cls.stdin_fd,num_chars).decode() + s = os.read(cls.stdin_fd,num_bytes).decode() if prehold_protect and key: continue if s in immed_chars: @@ -124,10 +124,10 @@ class MMGenTermLinux(MMGenTerm): return s @classmethod - def get_char_raw(cls,prompt='',num_chars=5): + def get_char_raw(cls,prompt='',num_bytes=5): tty.setcbreak(cls.stdin_fd) msg_r(prompt) - s = os.read(cls.stdin_fd,num_chars).decode() + s = os.read(cls.stdin_fd,num_bytes).decode() termios.tcsetattr(cls.stdin_fd, termios.TCSADRAIN, cls.old_term) return s @@ -142,7 +142,7 @@ class MMGenTermLinuxStub(MMGenTermLinux): pass @classmethod - def get_char(cls,prompt='',immed_chars='',prehold_protect=None,num_chars=None): + def get_char(cls,prompt='',immed_chars='',prehold_protect=None,num_bytes=None): msg_r(prompt) return sys.stdin.read(1) @@ -190,9 +190,9 @@ class MMGenTermMSWin(MMGenTerm): return @classmethod - def get_char(cls,prompt='',immed_chars='',prehold_protect=True,num_chars=None): + def get_char(cls,prompt='',immed_chars='',prehold_protect=True,num_bytes=None): """ - always return a single character, ignore num_chars + always return a single character, ignore num_bytes first character of 2-character sequence returned by F1-F12 keys is discarded prehold_protect is ignored """ @@ -213,9 +213,9 @@ class MMGenTermMSWin(MMGenTerm): return ch @classmethod - def get_char_raw(cls,prompt='',num_chars=None): + def get_char_raw(cls,prompt='',num_bytes=None): """ - always return a single character, ignore num_chars + always return a single character, ignore num_bytes first character of 2-character sequence returned by F1-F12 keys is discarded """ while True: @@ -230,7 +230,7 @@ class MMGenTermMSWin(MMGenTerm): class MMGenTermMSWinStub(MMGenTermMSWin): @classmethod - def get_char(cls,prompt='',immed_chars='',prehold_protect=None,num_chars=None): + def get_char(cls,prompt='',immed_chars='',prehold_protect=None,num_bytes=None): msg_r(prompt) return os.read(0,1).decode() diff --git a/mmgen/wallet/dieroll.py b/mmgen/wallet/dieroll.py index d1d145b0..96f238b5 100755 --- a/mmgen/wallet/dieroll.py +++ b/mmgen/wallet/dieroll.py @@ -98,7 +98,7 @@ class wallet(wallet): p = prompt_fs while True: time.sleep(g.short_disp_timeout) - ch = get_char(p.format(n),num_chars=1) + ch = get_char(p.format(n),num_bytes=1) if ch in bc.digits: msg_r(CUR_HIDE + ' OK') return ch diff --git a/test/misc/term.py b/test/misc/term.py index 3bcf25a2..5c3b592a 100755 --- a/test/misc/term.py +++ b/test/misc/term.py @@ -65,7 +65,7 @@ def tt_line_input(): The held-down "y" and ENTER keys should be blocked, not affecting the output on screen or entered text. """)) - get_char_raw('Ready? ',num_chars=1) + get_char_raw('Ready? ',num_bytes=1) reply = line_input('\nEnter text: ') confirm(f'Did you enter the text {reply!r}?') @@ -96,7 +96,7 @@ def tt_get_char(raw=False,one_char=False,immed_chars=''): m3 = 'The Escape and F1-F12 keys will be returned as single characters.' kwargs = {} if one_char: - kwargs.update({'num_chars':1}) + kwargs.update({'num_bytes':1}) if immed_chars: kwargs.update({'immed_chars':immed_chars})