How to use the curtsies.events.PasteEvent 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 / examples / manualtestdelay.py View on Github external
def main():
    with Terminal(sys.stdin, sys.stdout, paste_mode=True) as tc:
        while True:
            e = tc.get_event()
            if isinstance(e, PasteEvent):
                print('PasteEvent!', repr(e.events))
            else:
                print('other event', e)
            for i in xrange(10000000):
                pass
            if e == '':
                return
github bpython / curtsies / examples / manualtestpaste.py View on Github external
def main():
    with Terminal(sys.stdin, sys.stdout, paste_mode=True) as tc:
        while True:
            e = tc.get_event()
            if isinstance(e, PasteEvent):
                print('PasteEvent!', repr(e.events))
            else:
                print('other event', e)
            if e == '':
                return
github bpython / bpython / bpython / curtsies.py View on Github external
Option('--log', '-L', action='store_true',
                help=_("log debug messages to bpython-curtsies.log")),
            Option('--type', '-t', action='store_true',
                help=_("enter lines of file as though interactively typed")),
            ]))
    if options.log:
        import logging
        logging.basicConfig(filename='scroll.log', level=logging.DEBUG)

    interp = None
    paste = None
    if exec_args:
        assert options, "don't pass in exec_args without options"
        exit_value = 0
        if options.type:
            paste = curtsies.events.PasteEvent()
            sourcecode = open(exec_args[0]).read()
            paste.events.extend(sourcecode)
        else:
            try:
                interp = code.InteractiveInterpreter(locals=locals_)
                bpargs.exec_code(interp, exec_args)
            except SystemExit, e:
                exit_value = e.args
            if not options.interactive:
                raise SystemExit(exit_value)
    else:
        sys.path.insert(0, '') # expected for interactive sessions (vanilla python does it)

    mainloop(config, locals_, banner, interp, paste)
github bpython / curtsies / curtsies / input.py View on Github external
if self.queued_scheduled_events and when < time.time():  # when should always be defined
            # because queued_scheduled_events should not be modified during this time
            logger.warning('popping an event! %r %r', self.queued_scheduled_events[0],
                           self.queued_scheduled_events[1:])
            return self.queued_scheduled_events.pop(0)[1]
        if not stdin_ready_for_read:
            return None

        num_bytes = self._nonblocking_read()
        if num_bytes == 0:
            # thought stdin was ready, but not bytes to read is triggered
            # when SIGTSTP was send by dsusp
            return None

        if self.paste_threshold is not None and num_bytes > self.paste_threshold:
            paste = events.PasteEvent()
            while True:
                if len(self.unprocessed_bytes) < events.MAX_KEYPRESS_SIZE:
                    self._nonblocking_read()  # may need to read to get the rest of a keypress
                e = find_key()
                if e is None:
                    return paste
                else:
                    paste.events.append(e)
        else:
            e = find_key()
            assert e is not None
            return e
github ianmiell / autotrace / autotrace / autotrace.py View on Github external
def write_to_manager_logfile(self, msg):
		if isinstance(msg, PasteEvent):
			msg = str(msg)
		assert isinstance(msg, unicode), str(type(msg))
		self.logfile.write(self.get_elapsed_time_str() + ' ' + str(msg) + '\n')
		self.logfile.flush()
github bpython / bpython / bpython / curtsies.py View on Github external
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 / bpython / bpython / curtsies.py View on Github external
logging.getLogger("bpython").setLevel(level)
    if options.log:
        handler = logging.FileHandler(filename="bpython.log")
        logging.getLogger("curtsies").addHandler(handler)
        logging.getLogger("curtsies").propagate = False
        logging.getLogger("bpython").addHandler(handler)
        logging.getLogger("bpython").propagate = False

    interp = None
    paste = None
    if exec_args:
        if not options:
            raise ValueError("don't pass in exec_args without options")
        exit_value = ()
        if options.paste:
            paste = curtsies.events.PasteEvent()
            encoding = inspection.get_encoding_file(exec_args[0])
            with io.open(exec_args[0], encoding=encoding) as f:
                sourcecode = f.read()
            paste.events.extend(sourcecode)
        else:
            try:
                interp = Interp(locals=locals_)
                bpargs.exec_code(interp, exec_args)
            except SystemExit as e:
                exit_value = e.args
            if not options.interactive:
                return extract_exit_value(exit_value)
    else:
        # expected for interactive sessions (vanilla python does it)
        sys.path.insert(0, "")
github ianmiell / autotrace / autotrace / autotrace.py View on Github external
def handle_input(self):
		self.trigger_debug = False
		quit_chars = (u'', u'', u'q')
		with Input() as input_generator:
			input_char = input_generator.send(self.timeout_delay)
			if isinstance(input_char, PasteEvent):
				input_char = str(input_char)[-1]
			if input_char:
				self.write_to_manager_logfile('input_char: ' + input_char)
			if input_char in quit_chars:
				self.quit_autotrace(msg=input_char + ' hit, quitting.')
			elif input_char in (u'r',):
				self.draw_screen('clearscreen',quick_help=self.get_quick_help())
			elif input_char in (u'd',):
				self.trigger_debug = True
			elif input_char in (u'm',):
				self.cycle_panes()
				self.draw_screen('sessions',quick_help=self.get_quick_help())
			elif input_char in (u'z',):
				# Revert layout status from zoomed
				self.zoomed_session = None
				self.do_layout('default')