本文整理汇总了Python中prompt_toolkit.layout.controls.BufferControl方法的典型用法代码示例。如果您正苦于以下问题:Python controls.BufferControl方法的具体用法?Python controls.BufferControl怎么用?Python controls.BufferControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.layout.controls
的用法示例。
在下文中一共展示了controls.BufferControl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def __init__(
self,
buffer_control: "BufferControl",
document: Document,
lineno: int,
source_to_display: SourceToDisplay,
fragments: StyleAndTextTuples,
width: int,
height: int,
) -> None:
self.buffer_control = buffer_control
self.document = document
self.lineno = lineno
self.source_to_display = source_to_display
self.fragments = fragments
self.width = width
self.height = height
示例2: create_tutorial_layout
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def create_tutorial_layout(lex):
""" layout for example tutorial """
lexer, _, _ = get_lexers(lex, None, None)
layout_full = HSplit([
FloatContainer(
Window(
BufferControl(
input_processors=input_processors,
lexer=lexer,
preview_search=Always()),
get_height=get_height),
[
Float(xcursor=True,
ycursor=True,
content=CompletionsMenu(
max_height=MAX_COMPLETION,
scroll_offset=1,
extra_filter=(HasFocus(DEFAULT_BUFFER))))]),
ConditionalContainer(
HSplit([
get_hline(),
get_param(lexer),
get_hline(),
Window(
content=BufferControl(
buffer_name='example_line',
lexer=lexer
),
),
Window(
TokenListControl(
get_tutorial_tokens,
default_char=Char(' ', Token.Toolbar)),
height=D.exact(1)),
]),
filter=~IsDone() & RendererHeightIsKnown()
)
])
return layout_full
示例3: get_descript
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def get_descript(lexer):
""" command description window """
return Window(
content=BufferControl(
buffer_name="description",
lexer=lexer))
示例4: get_param
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def get_param(lexer):
""" parameter description window """
return Window(
content=BufferControl(
buffer_name="parameter",
lexer=lexer))
示例5: get_example
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def get_example(config, exam_lex):
""" example description window """
if config.BOOLEAN_STATES[config.config.get('Layout', 'examples')]:
return Window(
content=BufferControl(
buffer_name="examples",
lexer=exam_lex))
else:
return get_empty()
示例6: current_search_state
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def current_search_state(self) -> SearchState:
"""
Return the current :class:`.SearchState`. (The one for the focused
:class:`.BufferControl`.)
"""
ui_control = self.layout.current_control
if isinstance(ui_control, BufferControl):
return ui_control.search_state
else:
return SearchState() # Dummy search state. (Don't return None!)
示例7: reverse_search_history
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def reverse_search_history(event: E) -> None:
"""
Search backward starting at the current line and moving `up` through
the history as necessary. This is an incremental search.
"""
control = event.app.layout.current_control
if isinstance(control, BufferControl) and control.search_buffer_control:
event.app.current_search_state.direction = SearchDirection.BACKWARD
event.app.layout.current_control = control.search_buffer_control
#
# Commands for changing text
#
示例8: buffer_has_focus
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def buffer_has_focus() -> bool:
"""
Enabled when the currently focused control is a `BufferControl`.
"""
return get_app().layout.buffer_has_focus
示例9: control_is_searchable
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def control_is_searchable() -> bool:
" When the current UIControl is searchable. "
from prompt_toolkit.layout.controls import BufferControl
control = get_app().layout.current_control
return (
isinstance(control, BufferControl) and control.search_buffer_control is not None
)
示例10: start_search
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def start_search(
buffer_control: Optional["BufferControl"] = None,
direction: SearchDirection = SearchDirection.FORWARD,
) -> None:
"""
Start search through the given `buffer_control` using the
`search_buffer_control`.
:param buffer_control: Start search for this `BufferControl`. If not given,
search through the current control.
"""
from prompt_toolkit.layout.controls import BufferControl
assert buffer_control is None or isinstance(buffer_control, BufferControl)
layout = get_app().layout
# When no control is given, use the current control if that's a BufferControl.
if buffer_control is None:
if not isinstance(layout.current_control, BufferControl):
return
buffer_control = layout.current_control
# Only if this control is searchable.
search_buffer_control = buffer_control.search_buffer_control
if search_buffer_control:
buffer_control.search_state.direction = direction
# Make sure to focus the search BufferControl
layout.focus(search_buffer_control)
# Remember search link.
layout.search_links[search_buffer_control] = buffer_control
# If we're in Vi mode, make sure to go into insert mode.
get_app().vi_state.input_mode = InputMode.INSERT
示例11: do_incremental_search
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def do_incremental_search(direction: SearchDirection, count: int = 1) -> None:
"""
Apply search, but keep search buffer focused.
"""
assert is_searching()
layout = get_app().layout
# Only search if the current control is a `BufferControl`.
from prompt_toolkit.layout.controls import BufferControl
search_control = layout.current_control
if not isinstance(search_control, BufferControl):
return
prev_control = layout.search_target_buffer_control
if prev_control is None:
return
search_state = prev_control.search_state
# Update search_state.
direction_changed = search_state.direction != direction
search_state.text = search_control.buffer.text
search_state.direction = direction
# Apply search to current buffer.
if not direction_changed:
prev_control.buffer.apply_search(
search_state, include_current_position=False, count=count
)
示例12: accept_search
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def accept_search() -> None:
"""
Accept current search query. Focus original `BufferControl` again.
"""
layout = get_app().layout
search_control = layout.current_control
target_buffer_control = layout.search_target_buffer_control
from prompt_toolkit.layout.controls import BufferControl
if not isinstance(search_control, BufferControl):
return
if target_buffer_control is None:
return
search_state = target_buffer_control.search_state
# Update search state.
if search_control.buffer.text:
search_state.text = search_control.buffer.text
# Apply search.
target_buffer_control.buffer.apply_search(
search_state, include_current_position=True
)
# Add query to history of search line.
search_control.buffer.append_to_history()
# Stop search and focus previous control again.
stop_search(target_buffer_control)
示例13: _get_reverse_search_links
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def _get_reverse_search_links(
layout: "Layout",
) -> Dict["BufferControl", "SearchBufferControl"]:
"""
Return mapping from BufferControl to SearchBufferControl.
"""
return {
buffer_control: search_buffer_control
for search_buffer_control, buffer_control in layout.search_links.items()
}
示例14: unpack
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def unpack(
self,
) -> Tuple[
"BufferControl", Document, int, SourceToDisplay, StyleAndTextTuples, int, int
]:
return (
self.buffer_control,
self.document,
self.lineno,
self.source_to_display,
self.fragments,
self.width,
self.height,
)
示例15: _get_search_text
# 需要导入模块: from prompt_toolkit.layout import controls [as 别名]
# 或者: from prompt_toolkit.layout.controls import BufferControl [as 别名]
def _get_search_text(self, buffer_control: "BufferControl") -> str:
"""
The text we are searching for.
"""
# When the search buffer has focus, take that text.
search_buffer = buffer_control.search_buffer
if search_buffer is not None and search_buffer.text:
return search_buffer.text
return ""