當前位置: 首頁>>代碼示例>>Python>>正文


Python readline.get_completer_delims方法代碼示例

本文整理匯總了Python中readline.get_completer_delims方法的典型用法代碼示例。如果您正苦於以下問題:Python readline.get_completer_delims方法的具體用法?Python readline.get_completer_delims怎麽用?Python readline.get_completer_delims使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在readline的用法示例。


在下文中一共展示了readline.get_completer_delims方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: init_readline

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer_delims [as 別名]
def init_readline(complete_method, histfile=None):
    """init the readline library if available"""
    try:
        import readline
        readline.parse_and_bind("tab: complete")
        readline.set_completer(complete_method)
        string = readline.get_completer_delims().replace(':', '')
        readline.set_completer_delims(string)
        if histfile is not None:
            try:
                readline.read_history_file(histfile)
            except IOError:
                pass
            import atexit
            atexit.register(readline.write_history_file, histfile)
    except:
        print('readline si not available :-(') 
開發者ID:jlachowski,項目名稱:clonedigger,代碼行數:19,代碼來源:cli.py

示例2: autocomplete

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer_delims [as 別名]
def autocomplete(command: str):
    """..."""
    # On Linux/OSX the completer delims are retrieved from the readline module,
    # but the delims are different on Windows. So for testing consistency we
    # supply the Linux/OSX delims explicitly here in place of:
    # readline.get_completer_delims()

    completer_delims = ' \t\n`~!@#$%^&*()-=+[{]}\\|;:\'",<>/?'

    with patch('readline.get_line_buffer', return_value=command):
        cs = CauldronShell()
        line = command.lstrip()

        splits = re.split('[{}]{{1}}'.format(
            re.escape(completer_delims)),
            line
        )

        return cs.completedefault(
            text=splits[-1],
            line=line,
            begin_index=len(line) - len(splits[-1]),
            end_index=len(line) - 1
        ) 
開發者ID:sernst,項目名稱:cauldron,代碼行數:26,代碼來源:__init__.py

示例3: complete

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer_delims [as 別名]
def complete(self, text, state):
        """Return the next possible completion for 'text'.

        If a command has not been entered, then complete against command list.
        Otherwise try to call complete_<command> to get list of completions.
        """
        if state == 0:
            import readline
            old_delims = readline.get_completer_delims()
            readline.set_completer_delims(old_delims.replace('#', ''))
            origline = readline.get_line_buffer()
            line = origline.lstrip()
            stripped = len(origline) - len(line)
            begidx = readline.get_begidx() - stripped
            endidx = readline.get_endidx() - stripped
            if begidx > 0:
                cmd, args, foo = self.parseline(line)
                if cmd == '':
                    compfunc = self.completedefault
                else:
                    try:
                        compfunc = getattr(self, 'complete_' + cmd)
                    except AttributeError:
                        compfunc = self.completedefault
            else:
                compfunc = self.completenames
            self.completion_matches = compfunc(text, line, begidx, endidx)
        try:
            return self.completion_matches[state]
        except IndexError:
            return None 
開發者ID:antonioCoco,項目名稱:SharPyShell,代碼行數:33,代碼來源:SharPyShellPrompt.py

示例4: __enter__

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer_delims [as 別名]
def __enter__(self) -> 'Completer':
        with suppress(Exception):
            readline.read_history_file(self.history_path)
        readline.set_completer(self.complete)
        delims = readline.get_completer_delims()
        readline.set_completer_delims(delims.replace('-', ''))
        return self 
開發者ID:kovidgoyal,項目名稱:kitty,代碼行數:9,代碼來源:shell.py

示例5: set_readline

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer_delims [as 別名]
def set_readline(self):
        if not objectmodel.we_are_translated():
            self.old_completer = readline.get_completer()
            self.old_delims = readline.get_completer_delims()
            readline.set_completer(completer)
            readline.set_completer_delims("\t ") 
開發者ID:hpi-swa,項目名稱:RSqueak,代碼行數:8,代碼來源:shell.py

示例6: init_readline

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer_delims [as 別名]
def init_readline(self):
        """Activates history and tab completion
        """
        # - mainly borrowed from site.enablerlcompleter() from py3.4+

        # Reading the initialization (config) file may not be enough to set a
        # completion key, so we set one first and then read the file.
        readline_doc = getattr(readline, '__doc__', '')
        if readline_doc is not None and 'libedit' in readline_doc:
            readline.parse_and_bind('bind ^I rl_complete')
        else:
            readline.parse_and_bind('tab: complete')

        try:
            readline.read_init_file()
        except OSError:
            # An OSError here could have many causes, but the most likely one
            # is that there's no .inputrc file (or .editrc file in the case of
            # Mac OS X + libedit) in the expected location.  In that case, we
            # want to ignore the exception.
            pass

        if readline.get_current_history_length() == 0:
            # If no history was loaded, default to .python_history.
            # The guard is necessary to avoid doubling history size at
            # each interpreter exit when readline was already configured
            # see: http://bugs.python.org/issue5845#msg198636
            try:
                readline.read_history_file(config['HISTFILE'])
            except IOError:
                pass
            atexit.register(readline.write_history_file,
                            config['HISTFILE'])
        readline.set_history_length(config['HISTSIZE'])

        # - replace default completer
        readline.set_completer(self.improved_rlcompleter())

        # - enable auto-indenting
        if config['AUTO_INDENT']:
            readline.set_pre_input_hook(self.auto_indent_hook)

        # - remove '/' and '~' from delimiters to help with path completion
        completer_delims = readline.get_completer_delims()
        completer_delims = completer_delims.replace('/', '')
        if config.get('COMPLETION_EXPANDS_TILDE'):
            completer_delims = completer_delims.replace('~', '')
        readline.set_completer_delims(completer_delims) 
開發者ID:lonetwin,項目名稱:pythonrc,代碼行數:50,代碼來源:pythonrc.py

示例7: run_interactive_gtp_session

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import get_completer_delims [as 別名]
def run_interactive_gtp_session(engine):
    """Run a GTP engine session on stdin and stdout, using readline.

    engine -- Gtp_engine_protocol object

    This enables readline tab-expansion, and command history in
    ~/.gomill-gtp-history (if readline is available).

    Returns either when EOF is seen on stdin, or when the engine signals end of
    session.

    If stdin isn't a terminal, this is equivalent to run_gtp_session.

    If a write fails with 'broken pipe', this raises ControllerDisconnected.

    Note that this will propagate KeyboardInterrupt if the user presses ^C;
    normally you'll want to handle this to avoid an ugly traceback.

    """
    # readline doesn't do anything if stdin isn't a tty, but it's simplest to
    # just not import it in that case.
    try:
        use_readline = os.isatty(sys.stdin.fileno())
        if use_readline:
            import readline
    except Exception:
        use_readline = False
    if not use_readline:
        run_gtp_session(engine, sys.stdin, sys.stdout)
        return

    def write(s):
        sys.stdout.write(s)
        sys.stdout.flush()

    history_pathname = os.path.expanduser("~/.gomill-gtp-history")
    readline.parse_and_bind("tab: complete")
    old_completer = readline.get_completer()
    old_delims = readline.get_completer_delims()
    readline.set_completer(make_readline_completer(engine))
    readline.set_completer_delims("")
    try:
        readline.read_history_file(history_pathname)
    except EnvironmentError:
        pass
    _run_gtp_session(engine, raw_input, write)
    try:
        readline.write_history_file(history_pathname)
    except EnvironmentError:
        pass
    readline.set_completer(old_completer)
    readline.set_completer_delims(old_delims) 
開發者ID:pnprog,項目名稱:goreviewpartner,代碼行數:54,代碼來源:gtp_engine.py


注:本文中的readline.get_completer_delims方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。