本文整理汇总了Python中readline.set_completer方法的典型用法代码示例。如果您正苦于以下问题:Python readline.set_completer方法的具体用法?Python readline.set_completer怎么用?Python readline.set_completer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类readline
的用法示例。
在下文中一共展示了readline.set_completer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_console
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def run_console(glob):
import readline
import rlcompleter
import atexit
import code
history_path = os.path.expanduser("~/.python_history")
def save_history(history_path=history_path):
readline.write_history_file(history_path)
if os.path.exists(history_path):
readline.read_history_file(history_path)
atexit.register(save_history)
readline.set_completer(rlcompleter.Completer(glob).complete)
readline.parse_and_bind("tab: complete")
code.InteractiveConsole(locals=glob).interact()
示例2: __init__
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def __init__(self):
"""Create the main mode.
If titus.inspector.defs.CONFIG_DIRECTORY_EXISTS is ``True``, get the readline history file from the user's titus.inspector.defs.CONFIG_DIRECTORY.
"""
if CONFIG_DIRECTORY_EXISTS:
self.historyPath = os.path.join(os.path.expanduser(CONFIG_DIRECTORY), self.historyFileName)
if not os.path.exists(self.historyPath):
open(self.historyPath, "w").close()
self.active = True
self.tabCompleter = TabCompleter(self)
readline.read_history_file(self.historyPath)
readline.set_completer(self.tabCompleter.complete)
def writehistory():
if self.active:
readline.write_history_file(self.historyPath)
atexit.register(writehistory)
示例3: get_input_autocomplete
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def get_input_autocomplete(message=''):
""" Allow user to type input and provide auto-completion """
# Apple does not ship GNU readline with OS X.
# It does ship BSD libedit which includes a readline compatibility interface.
# Source: https://stackoverflow.com/questions/7116038/python-tab-completion-mac-osx-10-7-lion
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
readline.set_completer(autocomplete)
try:
return input(message).strip()
except KeyboardInterrupt:
return False
except Exception: # Other Exception
return False
示例4: show_menu
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def show_menu(CommandClass, CompleterClass, name):
command = CommandClass(name)
completer = CompleterClass(command)
readline.set_completer(completer.complete)
readline.set_completer_delims(" ")
readline.parse_and_bind("tab: complete")
res = False
while res is not True:
valid_commands = command.cmd.keys()
ret_cmd = six.input("%s> " % name).strip()
cmd, options = (ret_cmd.split(" ")[0], " ".join(ret_cmd.split(" ")[1:]))
if cmd == "debug":
pdb.set_trace()
elif cmd.lower() in valid_commands:
res = command.run_cmd(cmd, options)
else:
print("Invalid command.")
readline.set_completer(completer.complete)
示例5: run
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def run(self, line):
ishellCompleter = readline.get_completer()
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(completer.complete)
sample_file = raw_input('Please enter the filename you want to open: ')
try:
sample_fh = open(sample_file,'r')
feathermodules.samples.extend([sample.strip() for sample in sample_fh.readlines()])
sample_fh.close()
feathermodules.samples = filter(lambda x: x != '' and x != None, feathermodules.samples)
except:
print 'Something went wrong. Sorry! Please try again.'
finally:
readline.set_completer(ishellCompleter)
示例6: setup
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def setup(self):
""" Initialization of third-party libraries
Setting interpreter history.
Setting appropriate completer function.
:return:
"""
if not os.path.exists(self.history_file):
open(self.history_file, 'a+').close()
readline.read_history_file(self.history_file)
readline.set_history_length(self.history_length)
atexit.register(readline.write_history_file, self.history_file)
readline.parse_and_bind('set enable-keypad on')
readline.set_completer(self.complete)
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
示例7: Input_completer
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def Input_completer(keywords):
completer = MyCompleter(keywords)
readline.set_completer(completer.complete)
if "libedit" in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind('tab: complete')
#readline.parse_and_bind('"\\e[A": complete') # Up arrow
readline.parse_and_bind("set colored-completion-prefix on")
readline.parse_and_bind("set show-all-if-unmodified on")
readline.parse_and_bind("set horizontal-scroll-mode on")
if os.path.exists(history_file):
readline.read_history_file(history_file)
readline.set_history_length(20)
readline.set_completer_delims(' ')
atexit.register(save_history)
示例8: use
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def use(self,args,pointer = None):
global POINTER
if(len(args) < 2):
return None
POINTER = args[1]
moduleName = args[1].split('/')
comp = Completer()
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
readline.set_completer(comp.complete)
while True:
input = raw_input('SMOD ' + moduleName[0] + '(' + bcolors.OKBLUE + moduleName[-1] + bcolors.ENDC + ') >').strip().split()
try:
result = getattr(globals()['Command'](),input[0])(input,args[1])
except:
return None
if (POINTER == None):
break
示例9: init_readline
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [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 :-(')
示例10: do_python
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def do_python(self,arg):
""" start the local python interpreter (for debugging purposes) """
orig_exit=builtins.exit
orig_quit=builtins.quit
def disabled_exit(*args, **kwargs):
self.display_warning("exit() disabled ! use ctrl+D to exit the python shell")
builtins.exit=disabled_exit
builtins.quit=disabled_exit
oldcompleter=readline.get_completer()
try:
local_ns={"pupsrv":self.pupsrv}
readline.set_completer(PythonCompleter(local_ns=local_ns).complete)
readline.parse_and_bind('tab: complete')
code.interact(local=local_ns)
except Exception as e:
self.display_error(str(e))
finally:
readline.set_completer(oldcompleter)
readline.parse_and_bind('tab: complete')
builtins.exit=orig_exit
builtins.quit=orig_quit
示例11: get_command
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def get_command(self, prompt, auto_complete_fn=None, basefile_fn=None):
try:
if auto_complete_fn != None:
import readline
readline.set_completer_delims(' \t\n;/')
readline.parse_and_bind("tab: complete")
readline.set_completer(auto_complete_fn)
# readline.set_completion_display_matches_hook(basefile_fn)
except:
pass
# python3 changes raw input name
if sys.version_info[0] == 3:
raw_input = input
else:
raw_input = __builtins__['raw_input']
cmd = raw_input("%s" % prompt)
return cmd.strip()
示例12: _cmdloop
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def _cmdloop(self, intro=None):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
"""
# An almost perfect copy from Cmd; however, the pseudo_raw_input portion
# has been split out so that it can be called separately
self.preloop()
if self.use_rawinput and self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey+": complete")
except ImportError:
pass
try:
if intro is not None:
self.intro = intro
if self.intro:
self.stdout.write(str(self.intro)+"\n")
stop = None
while not stop:
if self.cmdqueue:
line = self.cmdqueue.pop(0)
else:
line = self.pseudo_raw_input(self.prompt)
if (self.echo) and (isinstance(self.stdin, file)):
self.stdout.write(line + '\n')
stop = self.onecmd_plus_hooks(line)
self.postloop()
finally:
if self.use_rawinput and self.completekey:
try:
import readline
readline.set_completer(self.old_completer)
except ImportError:
pass
return stop
示例13: pause
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def pause(self):
"""Write the current history to the history file and stop readline."""
readline.write_history_file(self.historyPath)
readline.clear_history()
readline.set_completer()
self.active = False
示例14: resume
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def resume(self):
"""Read the history file and restart readline."""
self.active = True
readline.read_history_file(self.historyPath)
readline.set_completer(self.tabCompleter.complete)
示例15: loop
# 需要导入模块: import readline [as 别名]
# 或者: from readline import set_completer [as 别名]
def loop(self):
previous_completer = readline.get_completer()
readline.parse_and_bind("tab: complete")
readline.set_completer(self.walk)
prompt = self.prompt + self.prompt_delim
if not ishell._current_prompt:
previous_prompt = prompt
else:
previous_prompt = ishell._current_prompt
ishell._current_prompt = prompt
if self.welcome_message:
sys.stdout.write(self.welcome_message + "\n\r")
while 1:
try:
sys.stdout.write("\r")
if self._exit:
break
sys.stdout.write("\033[K")
input_ = input(prompt + " ")
if not input_.strip():
self.print_childs_help()
elif input_ in ('quit', 'exit'):
break
else:
self.walk_and_run(input_)
except (KeyboardInterrupt, EOFError):
print("exit")
break
except Exception:
print(traceback.format_exc())
sys.exit(1)
ishell._current_prompt = previous_prompt
readline.set_completer(previous_completer)