How to use the curtsies.events function in curtsies

To help you get started, we’ve selected a few curtsies examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bpython / curtsies / tests / test_events.py View on Github external
def test_helpers(self):
        self.assertEqual(events.chr_byte(97), b'a')
        self.assertEqual(events.chr_uni(97), u'a')
github bpython / curtsies / tests / test_events.py View on Github external
def test_sequences_without_names(self):
        get_utf = partial(events.get_key, encoding='utf-8', keynames='curtsies', full=False)
        self.assertEqual(get_utf([b'\xc3'], full=True), '')
        self.assertEqual(get_utf([b'\xc3'], full=True, keynames='curses'), 'xC3')
github bpython / curtsies / tests / test_events.py View on Github external
def test_key_names(self):
        "Every key sequence with a Curses name should have a Curtsies name too."
        self.assertTrue(set(events.CURTSIES_NAMES).issuperset(set(events.CURSES_NAMES)), set(events.CURSES_NAMES) - set(events.CURTSIES_NAMES))
github bpython / bpython / bpython / curtsiesfrontend / interaction.py View on Github external
def process_event(self, e):
        """Returns True if shutting down"""
        assert self.in_prompt or self.in_confirm or self.waiting_for_refresh
        if isinstance(e, RefreshRequestEvent):
            self.waiting_for_refresh = False
            self.request_context.switch()
        elif isinstance(e, events.PasteEvent):
            for ee in e.events:
                # strip control seq
                self.add_normal_character(ee if len(ee) == 1 else ee[-1])
        elif e in [""] or isinstance(e, events.SigIntEvent):
            self.request_context.switch(False)
            self.escape()
        elif e in edit_keys:
            self.cursor_offset_in_line, self._current_line = edit_keys[e](
                self.cursor_offset_in_line, self._current_line
            )
        elif e == "":  # TODO can this be removed?
            raise KeyboardInterrupt()
        elif e == "":  # TODO this isn't a very intuitive behavior
            raise SystemExit()
        elif self.in_prompt and e in ("\n", "\r", "", "Ctrl-m>"):
            line = self._current_line
github bpython / curtsies / curtsies / terminal.py View on Github external
self.refresh_queued = False
                return events.RefreshRequestEvent('terminal control')
            if len(chars) > 6: #debugging tool - eventually detect all key sequences!
                raise ValueError("Key sequence not detected at some point: %r" % ''.join(chars))
            logging.debug('getting key for %r', chars)
            logging.debug('self.in_buffer %r', self.in_buffer)
            if chars == ["\x1b"]:
                # This also won't work on Windows I think
                if self.in_buffer or self.nonblocking_read():
                    chars.append(self.in_buffer.pop(0))
                    continue
                else:
                    c = '\x1b'
                    chars = []
            else:
                c = events.get_key(chars, keynames=keynames)

            # c is a keyname or None for an incomplete prefix.
            # Here the pending input has two cases: either
            #   * c is None: pending is chars + self.in_buffer.
            #   * c is not None: pending is self.in_buffer.

            if c:
                if self.paste_mode_enabled:
                    # This needs to be disabled if we ever want to work with Windows
                    #TODO take the in_buffer into account here!
                    if self.in_buffer or self.nonblocking_read():
                        if not paste_event:
                            paste_event = events.PasteEvent()
                        paste_event.events.append(c)
                        chars = []
                    else:
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
def just_simple_events(event_list):
    simple_events = []
    for e in event_list:
        # '\n' necessary for pastes
        if e in ("", "", "", "\n", "\r"):
            simple_events.append("\n")
        elif isinstance(e, events.Event):
            pass  # ignore events
        elif e == "":
            simple_events.append(" ")
        elif len(e) > 1:
            pass  # get rid of  etc.
        else:
            simple_events.append(e)
    return simple_events
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
elif isinstance(e, bpythonevents.RunStartupFileEvent):
            try:
                self.startup()
            except IOError as e:
                self.status_bar.message(
                    _("Executing PYTHONSTARTUP failed: %s") % (e,)
                )

        elif isinstance(e, bpythonevents.UndoEvent):
            self.undo(n=e.n)

        elif self.stdin.has_focus:
            return self.stdin.process_event(e)

        elif isinstance(e, events.SigIntEvent):
            logger.debug("received sigint event")
            self.keyboard_interrupt()
            return

        elif isinstance(e, bpythonevents.ReloadEvent):
            if self.watching_files:
                self.clear_modules_and_reevaluate()
                self.status_bar.message(
                    _("Reloaded at %s because %s modified.")
                    % (time.strftime("%X"), " & ".join(e.files_modified))
                )

        else:
            raise ValueError("Don't know how to handle event type: %r" % e)
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
# event names uses here are curses compatible, or the full names
        # for a full list of what should have pretty names, see curtsies.events.CURSES_TABLE

        if not isinstance(e, events.Event):
            self.last_events.append(e)
            self.last_events.pop(0)

        result = None
        logging.debug("processing event %r", e)
        if isinstance(e, events.RefreshRequestEvent):
            if self.status_bar.has_focus:
                self.status_bar.process_event(e)
            else:
                assert self.coderunner.code_is_waiting
                self.run_code_and_maybe_finish()
        elif isinstance(e, events.WindowChangeEvent):
            logging.debug('window change to %d %d', e.width, e.height)
            self.width, self.height = e.width, e.height
        elif self.status_bar.has_focus:
            result = self.status_bar.process_event(e)
        elif self.stdin.has_focus:
            result = self.stdin.process_event(e)

        elif isinstance(e, events.SigIntEvent):
            logging.debug('received sigint event')
            self.keyboard_interrupt()
            self.update_completion()
            return
        elif isinstance(e, events.PasteEvent):
            self.paste_mode = True
            for ee in e.events:
                if ee in ("\n", "\r", "PAD_ENTER"):