Пример #1
0
 def _bell(self):
     u'''ring the bell if requested.'''
     if self.bell_style == u'none':
         pass
     elif self.bell_style == u'visible':
         raise NotImplementedError(u"Bellstyle visible is not implemented yet.")
     elif self.bell_style == u'audible':
         self.console.bell()
     else:
         raise ReadlineError(u"Bellstyle %s unknown."%self.bell_style)
Пример #2
0
 def _bell(self):
     if self.bell_style == 'none':
         pass
     elif self.bell_style == 'visible':
         raise NotImplementedError(
             'Bellstyle visible is not implemented yet.')
     elif self.bell_style == 'audible':
         self.console.bell()
     else:
         raise ReadlineError('Bellstyle %s unknown.' % self.bell_style)
Пример #3
0
    def read_inputrc(self, #in 2.4 we cannot call expanduser with unicode string
                     inputrcpath=os.path.expanduser("~/pyreadlineconfig.ini")):
        modes = dict([(x.mode,x) for x in self.editingmodes])
        mode = self.editingmodes[0].mode

        def setmode(name):
            self.mode = modes[name]

        def bind_key(key, name):
            import new
            if callable(name):
                modes[mode]._bind_key(key, new.instancemethod(name, modes[mode], modes[mode].__class__))
            elif hasattr(modes[mode], name):
                modes[mode]._bind_key(key, getattr(modes[mode], name))
            else:
                print u"Trying to bind unknown command '%s' to key '%s'"%(name, key)

        def un_bind_key(key):
            keyinfo = make_KeyPress_from_keydescr(key).tuple()
            if keyinfo in modes[mode].key_dispatch:
                del modes[mode].key_dispatch[keyinfo]

        def bind_exit_key(key):
            modes[mode]._bind_exit_key(key)
            
        def un_bind_exit_key(key):
            keyinfo = make_KeyPress_from_keydescr(key).tuple()
            if keyinfo in modes[mode].exit_dispatch:
                del modes[mode].exit_dispatch[keyinfo]

        def setkill_ring_to_clipboard(killring):
            import pyreadline.lineeditor.lineobj 
            pyreadline.lineeditor.lineobj.kill_ring_to_clipboard = killring

        def sethistoryfilename(filename):
            self.mode._history.history_filename=os.path.expanduser(filename)

        def setbellstyle(mode):
            self.bell_style = mode

        def disable_readline(mode):
            self.disable_readline = mode

        def sethistorylength(length):
            self.mode._history.history_length = int(length)

        def allow_ctrl_c(mode):
            log(u"allow_ctrl_c:%s:%s"%(self.allow_ctrl_c, mode))
            self.allow_ctrl_c = mode
 
        def setbellstyle(mode):
            self.bell_style = mode
 
        def show_all_if_ambiguous(mode):
            self.mode.show_all_if_ambiguous = mode
        
        def ctrl_c_tap_time_interval(mode):
            self.ctrl_c_tap_time_interval = mode
        
        def mark_directories(mode):
            self.mode.mark_directories = mode
        
        def completer_delims(delims):
            self.mode.completer_delims = delims
        
        def complete_filesystem(delims):
            self.mode.complete_filesystem = delims.lower()

        def enable_ipython_paste_for_paths(boolean):
            self.mode.enable_ipython_paste_for_paths = boolean

        def debug_output(on, filename=u"pyreadline_debug_log.txt"): #Not implemented yet
            if on in [u"on", u"on_nologfile"]:
                self.debug=True

            if on == "on":
                logger.start_file_log(filename)
                logger.start_socket_log()
                logger.log(u"STARTING LOG")
            elif on == u"on_nologfile":
                logger.start_socket_log()
                logger.log(u"STARTING LOG")
            else:
                logger.log(u"STOPING LOG")
                logger.stop_file_log()
                logger.stop_socket_log()
        
        _color_trtable={u"black":0,      u"darkred":4,  u"darkgreen":2, 
                        u"darkyellow":6, u"darkblue":1, u"darkmagenta":5,
                        u"darkcyan":3,   u"gray":7,     u"red":4+8,
                        u"green":2+8,    u"yellow":6+8, u"blue":1+8,
                        u"magenta":5+8,  u"cyan":3+8,   u"white":7+8}
        
        def set_prompt_color(color):
            self.prompt_color = self._color_trtable.get(color.lower(),7)            
            
        def set_input_color(color):
            self.command_color=self._color_trtable.get(color.lower(),7)            

        loc = {u"branch":release.branch,
               u"version":release.version,
               u"mode":mode,
               u"modes":modes,
               u"set_mode":setmode,
               u"bind_key":bind_key,
               u"disable_readline":disable_readline,
               u"bind_exit_key":bind_exit_key,
               u"un_bind_key":un_bind_key,
               u"un_bind_exit_key":un_bind_exit_key,
               u"bell_style":setbellstyle,
               u"mark_directories":mark_directories,
               u"show_all_if_ambiguous":show_all_if_ambiguous,
               u"completer_delims":completer_delims,
               u"complete_filesystem":complete_filesystem,
               u"debug_output":debug_output,
               u"history_filename":sethistoryfilename,
               u"history_length":sethistorylength,
               u"set_prompt_color":set_prompt_color,
               u"set_input_color":set_input_color,
               u"allow_ctrl_c":allow_ctrl_c,
               u"ctrl_c_tap_time_interval":ctrl_c_tap_time_interval,
               u"kill_ring_to_clipboard":setkill_ring_to_clipboard,
               u"enable_ipython_paste_for_paths":enable_ipython_paste_for_paths,
              }
        if os.path.isfile(inputrcpath): 
            try:
                execfile(inputrcpath, loc, loc)
            except Exception,x:
                raise
                import traceback
                print >>sys.stderr, u"Error reading .pyinputrc"
                filepath,lineno=traceback.extract_tb(sys.exc_traceback)[1][:2]
                print >>sys.stderr, u"Line: %s in file %s"%(lineno, filepath)
                print >>sys.stderr, x
                raise ReadlineError(u"Error reading .pyinputrc")
Пример #4
0
    def read_inputrc(self,
                     inputrcpath=os.path.expanduser('~/pyreadlineconfig.ini')):
        modes = dict([(x.mode, x) for x in self.editingmodes])
        mode = self.editingmodes[0].mode

        def setmode(name):
            self.mode = modes[name]

        def bind_key(key, name):
            import new
            if callable(name):
                modes[mode]._bind_key(
                    key,
                    new.instancemethod(name, modes[mode],
                                       modes[mode].__class__))
            elif hasattr(modes[mode], name):
                modes[mode]._bind_key(key, getattr(modes[mode], name))
            else:
                print "Trying to bind unknown command '%s' to key '%s'" % (
                    name, key)

        def un_bind_key(key):
            keyinfo = make_KeyPress_from_keydescr(key).tuple()
            if keyinfo in modes[mode].key_dispatch:
                del modes[mode].key_dispatch[keyinfo]

        def bind_exit_key(key):
            modes[mode]._bind_exit_key(key)

        def un_bind_exit_key(key):
            keyinfo = make_KeyPress_from_keydescr(key).tuple()
            if keyinfo in modes[mode].exit_dispatch:
                del modes[mode].exit_dispatch[keyinfo]

        def setkill_ring_to_clipboard(killring):
            import pyreadline.lineeditor.lineobj
            pyreadline.lineeditor.lineobj.kill_ring_to_clipboard = killring

        def sethistoryfilename(filename):
            self.mode._history.history_filename = os.path.expanduser(filename)

        def setbellstyle(mode):
            self.bell_style = mode

        def disable_readline(mode):
            self.disable_readline = mode

        def sethistorylength(length):
            self.mode._history.history_length = int(length)

        def allow_ctrl_c(mode):
            log('allow_ctrl_c:%s:%s' % (self.allow_ctrl_c, mode))
            self.allow_ctrl_c = mode

        def setbellstyle(mode):
            self.bell_style = mode

        def show_all_if_ambiguous(mode):
            self.mode.show_all_if_ambiguous = mode

        def ctrl_c_tap_time_interval(mode):
            self.ctrl_c_tap_time_interval = mode

        def mark_directories(mode):
            self.mode.mark_directories = mode

        def completer_delims(delims):
            self.mode.completer_delims = delims

        def complete_filesystem(delims):
            self.mode.complete_filesystem = delims.lower()

        def enable_ipython_paste_for_paths(boolean):
            self.mode.enable_ipython_paste_for_paths = boolean

        def debug_output(on, filename='pyreadline_debug_log.txt'):
            if on in ('on', 'on_nologfile'):
                self.debug = True
            if on == 'on':
                logger.start_file_log(filename)
                logger.start_socket_log()
                logger.log('STARTING LOG')
            elif on == 'on_nologfile':
                logger.start_socket_log()
                logger.log('STARTING LOG')
            else:
                logger.log('STOPING LOG')
                logger.stop_file_log()
                logger.stop_socket_log()

        _color_trtable = {
            'black': 0,
            'darkred': 4,
            'darkgreen': 2,
            'darkyellow': 6,
            'darkblue': 1,
            'darkmagenta': 5,
            'darkcyan': 3,
            'gray': 7,
            'red': 12,
            'green': 10,
            'yellow': 14,
            'blue': 9,
            'magenta': 13,
            'cyan': 11,
            'white': 15
        }

        def set_prompt_color(color):
            self.prompt_color = self._color_trtable.get(color.lower(), 7)

        def set_input_color(color):
            self.command_color = self._color_trtable.get(color.lower(), 7)

        loc = {
            'branch': release.branch,
            'version': release.version,
            'mode': mode,
            'modes': modes,
            'set_mode': setmode,
            'bind_key': bind_key,
            'disable_readline': disable_readline,
            'bind_exit_key': bind_exit_key,
            'un_bind_key': un_bind_key,
            'un_bind_exit_key': un_bind_exit_key,
            'bell_style': setbellstyle,
            'mark_directories': mark_directories,
            'show_all_if_ambiguous': show_all_if_ambiguous,
            'completer_delims': completer_delims,
            'complete_filesystem': complete_filesystem,
            'debug_output': debug_output,
            'history_filename': sethistoryfilename,
            'history_length': sethistorylength,
            'set_prompt_color': set_prompt_color,
            'set_input_color': set_input_color,
            'allow_ctrl_c': allow_ctrl_c,
            'ctrl_c_tap_time_interval': ctrl_c_tap_time_interval,
            'kill_ring_to_clipboard': setkill_ring_to_clipboard,
            'enable_ipython_paste_for_paths': enable_ipython_paste_for_paths
        }
        if os.path.isfile(inputrcpath):
            try:
                execfile(inputrcpath, loc, loc)
            except Exception, x:
                raise
                import traceback
                print >> sys.stderr, 'Error reading .pyinputrc'
                filepath, lineno = traceback.extract_tb(
                    sys.exc_traceback)[1][:2]
                print >> sys.stderr, 'Line: %s in file %s' % (lineno, filepath)
                print >> sys.stderr, x
                raise ReadlineError('Error reading .pyinputrc')
Пример #5
0
    def read_inputrc(self,inputrcpath=os.path.expanduser("~/pyreadlineconfig.ini")):
        modes=dict([(x.mode,x) for x in self.editingmodes])
        mode=self.editingmodes[0].mode
        def setmode(name):
            self.mode=modes[name]
        def bind_key(key,name):
            log("bind %s %s"%(key,name))
            if hasattr(modes[mode],name):
                modes[mode]._bind_key(key,getattr(modes[mode],name))
            else:
                print "Trying to bind unknown command '%s' to key '%s'"%(name,key)
        def un_bind_key(key):
            keyinfo = make_KeyPress_from_keydescr(key).tuple()
            if keyinfo in modes[mode].key_dispatch:
                del modes[mode].key_dispatch[keyinfo]

        def bind_exit_key(key):
            modes[mode]._bind_exit_key(key)
        def un_bind_exit_key(key):
            keyinfo = make_KeyPress_from_keydescr(key).tuple()
            if keyinfo in modes[mode].exit_dispatch:
                del modes[mode].exit_dispatch[keyinfo]

        def setkill_ring_to_clipboard(killring):
            import pyreadline.lineeditor.lineobj 
            pyreadline.lineeditor.lineobj.kill_ring_to_clipboard=killring
        def sethistoryfilename(filename):
            self._history.history_filename=os.path.expanduser(filename)
        def setbellstyle(mode):
            self.bell_style=mode
        def sethistorylength(length):
            self._history.history_length=int(length)
        def allow_ctrl_c(mode):
            log_sock("allow_ctrl_c:%s:%s"%(self.allow_ctrl_c,mode))
            self.allow_ctrl_c=mode
        def setbellstyle(mode):
            self.bell_style=mode
        def show_all_if_ambiguous(mode):
            self.show_all_if_ambiguous=mode
        def ctrl_c_tap_time_interval(mode):
            self.ctrl_c_tap_time_interval=mode
        def mark_directories(mode):
            self.mark_directories=mode
        def completer_delims(mode):
            self.completer_delims=mode
        def debug_output(on,filename="pyreadline_debug_log.txt"):  #Not implemented yet
            if on in ["on","on_nologfile"]:
                self.debug=True
            logger.start_log(on,filename)
            logger.log("STARTING LOG")
#            print release.branch
        def set_prompt_color(color):
            trtable={"black":0,"darkred":4,"darkgreen":2,"darkyellow":6,"darkblue":1,"darkmagenta":5,"darkcyan":3,"gray":7,
                     "red":4+8,"green":2+8,"yellow":6+8,"blue":1+8,"magenta":5+8,"cyan":3+8,"white":7+8}
            self.prompt_color=trtable.get(color.lower(),7)            
            
        def set_input_color(color):
            trtable={"black":0,"darkred":4,"darkgreen":2,"darkyellow":6,"darkblue":1,"darkmagenta":5,"darkcyan":3,"gray":7,
                     "red":4+8,"green":2+8,"yellow":6+8,"blue":1+8,"magenta":5+8,"cyan":3+8,"white":7+8}
            self.command_color=trtable.get(color.lower(),7)            
        loc={"branch":release.branch,
             "version":release.version,
             "mode":mode,
             "modes":modes,
             "set_mode":setmode,
             "bind_key":bind_key,
             "bind_exit_key":bind_exit_key,
             "un_bind_key":un_bind_key,
             "un_bind_exit_key":un_bind_exit_key,
             "bell_style":setbellstyle,
             "mark_directories":mark_directories,
             "show_all_if_ambiguous":show_all_if_ambiguous,
             "completer_delims":completer_delims,
             "debug_output":debug_output,
             "history_filename":sethistoryfilename,
             "history_length":sethistorylength,
             "set_prompt_color":set_prompt_color,
             "set_input_color":set_input_color,
             "allow_ctrl_c":allow_ctrl_c,
             "ctrl_c_tap_time_interval":ctrl_c_tap_time_interval,
             "kill_ring_to_clipboard":setkill_ring_to_clipboard,
             }
        if os.path.isfile(inputrcpath): 
            try:
                execfile(inputrcpath,loc,loc)
            except Exception,x:
                raise
                import traceback
                print >>sys.stderr, "Error reading .pyinputrc"
                filepath,lineno=traceback.extract_tb(sys.exc_traceback)[1][:2]
                print >>sys.stderr, "Line: %s in file %s"%(lineno,filepath)
                print >>sys.stderr, x
                raise ReadlineError("Error reading .pyinputrc")