changeset 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 227a4e617549
files frontends/src/primitivus/constants.py frontends/src/primitivus/primitivus
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/constants.py	Sat Apr 23 00:31:59 2016 +0200
+++ b/frontends/src/primitivus/constants.py	Sat Apr 23 01:28:35 2016 +0200
@@ -23,6 +23,7 @@
 class Const(constants.Const):
 
     APP_NAME = "Primitivus"
+    SECTION_NAME = APP_NAME.lower()
     PALETTE = [
                ('title', 'black', 'light gray', 'standout,underline'),
                ('title_focus', 'white,bold', 'light gray', 'standout,underline'),
--- a/frontends/src/primitivus/primitivus	Sat Apr 23 00:31:59 2016 +0200
+++ b/frontends/src/primitivus/primitivus	Sat Apr 23 01:28:35 2016 +0200
@@ -24,6 +24,7 @@
 log_config.satConfigure(C.LOG_BACKEND_STANDARD, C)
 from sat.core import log as logging
 log = logging.getLogger(__name__)
+from sat.tools import config as sat_config
 import urwid
 from urwid.util import is_wide_char
 from urwid_satext import sat_widgets
@@ -44,6 +45,7 @@
 from sat_frontends.tools import jid
 from os.path import join
 import signal
+import sys
 
 
 class EditBar(sat_widgets.ModalEdit):
@@ -301,7 +303,12 @@
 
         # we already manage exit with a_key['APP_QUIT'], so we don't want C-c
         signal.signal(signal.SIGINT, signal.SIG_IGN)
-        self._bracketed_paste = False
+        sat_conf = sat_config.parseMainConf()
+        self._bracketed_paste = C.bool(sat_config.getConfig(sat_conf, C.SECTION_NAME, 'bracketed_paste', 'false'))
+        if self._bracketed_paste:
+            log.debug("setting bracketed paste mode as requested")
+            sys.stdout.write("\033[?2004h")
+            self._bracketed_mode_set = True
 
     @property
     def visible_widgets(self):
@@ -374,6 +381,7 @@
         if self.__saved_overlay and input_ != a_key['OVERLAY_HIDE']:
             return
 
+        ## paste detection/handling
         if (len(input_) > 1 and                  # XXX: it may be needed to increase this value if buffer
             not isinstance(input_[0], tuple) and #      or other things result in several chars at once
             not 'window' in input_[0]):          #      (e.g. using Primitivus through ssh). Need some testing
@@ -420,6 +428,7 @@
             if not extra:
                 return
             input_ = extra
+        ## end of paste detection/handling
 
         for i in input_:
             if isinstance(i,tuple):
@@ -822,6 +831,12 @@
 
     def onExitRequest(self, menu):
         QuickApp.onExit(self)
+        try:
+            if self._bracketed_mode_set: # we don't unset if bracketed paste mode was detected automatically (i.e. not in conf)
+                log.debug("unsetting bracketed paste mode")
+                sys.stdout.write("\033[?2004l")
+        except AttributeError:
+            pass
         raise urwid.ExitMainLoop()
 
     def onJoinRoomRequest(self, menu):