get_char(): num_chars -> num_bytes
This commit is contained in:
parent
9c1b58717c
commit
5e0a39f4bb
4 changed files with 14 additions and 14 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue