本文整理汇总了Python中prompt_toolkit.filters.has_focus方法的典型用法代码示例。如果您正苦于以下问题:Python filters.has_focus方法的具体用法?Python filters.has_focus怎么用?Python filters.has_focus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.filters
的用法示例。
在下文中一共展示了filters.has_focus方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_prefix_binding
# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import has_focus [as 别名]
def _load_prefix_binding(self):
"""
Load the prefix key binding.
"""
pymux = self.pymux
# Remove previous binding.
if self._prefix_binding:
self.custom_key_bindings.remove_binding(self._prefix_binding)
# Create new Python binding.
@self.custom_key_bindings.add(*self._prefix, filter=
~(HasPrefix(pymux) | has_focus(COMMAND) | has_focus(PROMPT) |
WaitsForConfirmation(pymux)))
def enter_prefix_handler(event):
" Enter prefix mode. "
pymux.get_client_state().has_prefix = True
self._prefix_binding = enter_prefix_handler
示例2: __init__
# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import has_focus [as 别名]
def __init__(self, editor):
def get_formatted_text():
eb = editor.window_arrangement.active_editor_buffer
lineno = eb.buffer.document.cursor_position_row
errors = eb.report_errors
for e in errors:
if e.lineno == lineno:
return e.formatted_text
return []
super(ReportMessageToolbar, self).__init__(
FormattedTextToolbar(get_formatted_text),
filter=~has_focus(editor.command_buffer) & ~is_searching & ~has_focus('system'))
示例3: add_custom_binding
# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import has_focus [as 别名]
def add_custom_binding(self, key_name, command, arguments, needs_prefix=False):
"""
Add custom binding (for the "bind-key" command.)
Raises ValueError if the give `key_name` is an invalid name.
:param key_name: Pymux key name, for instance "C-a" or "M-x".
"""
assert isinstance(key_name, six.text_type)
assert isinstance(command, six.text_type)
assert isinstance(arguments, list)
# Unbind previous key.
self.remove_custom_binding(key_name, needs_prefix=needs_prefix)
# Translate the pymux key name into a prompt_toolkit key sequence.
# (Can raise ValueError.)
keys_sequence = pymux_key_to_prompt_toolkit_key_sequence(key_name)
# Create handler and add to Registry.
if needs_prefix:
filter = HasPrefix(self.pymux)
else:
filter = ~HasPrefix(self.pymux)
filter = filter & ~(WaitsForConfirmation(self.pymux) |
has_focus(COMMAND) | has_focus(PROMPT))
def key_handler(event):
" The actual key handler. "
call_command_handler(command, self.pymux, arguments)
self.pymux.get_client_state().has_prefix = False
self.custom_key_bindings.add(*keys_sequence, filter=filter)(key_handler)
# Store key in `custom_bindings` in order to be able to call
# "unbind-key" later on.
k = (needs_prefix, key_name)
self.custom_bindings[k] = CustomBinding(key_handler, command, arguments)
示例4: _bufferlist_overlay_visible
# 需要导入模块: from prompt_toolkit import filters [as 别名]
# 或者: from prompt_toolkit.filters import has_focus [as 别名]
def _bufferlist_overlay_visible(editor):
"""
True when the buffer list overlay should be displayed.
(This is when someone starts typing ':b' or ':buffer' in the command line.)
"""
@Condition
def overlay_is_visible():
app = get_app()
text = editor.command_buffer.text.lstrip()
return app.layout.has_focus(editor.command_buffer) and (
any(text.startswith(p) for p in ['b ', 'b! ', 'buffer', 'buffer!']))
return overlay_is_visible