本文整理匯總了Python中prompt_toolkit.enums.DEFAULT_BUFFER屬性的典型用法代碼示例。如果您正苦於以下問題:Python enums.DEFAULT_BUFFER屬性的具體用法?Python enums.DEFAULT_BUFFER怎麽用?Python enums.DEFAULT_BUFFER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類prompt_toolkit.enums
的用法示例。
在下文中一共展示了enums.DEFAULT_BUFFER屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_buffer
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_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: create_buffer
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def create_buffer(cmd, history_file):
def accept(buff):
get_app().exit(result=buff.document.text)
return True
history = TruncatedFileHistory(history_file, max_length=MAX_HISTORY_LENGTH)
completer = SQLCompleter(cmd)
buffer = CrashBuffer(
name=DEFAULT_BUFFER,
history=history,
completer=completer,
enable_history_search=True,
accept_handler=accept,
on_text_insert=Capitalizer(cmd, completer).apply_capitalization,
tempfile_suffix=lambda: '.sql'
)
buffer.complete_while_typing = lambda cli=None: cmd.should_autocomplete()
return buffer
示例3: load_abort_and_exit_bindings
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def load_abort_and_exit_bindings():
"""
Basic bindings for abort (Ctrl-C) and exit (Ctrl-D).
"""
registry = Registry()
handle = registry.add_binding
@handle(Keys.ControlC)
def _(event):
" Abort when Control-C has been pressed. "
event.cli.abort()
@Condition
def ctrl_d_condition(cli):
""" Ctrl-D binding is only active when the default buffer is selected
and empty. """
return (cli.current_buffer_name == DEFAULT_BUFFER and
not cli.current_buffer.text)
handle(Keys.ControlD, filter=ctrl_d_condition)(get_by_name('end-of-file'))
return registry
示例4: buffer_should_be_handled
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def buffer_should_be_handled(pgcli):
@Condition
def cond():
if not pgcli.multi_line:
_logger.debug("Not in multi-line mode. Handle the buffer.")
return True
if pgcli.multiline_mode == "safe":
_logger.debug("Multi-line mode is set to 'safe'. Do NOT handle the buffer.")
return False
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
text = doc.text.strip()
return (
text.startswith("\\") # Special Command
or text.endswith(r"\e") # Special Command
or text.endswith(r"\G") # Ended with \e which should launch the editor
or _is_complete(text) # A complete SQL command
or (text == "exit") # Exit doesn't need semi-colon
or (text == "quit") # Quit doesn't need semi-colon
or (text == ":q") # To all the vim fans out there
or (text == "") # Just a plain enter without any text
)
return cond
示例5: is_multiline
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def is_multiline() -> bool:
doc = pt_app.get_app().layout.get_buffer_by_name(
pt_enums.DEFAULT_BUFFER).document
if (doc.cursor_position and doc.text[doc.cursor_position:].strip()):
return True
return is_multiline_text(doc.text)
示例6: meta_enter_message
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def meta_enter_message(python_input: "PythonInput") -> Container:
"""
Create the `Layout` for the 'Meta+Enter` message.
"""
def get_text_fragments() -> StyleAndTextTuples:
return [("class:accept-message", " [Meta+Enter] Execute ")]
@Condition
def extra_condition() -> bool:
" Only show when... "
b = python_input.default_buffer
return (
python_input.show_meta_enter_message
and (
not b.document.is_cursor_at_the_end
or python_input.accept_input_on_enter is None
)
and "\n" in b.text
)
visible = ~is_done & has_focus(DEFAULT_BUFFER) & extra_condition
return ConditionalContainer(
content=Window(FormattedTextControl(get_text_fragments)), filter=visible
)
示例7: cli_is_multiline
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def cli_is_multiline(cli):
@Condition
def cond():
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
if not cli.multi_line:
return False
else:
return not _multiline_exception(doc.text)
return cond
示例8: cli_is_multiline
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def cli_is_multiline(cli):
@Condition
def cond():
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
if not cli.multi_line:
return False
else:
return not _multiline_exception(doc.text)
return cond
示例9: create_application
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_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: example_repl
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def example_repl(self, text, example, start_index, continue_flag):
""" REPL for interactive tutorials """
if start_index:
start_index = start_index + 1
cmd = ' '.join(text.split()[:start_index])
example_cli = CommandLineInterface(
application=self.create_application(
full_layout=False),
eventloop=create_eventloop())
example_cli.buffers['example_line'].reset(
initial_document=Document(u'{}\n'.format(
add_random_new_lines(example)))
)
while start_index < len(text.split()):
if self.default_command:
cmd = cmd.replace(self.default_command + ' ', '')
example_cli.buffers[DEFAULT_BUFFER].reset(
initial_document=Document(
u'{}'.format(cmd),
cursor_position=len(cmd)))
example_cli.request_redraw()
answer = example_cli.run()
if not answer:
return "", True
answer = answer.text
if answer.strip('\n') == cmd.strip('\n'):
continue
else:
if len(answer.split()) > 1:
start_index += 1
cmd += " " + answer.split()[-1] + " " +\
u' '.join(text.split()[start_index:start_index + 1])
example_cli.exit()
del example_cli
else:
cmd = text
return cmd, continue_flag
# pylint: disable=too-many-branches
示例11: create_tutorial_layout
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [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
示例12: _create_default_buffer
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def _create_default_buffer(self) -> Buffer:
"""
Create and return the default input buffer.
"""
dyncond = self._dyncond
# Create buffers list.
def accept(buff: Buffer) -> bool:
""" Accept the content of the default buffer. This is called when
the validation succeeds. """
cast(Application[str], get_app()).exit(result=buff.document.text)
return True # Keep text, we call 'reset' later on.
return Buffer(
name=DEFAULT_BUFFER,
# Make sure that complete_while_typing is disabled when
# enable_history_search is enabled. (First convert to Filter,
# to avoid doing bitwise operations on bool objects.)
complete_while_typing=Condition(
lambda: is_true(self.complete_while_typing)
and not is_true(self.enable_history_search)
and not self.complete_style == CompleteStyle.READLINE_LIKE
),
validate_while_typing=dyncond("validate_while_typing"),
enable_history_search=dyncond("enable_history_search"),
validator=DynamicValidator(lambda: self.validator),
completer=DynamicCompleter(
lambda: ThreadedCompleter(self.completer)
if self.complete_in_thread and self.completer
else self.completer
),
history=self.history,
auto_suggest=DynamicAutoSuggest(lambda: self.auto_suggest),
accept_handler=accept,
tempfile_suffix=lambda: to_str(self.tempfile_suffix or ""),
tempfile=lambda: to_str(self.tempfile or ""),
)
示例13: mssql_is_multiline
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def mssql_is_multiline(mssql_cli):
@Condition
def cond():
doc = get_app().layout.get_buffer_by_name(DEFAULT_BUFFER).document
if not mssql_cli.multiline:
return False
if mssql_cli.multiline_mode == 'safe':
return True
return not _multiline_exception(doc.text)
return cond
示例14: _handle_command
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def _handle_command(self, command):
"""
Handle command. This will run in a separate thread, in order not
to block the event loop.
"""
logger.info('Handle command %r', command)
def in_executor():
self.handling_command = True
try:
if self.callback is not None:
self.callback(self, command)
finally:
self.server.call_from_executor(done)
def done():
self.handling_command = False
# Reset state and draw again. (If the connection is still open --
# the application could have called TelnetConnection.close()
if not self.closed:
self.cli.reset()
self.cli.buffers[DEFAULT_BUFFER].reset()
self.cli.renderer.request_absolute_cursor_position()
self.vt100_output.flush()
self.cli._redraw()
self.server.run_in_executor(in_executor)
示例15: __init__
# 需要導入模塊: from prompt_toolkit import enums [as 別名]
# 或者: from prompt_toolkit.enums import DEFAULT_BUFFER [as 別名]
def __init__(self,
buffer_name=DEFAULT_BUFFER,
input_processors=None,
lexer=None,
preview_search=False,
search_buffer_name=SEARCH_BUFFER,
get_search_state=None,
menu_position=None,
default_char=None,
focus_on_click=False):
assert input_processors is None or all(isinstance(i, Processor) for i in input_processors)
assert menu_position is None or callable(menu_position)
assert lexer is None or isinstance(lexer, Lexer)
assert get_search_state is None or callable(get_search_state)
assert default_char is None or isinstance(default_char, Char)
self.preview_search = to_cli_filter(preview_search)
self.get_search_state = get_search_state
self.focus_on_click = to_cli_filter(focus_on_click)
self.input_processors = input_processors or []
self.buffer_name = buffer_name
self.menu_position = menu_position
self.lexer = lexer or SimpleLexer()
self.default_char = default_char or Char(token=Token.Transparent)
self.search_buffer_name = search_buffer_name
#: Cache for the lexer.
#: Often, due to cursor movement, undo/redo and window resizing
#: operations, it happens that a short time, the same document has to be
#: lexed. This is a faily easy way to cache such an expensive operation.
self._token_cache = SimpleCache(maxsize=8)
self._xy_to_cursor_position = None
self._last_click_timestamp = None
self._last_get_processed_line = None