Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
1947:be4b143cf123 | 1948:373550000092 |
---|---|
299 | 299 |
300 self.x_notify = Notify() | 300 self.x_notify = Notify() |
301 | 301 |
302 # we already manage exit with a_key['APP_QUIT'], so we don't want C-c | 302 # we already manage exit with a_key['APP_QUIT'], so we don't want C-c |
303 signal.signal(signal.SIGINT, signal.SIG_IGN) | 303 signal.signal(signal.SIGINT, signal.SIG_IGN) |
304 self._bracketed_paste = False | |
304 | 305 |
305 @property | 306 @property |
306 def visible_widgets(self): | 307 def visible_widgets(self): |
307 return self._visible_widgets | 308 return self._visible_widgets |
308 | 309 |
375 | 376 |
376 if (len(input_) > 1 and # XXX: it may be needed to increase this value if buffer | 377 if (len(input_) > 1 and # XXX: it may be needed to increase this value if buffer |
377 not isinstance(input_[0], tuple) and # or other things result in several chars at once | 378 not isinstance(input_[0], tuple) and # or other things result in several chars at once |
378 not 'window' in input_[0]): # (e.g. using Primitivus through ssh). Need some testing | 379 not 'window' in input_[0]): # (e.g. using Primitivus through ssh). Need some testing |
379 # and experience to adjust value. | 380 # and experience to adjust value. |
381 if input_[0] == 'begin paste' and not self._bracketed_paste: | |
382 log.info(u"Bracketed paste mode detected") | |
383 self._bracketed_paste = True | |
384 | |
385 if self._bracketed_paste: | |
386 # after this block, extra will contain non pasted keys | |
387 # and input_ will contain pasted keys | |
388 try: | |
389 begin_idx = input_.index('begin paste') | |
390 except ValueError: | |
391 # this is not a paste, maybe we have something buffering | |
392 # or bracketed mode is set in conf but not enabled in term | |
393 extra = input_ | |
394 input_ = [] | |
395 else: | |
396 try: | |
397 end_idx = input_.index('end paste') | |
398 except ValueError: | |
399 log.warning(u"missing end paste sequence, discarding paste") | |
400 extra = input_[:begin_idx] | |
401 del input_[begin_idx:] | |
402 else: | |
403 extra = input_[:begin_idx] + input_[end_idx+1:] | |
404 input_ = input_[begin_idx+1:end_idx] | |
405 else: | |
406 extra = None | |
407 | |
380 log.debug(u"Paste detected (len {})".format(len(input_))) | 408 log.debug(u"Paste detected (len {})".format(len(input_))) |
381 try: | 409 try: |
382 edit_bar = self.editBar | 410 edit_bar = self.editBar |
383 except AttributeError: | 411 except AttributeError: |
384 log.warning(u"Paste discarded: there is no edit bar yet") | 412 log.warning(u"Paste discarded: there is no edit bar yet") |
387 # so the use can check it and press [enter] if it's OK | 415 # so the use can check it and press [enter] if it's OK |
388 buf_paste = u''.join(self.keysToText(input_)) | 416 buf_paste = u''.join(self.keysToText(input_)) |
389 pos = edit_bar.edit_pos | 417 pos = edit_bar.edit_pos |
390 edit_bar.set_edit_text(u'{}{}{}'.format(edit_bar.edit_text[:pos], buf_paste, edit_bar.edit_text[pos:])) | 418 edit_bar.set_edit_text(u'{}{}{}'.format(edit_bar.edit_text[:pos], buf_paste, edit_bar.edit_text[pos:])) |
391 edit_bar.edit_pos+=len(buf_paste) | 419 edit_bar.edit_pos+=len(buf_paste) |
420 if not extra: | |
392 return | 421 return |
422 input_ = extra | |
393 | 423 |
394 for i in input_: | 424 for i in input_: |
395 if isinstance(i,tuple): | 425 if isinstance(i,tuple): |
396 if i[0] == 'mouse press': | 426 if i[0] == 'mouse press': |
397 if i[1] == 4: #Mouse wheel up | 427 if i[1] == 4: #Mouse wheel up |