Mercurial > libervia-backend
diff frontends/src/primitivus/primitivus @ 1948:373550000092
primitivus: bracketed paste mode is now detected
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 23 Apr 2016 00:31:59 +0200 |
parents | be4b143cf123 |
children | c5fd304d0976 |
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus Fri Apr 22 22:30:13 2016 +0200 +++ b/frontends/src/primitivus/primitivus Sat Apr 23 00:31:59 2016 +0200 @@ -301,6 +301,7 @@ # 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 @@ 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 @@ 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):