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


Python readline.set_pre_input_hook方法代碼示例

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


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

示例1: toggle_auto_indent

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_pre_input_hook [as 別名]
def toggle_auto_indent(self, _):
        """{TOGGLE_AUTO_INDENT_CMD} - Toggles the auto-indentation behavior
        """
        hook = None if config['AUTO_INDENT'] else self.auto_indent_hook
        msg = '# Auto-Indent has been {}abled\n'.format('en' if hook else 'dis')
        config['AUTO_INDENT'] = bool(hook)

        if hook is None:
            msg += ('# End of blocks will be detected after 3 empty lines\n'
                    '# Re-type {TOGGLE_AUTO_INDENT_CMD} on a line by itself to enable')

        readline.set_pre_input_hook(hook)
        print(grey(msg.format(**config), bold=False))
        return '' 
開發者ID:lonetwin,項目名稱:pythonrc,代碼行數:16,代碼來源:pythonrc.py

示例2: init_completer

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_pre_input_hook [as 別名]
def init_completer(self):
		readline.set_pre_input_hook(self.pre_input_hook)
		readline.set_completer_delims(" \t") 
開發者ID:krintoxi,項目名稱:NoobSec-Toolkit,代碼行數:5,代碼來源:PupyCmd.py

示例3: editable_input

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_pre_input_hook [as 別名]
def editable_input(prompt, prefill=None):
    def hook():
        readline.insert_text(prefill)
        readline.redisplay()
    readline.set_pre_input_hook(hook)
    result = input(green(prompt + ': '))
    readline.set_pre_input_hook()
    return result 
開發者ID:Evidlo,項目名稱:passhole,代碼行數:10,代碼來源:passhole.py

示例4: input_prefill

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_pre_input_hook [as 別名]
def input_prefill(prompt, text):
    def hook():
        readline.insert_text(text)
        readline.redisplay()

    readline.set_pre_input_hook(hook)
    result = input(prompt)
    readline.set_pre_input_hook()
    return result 
開發者ID:mmeyer724,項目名稱:sshmenu,代碼行數:11,代碼來源:sshmenu.py

示例5: input_with_prefill

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_pre_input_hook [as 別名]
def input_with_prefill(prompt, text):
        def hook():
            readline.insert_text(text)
            readline.redisplay()
        readline.set_pre_input_hook(hook)

        if sys.version_info >= (3,):
            result = input(prompt)
        else:
            result = raw_input(prompt)

        readline.set_pre_input_hook()
        return result 
開發者ID:FirefighterBlu3,項目名稱:python-pam,代碼行數:15,代碼來源:pam.py

示例6: init_readline

# 需要導入模塊: import readline [as 別名]
# 或者: from readline import set_pre_input_hook [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


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