How to use the curtsies.events.Event 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 / curtsies / events.py View on Github external
class WindowChangeEvent(Event):
    def __init__(self, rows, columns, cursor_dy=None):
        self.rows = rows
        self.columns = columns
        self.cursor_dy = cursor_dy
    x = width = property(lambda self: self.columns)
    y = height = property(lambda self: self.rows)
    def __repr__(self):
        return "" % (self.rows, self.columns,
                '' if self.cursor_dy is None else " cursor_dy: %d" % self.cursor_dy)
    @property
    def name(self):
        return ''

class SigIntEvent(Event):
    """Event signifying a SIGINT"""
    def __repr__(self):
        return ""
    @property
    def name(self):
        return repr(self)

class PasteEvent(Event):
    """Multiple keypress events combined, likely from copy/paste.

    The events attribute contains a list of keypress event strings.
    """
    def __init__(self):
        self.events = []
    def __repr__(self):
        return "" % self.events
github bpython / bpython / bpython / curtsiesfrontend / events.py View on Github external
import time

import curtsies.events


class ReloadEvent(curtsies.events.Event):
    """Request to rerun REPL session ASAP because imported modules changed"""

    def __init__(self, files_modified=("?",)):
        self.files_modified = files_modified

    def __repr__(self):
        return "" % (" & ".join(self.files_modified))


class RefreshRequestEvent(curtsies.events.Event):
    """Request to refresh REPL display ASAP"""

    def __repr__(self):
        return ""


class ScheduledRefreshRequestEvent(curtsies.events.ScheduledEvent):
    """Request to refresh the REPL display at some point in the future

    Used to schedule the disappearance of status bar message that only shows
    for a few seconds"""

    def __init__(self, when):
        super(ScheduledRefreshRequestEvent, self).__init__(when)

    def __repr__(self):
github bpython / bpython / bpython / curtsiesfrontend / events.py View on Github external
# encoding: utf-8

"""Non-keyboard events used in bpython curtsies REPL"""
import time

import curtsies.events


class ReloadEvent(curtsies.events.Event):
    """Request to rerun REPL session ASAP because imported modules changed"""

    def __init__(self, files_modified=("?",)):
        self.files_modified = files_modified

    def __repr__(self):
        return "" % (" & ".join(self.files_modified))


class RefreshRequestEvent(curtsies.events.Event):
    """Request to refresh REPL display ASAP"""

    def __repr__(self):
        return ""
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
def is_simple_event(e):
    if isinstance(e, events.Event):
        return False
    if e in ("", "", "", "\n", "\r", ""):
        return True
    if len(e) > 1:
        return False
    else:
        return True
github bpython / bpython / bpython / curtsiesfrontend / repl.py View on Github external
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"):
                    self.on_enter()
                    while self.fake_refresh_request:
                        self.fake_refresh_request = False
                        self.process_event(events.RefreshRequestEvent())
                elif isinstance(ee, events.Event):
                    pass # ignore events in a paste
                else:
                    self.add_normal_character(ee if len(ee) == 1 else ee[-1]) #strip control seq
            self.paste_mode = False
            self.update_completion()

        elif e in self.rl_char_sequences:
            self.cursor_offset_in_line, self._current_line = self.rl_char_sequences[e](self.cursor_offset_in_line, self._current_line)
            self.update_completion()

        # readline history commands
        elif e in ("KEY_UP",) + key_dispatch[self.config.up_one_line_key]:
            self.rl_history.enter(self._current_line)
            self._current_line = self.rl_history.back(False)
            self.cursor_offset_in_line = len(self._current_line)
            self.update_completion()
github bpython / curtsies / curtsies / events.py View on Github external
class Event(object):
    pass

class ScheduledEvent(Event):
    """Event scheduled for a future time.

    args:
        when (float): unix time in seconds for which this event is scheduled

    Custom events that occur at a specific time in the future should
    be subclassed from ScheduledEvent."""
    def __init__(self, when):
        self.when = when

class WindowChangeEvent(Event):
    def __init__(self, rows, columns, cursor_dy=None):
        self.rows = rows
        self.columns = columns
        self.cursor_dy = cursor_dy
    x = width = property(lambda self: self.columns)
    y = height = property(lambda self: self.rows)
    def __repr__(self):
        return "" % (self.rows, self.columns,
                '' if self.cursor_dy is None else " cursor_dy: %d" % self.cursor_dy)
    @property
    def name(self):
        return ''

class SigIntEvent(Event):
    """Event signifying a SIGINT"""
    def __repr__(self):
github bpython / curtsies / curtsies / events.py View on Github external
def __repr__(self):
        return "" % (self.rows, self.columns,
                '' if self.cursor_dy is None else " cursor_dy: %d" % self.cursor_dy)
    @property
    def name(self):
        return ''

class SigIntEvent(Event):
    """Event signifying a SIGINT"""
    def __repr__(self):
        return ""
    @property
    def name(self):
        return repr(self)

class PasteEvent(Event):
    """Multiple keypress events combined, likely from copy/paste.

    The events attribute contains a list of keypress event strings.
    """
    def __init__(self):
        self.events = []
    def __repr__(self):
        return "" % self.events
    @property
    def name(self):
        return repr(self)

def decodable(seq, encoding):
    try:
        u = seq.decode(encoding)
    except UnicodeDecodeError:
github bpython / bpython / bpython / curtsies.py View on Github external
def _combined_events(event_provider, paste_threshold):
    """Combines consecutive keypress events into paste events."""
    timeout = yield "nonsense_event"  # so send can be used immediately
    queue = collections.deque()
    while True:
        e = event_provider.send(timeout)
        if isinstance(e, curtsies.events.Event):
            timeout = yield e
            continue
        elif e is None:
            timeout = yield None
            continue
        else:
            queue.append(e)
        e = event_provider.send(0)
        while not (e is None or isinstance(e, curtsies.events.Event)):
            queue.append(e)
            e = event_provider.send(0)
        if len(queue) >= paste_threshold:
            paste = curtsies.events.PasteEvent()
            paste.events.extend(queue)
            queue.clear()
            timeout = yield paste
        else:
            while len(queue):
                timeout = yield queue.popleft()
github bpython / curtsies / curtsies / events.py View on Github external
CURSES_NAMES[b'\x1b[OF'] = u'KEY_END'          # end    (1)
CURSES_NAMES[b'\x1b[OH'] = u'KEY_HOME'         # home   (7)

KEYMAP_PREFIXES = set()
for table in (CURSES_NAMES, CURTSIES_NAMES):
    for k in table:
        if k.startswith(b'\x1b'):
            for i in range(1, len(k)):
                KEYMAP_PREFIXES.add(k[:i])

MAX_KEYPRESS_SIZE = max(len(seq) for seq in (list(CURSES_NAMES.keys()) + list(CURTSIES_NAMES.keys())))

class Event(object):
    pass

class ScheduledEvent(Event):
    """Event scheduled for a future time.

    args:
        when (float): unix time in seconds for which this event is scheduled

    Custom events that occur at a specific time in the future should
    be subclassed from ScheduledEvent."""
    def __init__(self, when):
        self.when = when

class WindowChangeEvent(Event):
    def __init__(self, rows, columns, cursor_dy=None):
        self.rows = rows
        self.columns = columns
        self.cursor_dy = cursor_dy
    x = width = property(lambda self: self.columns)