primitivus: added bracketed_paste option in sat.conf (if set, the bracketed paste mode will be activated on Primitivus start)

This commit is contained in:
Goffi 2016-04-23 01:28:35 +02:00
commit 724fa7541a
2 changed files with 17 additions and 1 deletions

View file

@ -23,6 +23,7 @@ from sat_frontends.quick_frontend import constants
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'),

View file

@ -24,6 +24,7 @@ from sat.core import log_config
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.misc import InputHistory
from sat_frontends.tools import jid
from os.path import join
import signal
import sys
class EditBar(sat_widgets.ModalEdit):
@ -301,7 +303,12 @@ class PrimitivusApp(QuickApp, InputHistory):
# 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 @@ class PrimitivusApp(QuickApp, InputHistory):
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 @@ class PrimitivusApp(QuickApp, InputHistory):
if not extra:
return
input_ = extra
## end of paste detection/handling
for i in input_:
if isinstance(i,tuple):
@ -822,6 +831,12 @@ class PrimitivusApp(QuickApp, InputHistory):
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):