Mercurial > libervia-backend
diff frontends/src/primitivus/primitivus @ 671:4e691a231763
frontend, primitivus: added input history (mode-wise)
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 07 Nov 2013 16:58:20 +0100 |
parents | d81f55a58c08 |
children | 903c4749de15 |
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus Thu Nov 07 16:14:56 2013 +0100 +++ b/frontends/src/primitivus/primitivus Thu Nov 07 16:58:20 2013 +0100 @@ -31,6 +31,7 @@ from sat_frontends.primitivus.xmlui import XMLUI from sat_frontends.primitivus.progress import Progress from sat_frontends.primitivus.notify import Notify +from sat.tools.frontend.misc import InputHistory import sat_frontends.primitivus.constants import logging from logging import debug, info, error @@ -120,15 +121,30 @@ raise urwid.ExitMainLoop() def keypress(self, size, key): - """Callback when a key is pressed. Send "composing" states.""" - if key != "enter": + """Callback when a key is pressed. Send "composing" states + and move the index of the temporary history stack.""" + def history_cb(text): + self.set_edit_text(text) + self.set_edit_pos(len(text)) + + if key == "esc": + self.app._updateInputHistory(mode='NORMAL') + if self._mode == 'NORMAL' and key in self._modes: + self.app._updateInputHistory(mode=self._modes[key][0]) + if key == "up": + self.app._updateInputHistory(self.get_edit_text(), -1, history_cb, self.mode) + elif key == "down": + self.app._updateInputHistory(self.get_edit_text(), +1, history_cb, self.mode) + elif key == "enter": + self.app._updateInputHistory(self.get_edit_text(), mode=self.mode) + else: contact = self.app.contact_list.getContact() if contact: self.app.bridge.chatStateComposing(unescapePrivate(contact), self.app.profile) - return super(EditBar, self).keypress(size, key) + return super(EditBar, self).keypress(size, key) -class PrimitivusApp(QuickApp): +class PrimitivusApp(QuickApp, InputHistory): def __init__(self): QuickApp.__init__(self)