merged main branch

This commit is contained in:
Goffi 2016-06-24 22:41:28 +02:00
commit a28bb7be8f
2 changed files with 323 additions and 35 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,7 +24,9 @@ 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
from urwid_satext.files_management import FileDialog
from sat_frontends.bridge.DBus import DBusBridgeFrontend
@ -43,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):
@ -304,6 +307,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)
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):
@ -362,9 +371,69 @@ class PrimitivusApp(QuickApp, InputHistory):
self.showPopUp(popup)
super(PrimitivusApp, self).postInit(self.main_widget)
def keysToText(self, keys):
"""Generator return normal text from urwid keys"""
for k in keys:
if k == 'tab':
yield u'\t'
elif k == 'enter':
yield u'\n'
elif is_wide_char(k,0) or (len(k)==1 and ord(k) >= 32):
yield k
def inputFilter(self, input_, raw):
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 resize' in input_): # (e.g. using Primitivus through ssh). Need some testing
# and experience to adjust value.
if input_[0] == 'begin paste' and not self._bracketed_paste:
log.info(u"Bracketed paste mode detected")
self._bracketed_paste = True
if self._bracketed_paste:
# after this block, extra will contain non pasted keys
# and input_ will contain pasted keys
try:
begin_idx = input_.index('begin paste')
except ValueError:
# this is not a paste, maybe we have something buffering
# or bracketed mode is set in conf but not enabled in term
extra = input_
input_ = []
else:
try:
end_idx = input_.index('end paste')
except ValueError:
log.warning(u"missing end paste sequence, discarding paste")
extra = input_[:begin_idx]
del input_[begin_idx:]
else:
extra = input_[:begin_idx] + input_[end_idx+1:]
input_ = input_[begin_idx+1:end_idx]
else:
extra = None
log.debug(u"Paste detected (len {})".format(len(input_)))
try:
edit_bar = self.editBar
except AttributeError:
log.warning(u"Paste discarded: there is no edit bar yet")
else:
# XXX: if a paste is detected, we append it directly to the edit bar text
# so the use can check it and press [enter] if it's OK
buf_paste = u''.join(self.keysToText(input_))
pos = edit_bar.edit_pos
edit_bar.set_edit_text(u'{}{}{}'.format(edit_bar.edit_text[:pos], buf_paste, edit_bar.edit_text[pos:]))
edit_bar.edit_pos+=len(buf_paste)
if not extra:
return
input_ = extra
## end of paste detection/handling
for i in input_:
if isinstance(i,tuple):
if i[0] == 'mouse press':
@ -776,6 +845,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):