add input unicode support: urwid py3 still crashes on output...

pull/4/head
Blake DeMarcy 2017-04-20 19:00:28 -05:00
parent 6e959a510e
commit a2fae6ba8b
1 changed files with 34 additions and 22 deletions

View File

@ -1524,40 +1524,52 @@ class ExternalEditor(urwid.Terminal):
def keypress(self, size, key):
if key in ["down", "up", "left", "right"]:
# HACK: something somewhere is capturing some keys within
# the parent keypress method until some other keys are pressed. So when
# this widget was spawned, it would ignore arrow keys, C-n/C-p, pager keys,
# but when some _OTHER_ keys were pressed, this lock was released. Weird shit.
# instead of figuring out why lets just //TAKE_THE_REIGNS// #YOLO
if self.term_modes.keys_decckm and key in urwid.vterm.KEY_TRANSLATIONS_DECCKM:
key = urwid.vterm.KEY_TRANSLATIONS_DECCKM.get(key)
else:
key = urwid.vterm.KEY_TRANSLATIONS.get(key, key)
key = key.encode('ascii')
return os.write(self.master, key)
elif key.lower() == "ctrl l":
wipe_screen()
# always do this, and also pass it to the terminal
"""
The majority of the things the parent keypress method will do is
either erroneous or disruptive to my own usage. I've plucked out
the necessary bits and, most importantly, have changed from
ASCII encoding to utf8 when writing to the child process.
"""
if self.terminated:
return
self.term.scroll_buffer(reset=True)
keyl = key.lower()
if keyl not in ["f1", "f2", "f3", "ctrl z"]:
return super(ExternalEditor, self).keypress(size, key)
if keyl == "ctrl l":
# always do this, and also pass it to the terminal
wipe_screen()
elif key == "f1":
self.terminate()
app.close_editor()
app.refresh()
return app.refresh()
elif key == "f2":
app.switch_editor()
return app.switch_editor()
elif key == "f3":
app.formatting_help()
return app.formatting_help()
elif keyl == "ctrl z":
os.killpg(os.getpgid(os.getpid()), 19)
return os.killpg(os.getpgid(os.getpid()), 19)
if key.startswith("ctrl "):
if key[-1].islower():
key = chr(ord(key[-1]) - ord('a') + 1)
else:
key = chr(ord(key[-1]) - ord('A') + 1)
else:
if self.term_modes.keys_decckm and key in urwid.vterm.KEY_TRANSLATIONS_DECCKM:
key = urwid.vterm.KEY_TRANSLATIONS_DECCKM.get(key)
else:
key = urwid.vterm.KEY_TRANSLATIONS.get(key, key)
# ENTER transmits both a carriage return and linefeed in LF/NL mode.
if self.term_modes.lfnl and key == "\x0d":
key += "\x0a"
os.write(self.master, key.encode('utf8'))
def __del__(self):