本文整理匯總了Python中prompt_toolkit.token.Token.Prompt方法的典型用法代碼示例。如果您正苦於以下問題:Python Token.Prompt方法的具體用法?Python Token.Prompt怎麽用?Python Token.Prompt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類prompt_toolkit.token.Token
的用法示例。
在下文中一共展示了Token.Prompt方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: apply_transformation
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def apply_transformation(self, cli, document, lineno, source_to_display, tokens):
# Get text before cursor.
if cli.is_searching:
before = _get_isearch_tokens(cli)
elif cli.input_processor.arg is not None:
before = _get_arg_tokens(cli)
else:
before = self.get_tokens(cli)
# Insert before buffer text.
shift_position = token_list_len(before)
# Only show the prompt before the first line. For the following lines,
# only indent using spaces.
if lineno != 0:
before = [(Token.Prompt, ' ' * shift_position)]
return Transformation(
tokens=before + tokens,
source_to_display=lambda i: i + shift_position,
display_to_source=lambda i: i - shift_position)
示例2: _get_isearch_tokens
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def _get_isearch_tokens(cli):
def before():
if cli.search_state.direction == IncrementalSearchDirection.BACKWARD:
text = 'reverse-i-search'
else:
text = 'i-search'
return [(Token.Prompt.Search, '(%s)`' % text)]
def text():
return [(Token.Prompt.Search.Text, cli.buffers[SEARCH_BUFFER].text)]
def after():
return [(Token.Prompt.Search, '`: ')]
return before() + text() + after()
示例3: pt_init
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def pt_init(self):
def get_prompt_tokens(cli):
return [(Token.Prompt, self.prompt)]
if self._ptcomp is None:
compl = IPCompleter(shell=self.shell,
namespace={},
global_namespace={},
use_readline=False,
parent=self.shell,
)
self._ptcomp = IPythonPTCompleter(compl)
self._pt_app = create_prompt_application(
editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
history=self.shell.debugger_history,
completer= self._ptcomp,
enable_history_search=True,
mouse_support=self.shell.mouse_support,
get_prompt_tokens=get_prompt_tokens
)
self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
示例4: from_message
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def from_message(cls, message='> '):
"""
Create a default prompt with a static message text.
"""
assert isinstance(message, text_type)
def get_message_tokens(cli):
return [(Token.Prompt, message)]
return cls(get_message_tokens)
示例5: _get_arg_tokens
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def _get_arg_tokens(cli):
"""
Tokens for the arg-prompt.
"""
arg = cli.input_processor.arg
return [
(Token.Prompt.Arg, '(arg: '),
(Token.Prompt.Arg.Text, str(arg)),
(Token.Prompt.Arg, ') '),
]
示例6: pt_init
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def pt_init(self):
def get_prompt_tokens(cli):
return [(Token.Prompt, self.prompt)]
def patch_stdout(**kwargs):
return self.pt_cli.patch_stdout_context(**kwargs)
if self._ptcomp is None:
compl = IPCompleter(shell=self.shell,
namespace={},
global_namespace={},
parent=self.shell,
)
self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout)
kbmanager = KeyBindingManager.for_prompt()
supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend
)(suspend_to_bg)
if self.shell.display_completions == 'readlinelike':
kbmanager.registry.add_binding(Keys.ControlI,
filter=(HasFocus(DEFAULT_BUFFER)
& ~HasSelection()
& ViInsertMode() | EmacsInsertMode()
& ~cursor_in_leading_ws
))(display_completions_like_readline)
multicolumn = (self.shell.display_completions == 'multicolumn')
self._pt_app = create_prompt_application(
editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
key_bindings_registry=kbmanager.registry,
history=self.shell.debugger_history,
completer= self._ptcomp,
enable_history_search=True,
mouse_support=self.shell.mouse_support,
get_prompt_tokens=get_prompt_tokens,
display_completions_in_columns=multicolumn,
style=self.shell.style
)
self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
示例7: get_prompt_tokens
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def get_prompt_tokens(self, cli):
return [(Token.Prompt, '> ')]
示例8: pt_init
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def pt_init(self):
def get_prompt_tokens(cli):
return [(Token.Prompt, self.prompt)]
def patch_stdout(**kwargs):
return self.pt_cli.patch_stdout_context(**kwargs)
if self._ptcomp is None:
compl = IPCompleter(shell=self.shell,
namespace={},
global_namespace={},
use_readline=False,
parent=self.shell,
)
self._ptcomp = IPythonPTCompleter(compl, patch_stdout=patch_stdout)
kbmanager = KeyBindingManager.for_prompt()
supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP'))
kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend
)(suspend_to_bg)
if self.shell.display_completions == 'readlinelike':
kbmanager.registry.add_binding(Keys.ControlI,
filter=(HasFocus(DEFAULT_BUFFER)
& ~HasSelection()
& ViInsertMode() | EmacsInsertMode()
& ~cursor_in_leading_ws
))(display_completions_like_readline)
multicolumn = (self.shell.display_completions == 'multicolumn')
self._pt_app = create_prompt_application(
editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
key_bindings_registry=kbmanager.registry,
history=self.shell.debugger_history,
completer= self._ptcomp,
enable_history_search=True,
mouse_support=self.shell.mouse_support,
get_prompt_tokens=get_prompt_tokens,
display_completions_in_columns=multicolumn,
)
self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
示例9: get_prompt_tokens
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def get_prompt_tokens(cli):
return [
(Token.Prompt, ' :) '),
]
示例10: get_continuation_tokens
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def get_continuation_tokens(cli, width):
return [(Token.Prompt, ' ] ')]
示例11: run
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import Prompt [as 別名]
def run(self):
style = style_from_dict({
Token.Prompt: 'bold',
Token.Toolbar: '#ccc bg:#333',
Token.Name: '#fff bold bg:#333',
})
history = InMemoryHistory()
eventloop = create_eventloop()
app = create_prompt_application(history=history, style=style,
get_bottom_toolbar_tokens=self.get_bottom_toolbar_tokens,
get_prompt_tokens=self.get_prompt_tokens)
self.cli = CommandLineInterface(app, eventloop)
with self.cli.patch_stdout_context(raw=True):
while True:
try:
self.cli.run()
doc = self.cli.return_value()
if doc is None:
return
cmd = shlex.split(doc.text)
app.buffer.reset(append_to_history=True)
if not cmd:
continue
elif cmd[0] in ('exit', 'quit'):
self.q.put(Exit())
return
elif cmd[0] == 'help':
print('Help text forthcoming.')
elif cmd[0] == 'skip':
self.q.put(Skip())
elif cmd[0] == 'set':
self.q.put(Set(cmd[1], ast.literal_eval(' '.join(cmd[2:]))))
else:
print('Unknown command. Try \'help\'.')
except KeyboardInterrupt:
continue
except EOFError:
self.q.put(Exit())
return
except Exception as err:
print(err)
self.q.put(Exit())
return