aboutsummaryrefslogtreecommitdiffstats
path: root/clients/urwid/main.py
diff options
context:
space:
mode:
authorBlake DeMarcy <ofunknowndescent@gmail.com>2017-04-20 19:00:28 -0500
committerBlake DeMarcy <ofunknowndescent@gmail.com>2017-04-20 19:00:28 -0500
commita2fae6ba8bffdd24134b1234c7e8bf4c81194c3d (patch)
treeef138c8b275c9cd7082862248d1a9b98d2ba0054 /clients/urwid/main.py
parent6e959a510eeb3959dabfa49dd08e2d6765fe6186 (diff)
downloadbbj-a2fae6ba8bffdd24134b1234c7e8bf4c81194c3d.tar.gz
add input unicode support: urwid py3 still crashes on output...
Diffstat (limited to 'clients/urwid/main.py')
-rw-r--r--clients/urwid/main.py56
1 files changed, 34 insertions, 22 deletions
diff --git a/clients/urwid/main.py b/clients/urwid/main.py
index 1e9bdbd..f1c83ef 100644
--- a/clients/urwid/main.py
+++ b/clients/urwid/main.py
@@ -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):
Un proyecto texto-plano.xyz