Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
670:0fd123340fb9 | 671:4e691a231763 |
---|---|
29 from sat_frontends.primitivus.chat import Chat | 29 from sat_frontends.primitivus.chat import Chat |
30 from sat_frontends.primitivus.gateways import GatewaysManager | 30 from sat_frontends.primitivus.gateways import GatewaysManager |
31 from sat_frontends.primitivus.xmlui import XMLUI | 31 from sat_frontends.primitivus.xmlui import XMLUI |
32 from sat_frontends.primitivus.progress import Progress | 32 from sat_frontends.primitivus.progress import Progress |
33 from sat_frontends.primitivus.notify import Notify | 33 from sat_frontends.primitivus.notify import Notify |
34 from sat.tools.frontend.misc import InputHistory | |
34 import sat_frontends.primitivus.constants | 35 import sat_frontends.primitivus.constants |
35 import logging | 36 import logging |
36 from logging import debug, info, error | 37 from logging import debug, info, error |
37 from sat.tools.jid import JID | 38 from sat.tools.jid import JID |
38 from os.path import join | 39 from os.path import join |
118 if command == 'quit': | 119 if command == 'quit': |
119 self.app.onExit() | 120 self.app.onExit() |
120 raise urwid.ExitMainLoop() | 121 raise urwid.ExitMainLoop() |
121 | 122 |
122 def keypress(self, size, key): | 123 def keypress(self, size, key): |
123 """Callback when a key is pressed. Send "composing" states.""" | 124 """Callback when a key is pressed. Send "composing" states |
124 if key != "enter": | 125 and move the index of the temporary history stack.""" |
126 def history_cb(text): | |
127 self.set_edit_text(text) | |
128 self.set_edit_pos(len(text)) | |
129 | |
130 if key == "esc": | |
131 self.app._updateInputHistory(mode='NORMAL') | |
132 if self._mode == 'NORMAL' and key in self._modes: | |
133 self.app._updateInputHistory(mode=self._modes[key][0]) | |
134 if key == "up": | |
135 self.app._updateInputHistory(self.get_edit_text(), -1, history_cb, self.mode) | |
136 elif key == "down": | |
137 self.app._updateInputHistory(self.get_edit_text(), +1, history_cb, self.mode) | |
138 elif key == "enter": | |
139 self.app._updateInputHistory(self.get_edit_text(), mode=self.mode) | |
140 else: | |
125 contact = self.app.contact_list.getContact() | 141 contact = self.app.contact_list.getContact() |
126 if contact: | 142 if contact: |
127 self.app.bridge.chatStateComposing(unescapePrivate(contact), self.app.profile) | 143 self.app.bridge.chatStateComposing(unescapePrivate(contact), self.app.profile) |
128 return super(EditBar, self).keypress(size, key) | 144 return super(EditBar, self).keypress(size, key) |
129 | 145 |
130 | 146 |
131 class PrimitivusApp(QuickApp): | 147 class PrimitivusApp(QuickApp, InputHistory): |
132 | 148 |
133 def __init__(self): | 149 def __init__(self): |
134 QuickApp.__init__(self) | 150 QuickApp.__init__(self) |
135 | 151 |
136 ## main loop setup ## | 152 ## main loop setup ## |