comparison frontends/src/primitivus/primitivus @ 1949:c5fd304d0976

primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)
author Goffi <goffi@goffi.org>
date Sat, 23 Apr 2016 01:28:35 +0200
parents 373550000092
children 2c1a1b56dd22
comparison
equal deleted inserted replaced
1948:373550000092 1949:c5fd304d0976
22 from sat_frontends.primitivus.constants import Const as C 22 from sat_frontends.primitivus.constants import Const as C
23 from sat.core import log_config 23 from sat.core import log_config
24 log_config.satConfigure(C.LOG_BACKEND_STANDARD, C) 24 log_config.satConfigure(C.LOG_BACKEND_STANDARD, C)
25 from sat.core import log as logging 25 from sat.core import log as logging
26 log = logging.getLogger(__name__) 26 log = logging.getLogger(__name__)
27 from sat.tools import config as sat_config
27 import urwid 28 import urwid
28 from urwid.util import is_wide_char 29 from urwid.util import is_wide_char
29 from urwid_satext import sat_widgets 30 from urwid_satext import sat_widgets
30 from urwid_satext.files_management import FileDialog 31 from urwid_satext.files_management import FileDialog
31 from sat_frontends.bridge.DBus import DBusBridgeFrontend 32 from sat_frontends.bridge.DBus import DBusBridgeFrontend
42 from sat_frontends.primitivus import config 43 from sat_frontends.primitivus import config
43 from sat_frontends.tools.misc import InputHistory 44 from sat_frontends.tools.misc import InputHistory
44 from sat_frontends.tools import jid 45 from sat_frontends.tools import jid
45 from os.path import join 46 from os.path import join
46 import signal 47 import signal
48 import sys
47 49
48 50
49 class EditBar(sat_widgets.ModalEdit): 51 class EditBar(sat_widgets.ModalEdit):
50 """ 52 """
51 The modal edit bar where you would enter messages and commands. 53 The modal edit bar where you would enter messages and commands.
299 301
300 self.x_notify = Notify() 302 self.x_notify = Notify()
301 303
302 # we already manage exit with a_key['APP_QUIT'], so we don't want C-c 304 # we already manage exit with a_key['APP_QUIT'], so we don't want C-c
303 signal.signal(signal.SIGINT, signal.SIG_IGN) 305 signal.signal(signal.SIGINT, signal.SIG_IGN)
304 self._bracketed_paste = False 306 sat_conf = sat_config.parseMainConf()
307 self._bracketed_paste = C.bool(sat_config.getConfig(sat_conf, C.SECTION_NAME, 'bracketed_paste', 'false'))
308 if self._bracketed_paste:
309 log.debug("setting bracketed paste mode as requested")
310 sys.stdout.write("\033[?2004h")
311 self._bracketed_mode_set = True
305 312
306 @property 313 @property
307 def visible_widgets(self): 314 def visible_widgets(self):
308 return self._visible_widgets 315 return self._visible_widgets
309 316
372 379
373 def inputFilter(self, input_, raw): 380 def inputFilter(self, input_, raw):
374 if self.__saved_overlay and input_ != a_key['OVERLAY_HIDE']: 381 if self.__saved_overlay and input_ != a_key['OVERLAY_HIDE']:
375 return 382 return
376 383
384 ## paste detection/handling
377 if (len(input_) > 1 and # XXX: it may be needed to increase this value if buffer 385 if (len(input_) > 1 and # XXX: it may be needed to increase this value if buffer
378 not isinstance(input_[0], tuple) and # or other things result in several chars at once 386 not isinstance(input_[0], tuple) and # or other things result in several chars at once
379 not 'window' in input_[0]): # (e.g. using Primitivus through ssh). Need some testing 387 not 'window' in input_[0]): # (e.g. using Primitivus through ssh). Need some testing
380 # and experience to adjust value. 388 # and experience to adjust value.
381 if input_[0] == 'begin paste' and not self._bracketed_paste: 389 if input_[0] == 'begin paste' and not self._bracketed_paste:
418 edit_bar.set_edit_text(u'{}{}{}'.format(edit_bar.edit_text[:pos], buf_paste, edit_bar.edit_text[pos:])) 426 edit_bar.set_edit_text(u'{}{}{}'.format(edit_bar.edit_text[:pos], buf_paste, edit_bar.edit_text[pos:]))
419 edit_bar.edit_pos+=len(buf_paste) 427 edit_bar.edit_pos+=len(buf_paste)
420 if not extra: 428 if not extra:
421 return 429 return
422 input_ = extra 430 input_ = extra
431 ## end of paste detection/handling
423 432
424 for i in input_: 433 for i in input_:
425 if isinstance(i,tuple): 434 if isinstance(i,tuple):
426 if i[0] == 'mouse press': 435 if i[0] == 'mouse press':
427 if i[1] == 4: #Mouse wheel up 436 if i[1] == 4: #Mouse wheel up
820 self.alert(_("Error"), _("Can't get parameters (%s)") % error) 829 self.alert(_("Error"), _("Can't get parameters (%s)") % error)
821 self.bridge.getParamsUI(app=C.APP_NAME, profile_key=self.current_profile, callback=success, errback=failure) 830 self.bridge.getParamsUI(app=C.APP_NAME, profile_key=self.current_profile, callback=success, errback=failure)
822 831
823 def onExitRequest(self, menu): 832 def onExitRequest(self, menu):
824 QuickApp.onExit(self) 833 QuickApp.onExit(self)
834 try:
835 if self._bracketed_mode_set: # we don't unset if bracketed paste mode was detected automatically (i.e. not in conf)
836 log.debug("unsetting bracketed paste mode")
837 sys.stdout.write("\033[?2004l")
838 except AttributeError:
839 pass
825 raise urwid.ExitMainLoop() 840 raise urwid.ExitMainLoop()
826 841
827 def onJoinRoomRequest(self, menu): 842 def onJoinRoomRequest(self, menu):
828 """User wants to join a MUC room""" 843 """User wants to join a MUC room"""
829 pop_up_widget = sat_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt=self.bridge.getDefaultMUC(), ok_cb=self.onJoinRoom) 844 pop_up_widget = sat_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt=self.bridge.getDefaultMUC(), ok_cb=self.onJoinRoom)