本文整理汇总了Python中prompt_toolkit.buffer.Buffer方法的典型用法代码示例。如果您正苦于以下问题:Python buffer.Buffer方法的具体用法?Python buffer.Buffer怎么用?Python buffer.Buffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.buffer
的用法示例。
在下文中一共展示了buffer.Buffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_buffer
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def _create_buffer(self) -> Buffer:
"""
Create the `Buffer` for the Python input.
"""
python_buffer = Buffer(
name=DEFAULT_BUFFER,
complete_while_typing=Condition(lambda: self.complete_while_typing),
enable_history_search=Condition(lambda: self.enable_history_search),
tempfile_suffix=".py",
history=self.history,
completer=ThreadedCompleter(self._completer),
validator=ConditionalValidator(
self._validator, Condition(lambda: self.enable_input_validation)
),
auto_suggest=ConditionalAutoSuggest(
ThreadedAutoSuggest(AutoSuggestFromHistory()),
Condition(lambda: self.enable_auto_suggest),
),
accept_handler=self._accept_handler,
on_text_changed=self._on_input_timeout,
)
return python_buffer
示例2: test_undo_capitalize
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def test_undo_capitalize(self):
buffer = Buffer()
text = 'Selec'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('Selec', buffer.text)
text = buffer.text + 't'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('SELECT', buffer.text)
text = buffer.text + 'i'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('Selecti', buffer.text)
text = buffer.text + 'on'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('Selection', buffer.text)
示例3: __init__
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def __init__(self, terminal=None):
assert isinstance(terminal, Terminal)
self.terminal = terminal
self.chosen_name = None
# Displayed the clock instead of this pane content.
self.clock_mode = False
# Give unique ID.
Pane._pane_counter += 1
self.pane_id = Pane._pane_counter
# Prompt_toolkit buffer, for displaying scrollable text.
# (In copy mode, or help mode.)
# Note: Because the scroll_buffer can only contain text, we also use the
# get_tokens_for_line, that returns the token list with color
# information for each line.
self.scroll_buffer = Buffer(read_only=True)
self.copy_get_tokens_for_line = lambda lineno: []
self.display_scroll_buffer = False
self.scroll_buffer_title = ''
示例4: has_focus
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def has_focus(self, value: FocusableElement) -> bool:
"""
Check whether the given control has the focus.
:param value: :class:`.UIControl` or :class:`.Window` instance.
"""
if isinstance(value, str):
if self.current_buffer is None:
return False
return self.current_buffer.name == value
if isinstance(value, Buffer):
return self.current_buffer == value
if isinstance(value, UIControl):
return self.current_control == value
else:
value = to_container(value)
if isinstance(value, Window):
return self.current_window == value
else:
# Check whether this "container" is focused. This is true if
# one of the elements inside is focused.
for element in walk(value):
if element == self.current_window:
return True
return False
示例5: scroll_down
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def scroll_down(event, window: Optional[Window] = None, buffer: Optional[Buffer] = None):
w = window or event.app.layout.current_window
b = buffer or event.app.current_buffer
if w and w.render_info:
info = w.render_info
ui_content = info.ui_content
# Height to scroll.
scroll_height = info.window_height // 2
# Calculate how many lines is equivalent to that vertical space.
y = b.document.cursor_position_row + 1
height = 0
while y < ui_content.line_count:
line_height = info.get_height_for_line(y)
if height + line_height < scroll_height:
height += line_height
y += 1
else:
break
b.cursor_position = b.document.translate_row_col_to_index(y, 0)
示例6: scroll_up
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def scroll_up(event, window: Optional[Window] = None, buffer: Optional[Buffer] = None):
w = window or event.app.layout.current_window
b = buffer or event.app.current_buffer
if w and w.render_info:
info = w.render_info
# Height to scroll.
scroll_height = info.window_height // 2
# Calculate how many lines is equivalent to that vertical space.
y = max(0, b.document.cursor_position_row - 1)
height = 0
while y > 0:
line_height = info.get_height_for_line(y)
if height + line_height < scroll_height:
height += line_height
y -= 1
else:
break
b.cursor_position = b.document.translate_row_col_to_index(y, 0)
示例7: _accept_handler
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def _accept_handler(self, buff: Buffer) -> bool:
app = get_app()
app.exit(result=buff.text)
app.pre_run_callables.append(buff.reset)
return True # Keep text, we call 'reset' later on.
示例8: test_bindings
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def test_bindings(self):
kb = KeyBindings()
bind_keys(Buffer(), kb)
self.assertTrue('on_backspace' in handlers_for_key(kb, Keys.Backspace))
self.assertTrue('on_tab' in handlers_for_key(kb, Keys.Tab))
示例9: create_application
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def create_application(self, full_layout=True):
""" makes the application object and the buffers """
if full_layout:
layout = create_layout(self.lexer, ExampleLexer, ToolbarLexer)
else:
layout = create_tutorial_layout(self.lexer)
buffers = {
DEFAULT_BUFFER: Buffer(is_multiline=True),
'description': Buffer(is_multiline=True, read_only=True),
'parameter' : Buffer(is_multiline=True, read_only=True),
'examples' : Buffer(is_multiline=True, read_only=True),
'bottom_toolbar' : Buffer(is_multiline=True),
'example_line' : Buffer(is_multiline=True),
'default_values' : Buffer(),
'symbols' : Buffer()
}
writing_buffer = Buffer(
history=self.history,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True,
completer=self.completer,
complete_while_typing=Always()
)
return Application(
mouse_support=False,
style=self.styles,
buffer=writing_buffer,
on_input_timeout=self.on_input_timeout,
key_bindings_registry=registry,
layout=layout,
buffers=buffers,
)
示例10: current_buffer
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def current_buffer(self) -> Buffer:
"""
The currently focused :class:`~.Buffer`.
(This returns a dummy :class:`.Buffer` when none of the actual buffers
has the focus. In this case, it's really not practical to check for
`None` values or catch exceptions every time.)
"""
return self.layout.current_buffer or Buffer(
name="dummy-buffer"
) # Dummy buffer.
示例11: current_buffer
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def current_buffer(self) -> "Buffer":
"""
The current buffer.
"""
return self.app.current_buffer
示例12: get_line_numbers
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def get_line_numbers(self, buffer: Buffer) -> Tuple[int, int]:
"""
Return a (start_line, end_line) pair.
"""
# Get absolute cursor positions from the text object.
from_, to = self.operator_range(buffer.document)
from_ += buffer.cursor_position
to += buffer.cursor_position
# Take the start of the lines.
from_, _ = buffer.document.translate_index_to_position(from_)
to, _ = buffer.document.translate_index_to_position(to)
return from_, to
示例13: cut
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def cut(self, buffer: Buffer) -> Tuple[Document, ClipboardData]:
"""
Turn text object into `ClipboardData` instance.
"""
from_, to = self.operator_range(buffer.document)
from_ += buffer.cursor_position
to += buffer.cursor_position
# For Vi mode, the SelectionState does include the upper position,
# while `self.operator_range` does not. So, go one to the left, unless
# we're in the line mode, then we don't want to risk going to the
# previous line, and missing one line in the selection.
if self.type != TextObjectType.LINEWISE:
to -= 1
document = Document(
buffer.text,
to,
SelectionState(original_cursor_position=from_, type=self.selection_type),
)
new_document, clipboard_data = document.cut_selection()
return new_document, clipboard_data
# Typevar for any text object function:
示例14: text
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def text(self) -> str:
"""
The `Buffer` text.
"""
return self.buffer.text
示例15: __init__
# 需要导入模块: from prompt_toolkit import buffer [as 别名]
# 或者: from prompt_toolkit.buffer import Buffer [as 别名]
def __init__(
self,
prompt: AnyFormattedText = "Shell command: ",
enable_global_bindings: FilterOrBool = True,
) -> None:
self.prompt = prompt
self.enable_global_bindings = to_filter(enable_global_bindings)
self.system_buffer = Buffer(name=SYSTEM_BUFFER)
self._bindings = self._build_key_bindings()
self.buffer_control = BufferControl(
buffer=self.system_buffer,
lexer=SimpleLexer(style="class:system-toolbar.text"),
input_processors=[
BeforeInput(lambda: self.prompt, style="class:system-toolbar")
],
key_bindings=self._bindings,
)
self.window = Window(
self.buffer_control, height=1, style="class:system-toolbar"
)
self.container = ConditionalContainer(
content=self.window, filter=has_focus(self.system_buffer)
)