Ejemplo n.º 1
0
    def handle_ctrl_c(self):
        from pyreadline.keysyms.common import KeyPress
        from pyreadline.console.event import Event
        log_sock("KBDIRQ")
        event = Event(0, 0)
        event.char = "c"
        event.keyinfo = KeyPress("c",
                                 shift=False,
                                 control=True,
                                 meta=False,
                                 keyname=None)
        if self.allow_ctrl_c:
            now = time.time()
            if (now - self.ctrl_c_timeout) < self.ctrl_c_tap_time_interval:
                log_sock("Raise KeyboardInterrupt")
                raise KeyboardInterrupt
            else:
                self.ctrl_c_timeout = now
        else:
            raise KeyboardInterrupt

        dispatch_func = self.key_dispatch.get(event.keyinfo.tuple(), None)
        if dispatch_func:
            r = dispatch_func(event)
            self._keylog(dispatch_func, self.l_buffer)
            self.l_buffer.push_undo()
Ejemplo n.º 2
0
    def _readline_from_keyboard(self):
        c = self.console

        def nop(e):
            pass

        while 1:
            self._update_line()
            try:
                event = c.getkeypress()
            except KeyboardInterrupt:
                from pyreadline.keysyms.common import KeyPress
                from pyreadline.console.event import Event
                event = Event(0, 0)
                event.char = "c"
                event.keyinfo = KeyPress("c",
                                         shift=False,
                                         control=True,
                                         meta=False,
                                         keyname=None)
                log_sock("KBDIRQ")
                if self.allow_ctrl_c:
                    now = time.time()
                    if (now - self.ctrl_c_timeout
                        ) < self.ctrl_c_tap_time_interval:
                        raise
                    else:
                        self.ctrl_c_timeout = now
                    pass
                else:
                    raise
            if self.next_meta:
                self.next_meta = False
                control, meta, shift, code = event.keyinfo
                event.keyinfo = (control, True, shift, code)

            #Process exit keys. Only exit on empty line
            keyinfo = event.keyinfo.tuple()
            if keyinfo in self.exit_dispatch:
                if lineobj.EndOfLine(self.l_buffer) == 0:
                    raise EOFError
            if len(keyinfo[-1]) > 1:
                default = nop
            else:
                default = self.self_insert
            dispatch_func = self.key_dispatch.get(keyinfo, default)

            log("readline from keyboard:%s,%s" % (keyinfo, dispatch_func))
            log_sock("%s|%s" % (format(keyinfo), dispatch_func.__name__),
                     "bound_function")
            r = None
            if dispatch_func:
                r = dispatch_func(event)
                self._keylog(dispatch_func, self.l_buffer)
                self.l_buffer.push_undo()

            self.previous_func = dispatch_func
            if r:
                self._update_line()
                break
Ejemplo n.º 3
0
    def handle_ctrl_c(self):
        from pyreadline.keysyms.common import KeyPress
        from pyreadline.console.event import Event
        log("KBDIRQ")
        event = Event(0, 0)
        event.char = "c"
        event.keyinfo = KeyPress("c",
                                 shift=False,
                                 control=True,
                                 meta=False,
                                 keyname=None)
        if self.allow_ctrl_c:
            now = time.time()
            if (now - self.ctrl_c_timeout) < self.ctrl_c_tap_time_interval:
                log("Raise KeyboardInterrupt")
                raise KeyboardInterrupt
            else:
                self.ctrl_c_timeout = now
        else:
            if self.line_end_pos:
                self.console.pos(self.line_end_pos[0], self.line_end_pos[1])
            self.console.clear_state()
            self.mode.clear_state()

            raise KeyboardInterrupt
        return event
Ejemplo n.º 4
0
    def _readline_from_keyboard(self):
        c = self.console

        def nop(e):
            pass

        while 1:
            self._update_line()
            lbuf = self.l_buffer
            log_sock("point:%d mark:%d selection_mark:%d" % (lbuf.point, lbuf.mark, lbuf.selection_mark))
            try:
                event = c.getkeypress()
                log_sock(u">>%s" % event)
            except KeyboardInterrupt:
                from pyreadline.keysyms.common import KeyPress
                from pyreadline.console.event import Event
                event = Event(0, 0)
                event.char = "c"
                event.keyinfo = KeyPress("c", shift=False, control=True, meta=False, keyname=None)
                log_sock("KBDIRQ")
                if self.allow_ctrl_c:
                    now = time.time()
                    if (now - self.ctrl_c_timeout) < self.ctrl_c_tap_time_interval:
                        raise
                    else:
                        self.ctrl_c_timeout = now
                    pass
                else:
                    raise
            if self.next_meta:
                self.next_meta = False
                control, meta, shift, code = event.keyinfo
                event.keyinfo = (control, True, shift, code)

            # Process exit keys. Only exit on empty line
            keyinfo = event.keyinfo.tuple()
            if keyinfo in self.exit_dispatch:
                if lineobj.EndOfLine(self.l_buffer) == 0:
                    raise EOFError
            if len(keyinfo[-1]) > 1:
                default = nop
            else:
                default = self.self_insert
            dispatch_func = self.key_dispatch.get(keyinfo, default)

            log("readline from keyboard:%s,%s" % (keyinfo, dispatch_func))
            log_sock((u"%s|%s" % (ensure_unicode(format(keyinfo)), dispatch_func.__name__)), "bound_function")
            r = None
            if dispatch_func:
                r = dispatch_func(event)
                self._keylog(dispatch_func, self.l_buffer)
                self.l_buffer.push_undo()

            self.previous_func = dispatch_func
            if r:
                self._update_line()
                break
Ejemplo n.º 5
0
 def handle_ctrl_c(self):
     from pyreadline.console.event import Event
     log("KBDIRQ")
     event = Event(0,0)
     event.char = "c"
     event.keyinfo = KeyPress(char="c", shift=False, control=True,
                              meta=False, keyname=None)
     if self.allow_ctrl_c:
         now = time.time()
         if (now - self.ctrl_c_timeout) < self.ctrl_c_tap_time_interval:
             log("Raise KeyboardInterrupt")
             raise KeyboardInterrupt
         else:
             self.ctrl_c_timeout = now
     else:
         raise KeyboardInterrupt
     return event
Ejemplo n.º 6
0
 def handle_ctrl_c(self):
     from pyreadline.keysyms.common import KeyPress
     from pyreadline.console.event import Event
     log('KBDIRQ')
     event = Event(0, 0)
     event.char = 'c'
     event.keyinfo = KeyPress('c',
                              shift=False,
                              control=True,
                              meta=False,
                              keyname=None)
     if self.allow_ctrl_c:
         now = time.time()
         if now - self.ctrl_c_timeout < self.ctrl_c_tap_time_interval:
             log('Raise KeyboardInterrupt')
             raise KeyboardInterrupt
         else:
             self.ctrl_c_timeout = now
     else:
         raise KeyboardInterrupt
     return event
Ejemplo n.º 7
0
 def handle_ctrl_c(self):
     from pyreadline.keysyms.common import KeyPress
     from pyreadline.console.event import Event
     log("KBDIRQ")
     event = Event(0,0)
     event.char = "c"
     event.keyinfo = KeyPress("c", shift=False, control=True, 
                              meta=False, keyname=None)
     if self.allow_ctrl_c:
         now = time.time()
         if (now - self.ctrl_c_timeout) < self.ctrl_c_tap_time_interval:
             log("Raise KeyboardInterrupt")
             raise KeyboardInterrupt
         else:
             self.ctrl_c_timeout = now
     else:
         if self.line_end_pos:
             self.console.pos(self.line_end_pos[0], self.line_end_pos[1])
         self.console.clear_state()
         self.mode.clear_state()
     
         raise KeyboardInterrupt
     return event