本文整理汇总了Python中prompt_toolkit.history.InMemoryHistory方法的典型用法代码示例。如果您正苦于以下问题:Python history.InMemoryHistory方法的具体用法?Python history.InMemoryHistory怎么用?Python history.InMemoryHistory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.history
的用法示例。
在下文中一共展示了history.InMemoryHistory方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bootstrap_prompt
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def bootstrap_prompt(prompt_kwargs, group):
"""
Bootstrap prompt_toolkit kwargs or use user defined values.
:param prompt_kwargs: The user specified prompt kwargs.
"""
prompt_kwargs = prompt_kwargs or {}
defaults = {
"history": InMemoryHistory(),
"completer": ClickCompleter(group),
"message": u"> ",
}
for key in defaults:
default_value = defaults[key]
if key not in prompt_kwargs:
prompt_kwargs[key] = default_value
return prompt_kwargs
示例2: main
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def main():
settings = Settings()
bindings = get_bindings(settings)
executor = Executor(settings)
toolbar = Toolbar(settings)
completer = KafkaCompleter(settings) if settings.enable_auto_complete else None
suggester = AutoSuggestFromHistory() if settings.enable_auto_suggest else None
history = ThreadedHistory(FileHistory(get_user_history_path())) if settings.enable_history else InMemoryHistory()
session = PromptSession(completer=completer, style=style, bottom_toolbar=toolbar.handler,
key_bindings=bindings, history=history, include_default_pygments_style=False)
while True:
try:
command = session.prompt([("class:operator", "> ")], auto_suggest=suggester)
except KeyboardInterrupt:
continue
except EOFError:
break
else:
executor.execute(command)
settings.save_settings()
示例3: __init__
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def __init__(self, completer=None, styles=None,
lexer=None, history=InMemoryHistory(),
app=None, input_custom=sys.stdout, output_custom=None):
self.styles = styles
if styles:
self.lexer = lexer or AzLexer
else:
self.lexer = None
self.app = app
self.completer = completer
self.history = history
self._cli = None
self.refresh_cli = False
self.layout = None
self.description_docs = u''
self.param_docs = u''
self.example_docs = u''
self._env = os.environ
self.last = None
self.last_exit = 0
self.input = input_custom
self.output = output_custom
self.config_default = ""
self.default_command = ""
示例4: run
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def run(self):
""" Main entry function. """
history = InMemoryHistory()
self._load_file()
while True:
# (re)load the todo.txt file (only if it has been modified)
try:
user_input = prompt(u'topydo> ', history=history,
completer=self.completer,
complete_while_typing=False)
user_input = shlex.split(user_input)
except EOFError:
sys.exit(0)
except KeyboardInterrupt:
continue
except ValueError as verr:
error('Error: ' + str(verr))
continue
try:
(subcommand, args) = get_subcommand(user_input)
except ConfigError as ce:
error('Error: ' + str(ce) + '. Check your aliases configuration')
continue
try:
if self._execute(subcommand, args) != False:
self._post_execute()
except TypeError:
print(GENERIC_HELP)
示例5: shell
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def shell(self, items, pargs):
self.pargs = pargs
self.items = items
stdout.write(
'\n') # When the fetching messege ends need to add \n after \r.
self.prompt_show_items()
history = InMemoryHistory()
session = PromptSession() if PROMPT_TOOLKIT_V2 else None
while True:
kwargs = dict(
history=history,
auto_suggest=AutoSuggestFromHistory(),
completer=WGCompleter(list(self.items.keys())),
style=we_get_prompt_style
)
try:
p = prompt(u'we-get > ', **kwargs)
except TypeError as e:
log.debug('{}:{}'.format(type(e), e))
kwargs.pop('history')
if PROMPT_TOOLKIT_V2:
p = session.prompt(u'we-get > ', **kwargs)
else:
p = prompt(u'we-get > ', **kwargs)
if self.prompt_no_command(p):
continue
elif self.prompt_is_single_command(p):
command = p
args = None
else:
_ = p.split()
command = _[0]
_.pop(0)
args = ' '.join(_)
if not self.prompt_verify_command(command, args):
continue
elif not self.prompt_parse_command(command, args):
break
示例6: main
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def main():
# Create some history first. (Easy for testing.)
history = InMemoryHistory()
history.append_string("import os")
history.append_string('print("hello")')
history.append_string('print("world")')
history.append_string("import path")
# Print help.
print("This CLI has fish-style auto-suggestion enable.")
print('Type for instance "pri", then you\'ll see a suggestion.')
print("Press the right arrow to insert the suggestion.")
print("Press Control-C to retry. Control-D to exit.")
print()
session = PromptSession(
history=history,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True,
)
while True:
try:
text = session.prompt("Say something: ")
except KeyboardInterrupt:
pass # Ctrl-C pressed. Try again.
else:
break
print("You said: %s" % text)
示例7: main
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def main():
# Create some history first. (Easy for testing.)
history = InMemoryHistory()
history.append_string("import os")
history.append_string('print("hello")')
history.append_string('print("world")')
history.append_string("import path")
# Print help.
print("This CLI has up-arrow partial string matching enabled.")
print('Type for instance "pri" followed by up-arrow and you')
print('get the last items starting with "pri".')
print("Press Control-C to retry. Control-D to exit.")
print()
session = PromptSession(history=history, enable_history_search=True)
while True:
try:
text = session.prompt("Say something: ")
except KeyboardInterrupt:
pass # Ctrl-C pressed. Try again.
else:
break
print("You said: %s" % text)
示例8: _history
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def _history():
" Prefilled history. "
history = InMemoryHistory()
history.append_string("alpha beta gamma delta")
history.append_string("one two three four")
return history
# Test yank_last_arg.
示例9: _history
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def _history():
h = InMemoryHistory()
h.append_string("line1 first input")
h.append_string("line2 second input")
h.append_string("line3 third input")
return h
示例10: __init__
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def __init__(self, completer, model_completer, docs,
input=None, output=None, popen_cls=None):
self.completer = completer
self.model_completer = model_completer
self.history = InMemoryHistory()
self.file_history = FileHistory(build_config_file_path('history'))
self._cli = None
self._docs = docs
self.current_docs = u''
self.refresh_cli = False
self.key_manager = None
self._dot_cmd = DotCommandHandler()
self._env = os.environ.copy()
self._profile = None
self._input = input
self._output = output
if popen_cls is None:
popen_cls = subprocess.Popen
self._popen_cls = popen_cls
# These attrs come from the config file.
self.config_obj = None
self.config_section = None
self.enable_vi_bindings = None
self.show_completion_columns = None
self.show_help = None
self.theme = None
self.load_config()
示例11: __prompt_init
# 需要导入模块: from prompt_toolkit import history [as 别名]
# 或者: from prompt_toolkit.history import InMemoryHistory [as 别名]
def __prompt_init(self):
self.asm_history = InMemoryHistory()
self.dsm_history = InMemoryHistory()
self.prompt_style = style_from_pygments_dict({
Token: '#ff0066',
Token.OS: '#ff3838',
Token.Colon: '#ffffff',
Token.Mode: '#f9a9c3 bold',
Token.Arch: '#5db2fc',
Token.Pound: '#ffd82a',
})