当前位置: 首页>>代码示例>>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;未经允许,请勿转载。