diff options
author | Blake DeMarcy <ofunknowndescent@gmail.com> | 2017-04-15 06:39:46 -0500 |
---|---|---|
committer | Blake DeMarcy <ofunknowndescent@gmail.com> | 2017-04-15 06:39:46 -0500 |
commit | b0f51bd1170e67295dd0deada587e13262d8d4fd (patch) | |
tree | f92ac0f5f4becda816e476158138347d324c4179 /clients/urwid/main.py | |
parent | 7e0943345705f82cf66ceced291f88ed06447380 (diff) | |
download | bbj-b0f51bd1170e67295dd0deada587e13262d8d4fd.tar.gz |
""""polish"""" the external editor
Diffstat (limited to 'clients/urwid/main.py')
-rw-r--r-- | clients/urwid/main.py | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/clients/urwid/main.py b/clients/urwid/main.py index 204f165..61691e7 100644 --- a/clients/urwid/main.py +++ b/clients/urwid/main.py @@ -1262,25 +1262,40 @@ class ExternalEditor(urwid.Terminal): command = ["bash", "-c", "{} {}; echo Press any key to kill this window...".format( app.prefs["editor"], self.path)] super(ExternalEditor, self).__init__(command, env, app.loop, "f1") + urwid.connect_signal(self, "closed", self.exterminate) - def keypress(self, size, key): - if key.lower() == "ctrl l": - # always do this, and also pass it to the terminal - wipe_screen() + def exterminate(self, *_): + app.close_editor() + with open(self.path) as _: + body = _.read().strip() + os.remove(self.path) - if self.terminated: - app.close_editor() - with open(self.path) as _: - body = _.read().strip() - os.remove(self.path) + if body and not re.search("^>>[0-9]+$", body): + self.params.update({"body": body}) + network.request(self.endpoint, **self.params) + return app.refresh(True) + else: + return app.temp_footer_message("EMPTY POST DISCARDED") - if body and not re.search("^>>[0-9]+$", body): - self.params.update({"body": body}) - network.request(self.endpoint, **self.params) - return app.refresh(True) + + def keypress(self, size, key): + if key in ["down", "up", "left", "right"]: + # HACK HACK HACK 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: - return app.temp_footer_message("EMPTY POST DISCARDED") + key = urwid.vterm.KEY_TRANSLATIONS.get(key, key) + key = key.encode('ascii') + return os.write(self.master, key) + + elif key.lower() == "ctrl l": + # always do this, and also pass it to the terminal + wipe_screen() elif key not in ["f1", "f2", "f3"]: return super(ExternalEditor, self).keypress(size, key) |