MSWin: get_char_raw(): support function keys; minor fixes
This commit is contained in:
parent
0097e99850
commit
5b08b3d5e5
3 changed files with 14 additions and 19 deletions
|
|
@ -241,17 +241,15 @@ class MMGenTermMSWin(MMGenTerm):
|
|||
@classmethod
|
||||
def get_char_raw(cls,prompt='',num_bytes=None,**kwargs):
|
||||
"""
|
||||
always return a single character, ignore num_bytes
|
||||
first character of 2-character sequence returned by F1-F12 keys is discarded
|
||||
return single ASCII char or 2-char escape sequence, ignoring num_bytes
|
||||
"""
|
||||
while True:
|
||||
msg_r(prompt)
|
||||
ch = chr(msvcrt.getch()[0])
|
||||
if ch in '\x00\xe0': # first char of 2-char sequence for F1-F12 keys
|
||||
continue
|
||||
if ch == '\x03':
|
||||
raise KeyboardInterrupt
|
||||
return ch
|
||||
msg_r(prompt)
|
||||
ret = msvcrt.getch()
|
||||
if ret in (b'\x00',b'\xe0'): # first byte of 2-byte escape sequence
|
||||
return chr(ret[0]) + chr(msvcrt.getch()[0])
|
||||
if ret == b'\x03':
|
||||
raise KeyboardInterrupt
|
||||
return chr(ret[0])
|
||||
|
||||
class MMGenTermMSWinStub(MMGenTermMSWin):
|
||||
|
||||
|
|
|
|||
10
mmgen/ui.py
10
mmgen/ui.py
|
|
@ -73,13 +73,7 @@ def line_input(prompt,echo=True,insert_txt='',hold_protect=True):
|
|||
readline.set_startup_hook(lambda: readline.insert_text(''))
|
||||
else:
|
||||
from getpass import getpass
|
||||
if g.platform == 'win':
|
||||
# MSYS2/MSWin hack - getpass('foo') doesn't flush stderr - TODO: has this been fixed?
|
||||
msg_r(prompt.strip()) # getpass('') adds a space
|
||||
sys.stderr.flush()
|
||||
reply = getpass('')
|
||||
else:
|
||||
reply = getpass(prompt)
|
||||
reply = getpass(prompt)
|
||||
|
||||
if hold_protect:
|
||||
kb_hold_protect()
|
||||
|
|
@ -115,7 +109,7 @@ def do_pager(text):
|
|||
end_msg = '\n(end of text)\n\n'
|
||||
# --- Non-MSYS Windows code deleted ---
|
||||
# raw, chop, horiz scroll 8 chars, disable buggy line chopping in MSYS
|
||||
os.environ['LESS'] = (('--shift 8 -RS'),('-cR -#1'))[g.platform=='win']
|
||||
os.environ['LESS'] = (('--shift 8 -RS'),('--shift 16 -RS'))[g.platform=='win']
|
||||
|
||||
if 'PAGER' in os.environ and os.environ['PAGER'] != pagers[0]:
|
||||
pagers = [os.environ['PAGER']] + pagers
|
||||
|
|
|
|||
|
|
@ -119,7 +119,10 @@ def _tt_get_char(raw=False,one_char=False,immed_chars=''):
|
|||
'echoed as a FULL CONTROL SEQUENCE.'
|
||||
)
|
||||
if g.platform == 'win':
|
||||
m3 = 'The Escape and F1-F12 keys will be returned as single characters.'
|
||||
if raw:
|
||||
m3 = 'The Escape and F1-F12 keys will be returned as two-character strings.'
|
||||
else:
|
||||
m3 = 'The Escape and F1-F12 keys will be returned as single characters.'
|
||||
kwargs = {}
|
||||
if one_char:
|
||||
kwargs.update({'num_bytes':1})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue