primitivus: bracketed paste mode is now detected

This commit is contained in:
Goffi 2016-04-23 00:31:59 +02:00
commit 0d3a96a8da

View file

@ -301,6 +301,7 @@ 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
@property
def visible_widgets(self):
@ -377,6 +378,33 @@ class PrimitivusApp(QuickApp, InputHistory):
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
# 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
@ -389,7 +417,9 @@ class PrimitivusApp(QuickApp, InputHistory):
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
for i in input_:
if isinstance(i,tuple):