本文整理汇总了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 ''
示例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")
示例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
示例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
示例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
示例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)