本文整理汇总了Python中prompt_toolkit.buffer.Buffer.set_document方法的典型用法代码示例。如果您正苦于以下问题:Python Buffer.set_document方法的具体用法?Python Buffer.set_document怎么用?Python Buffer.set_document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.set_document方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_undo_capitalize
# 需要导入模块: from prompt_toolkit.buffer import Buffer [as 别名]
# 或者: from prompt_toolkit.buffer.Buffer import set_document [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)
示例2: Pane
# 需要导入模块: from prompt_toolkit.buffer import Buffer [as 别名]
# 或者: from prompt_toolkit.buffer.Buffer import set_document [as 别名]
class Pane(object):
"""
One pane, containing one process and a search buffer for going into copy
mode or displaying the help.
"""
_pane_counter = 1000 # Start at 1000, to be sure to not confuse this with pane indexes.
def __init__(self, process):
assert isinstance(process, Process)
self.process = process
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
# copy_token_list, that contains a token list with color information.
self.scroll_buffer = Buffer(read_only=True)
self.copy_token_list = []
self.display_scroll_buffer = False
self.scroll_buffer_title = ''
# Search buffer, for use in copy mode. (Each pane gets its own search buffer.)
self.search_buffer = Buffer()
self.is_searching = False
self.search_state = SearchState(ignore_case=False)
@property
def name(self):
"""
The name for the window as displayed in the title bar and status bar.
"""
# Name, explicitely set for the pane.
if self.chosen_name:
return self.chosen_name
else:
# Name from the process running inside the pane.
name = self.process.get_name()
if name:
return os.path.basename(name)
return ''
def enter_copy_mode(self):
"""
Suspend the process, and copy the screen content to the `scroll_buffer`.
That way the user can search through the history and copy/paste.
"""
document, token_list = self.process.create_copy_document()
self._enter_scroll_buffer('Copy', document, token_list)
def display_text(self, text, title=''):
"""
Display the given text in the scroll buffer.
"""
self._enter_scroll_buffer(
title,
document=Document(text, 0),
token_list=[(Token, text)])
def _enter_scroll_buffer(self, title, document, token_list):
# Suspend child process.
self.process.suspend()
self.scroll_buffer.set_document(document, bypass_readonly=True)
self.copy_token_list = token_list
self.display_scroll_buffer = True
self.scroll_buffer_title = title
# Reset search state.
self.search_state = SearchState(ignore_case=False)
def exit_scroll_buffer(self):
"""
Exit scroll buffer. (Exits help or copy mode.)
"""
self.process.resume()
self.display_scroll_buffer = False
示例3: test_capitalize
# 需要导入模块: from prompt_toolkit.buffer import Buffer [as 别名]
# 或者: from prompt_toolkit.buffer.Buffer import set_document [as 别名]
def test_capitalize(self):
buffer = Buffer()
text = 'selec'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('selec', buffer.text)
text = 'select'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('SELECT', buffer.text)
text = 'CREATE TABLE "select'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('CREATE TABLE "select', buffer.text)
text = 'CREATE TABLE \'select\''
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('CREATE TABLE \'select\'', buffer.text)
text = 'create table test (x int)'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('CREATE TABLE test (x INT)', buffer.text)
text = 'create table test (a boolean, b string, c integer)'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('CREATE TABLE test (a BOOLEAN, b STRING, c INTEGER)', buffer.text)
text = 'create table test\n(a boolean, b string, c integer)'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('CREATE TABLE test\n(a BOOLEAN, b STRING, c INTEGER)', buffer.text)
text = '\\select dynamic'
buffer.set_document(Document(text, len(text)))
self.capitalizer.apply_capitalization(buffer)
self.assertEqual('\\select dynamic', buffer.text)
示例4: TextArea
# 需要导入模块: from prompt_toolkit.buffer import Buffer [as 别名]
# 或者: from prompt_toolkit.buffer.Buffer import set_document [as 别名]
#.........这里部分代码省略.........
# Writeable attributes.
self.completer = completer
self.complete_while_typing = complete_while_typing
self.lexer = lexer
self.auto_suggest = auto_suggest
self.read_only = read_only
self.wrap_lines = wrap_lines
self.buffer = Buffer(
document=Document(text, 0),
multiline=multiline,
read_only=Condition(lambda: is_true(self.read_only)),
completer=DynamicCompleter(lambda: self.completer),
complete_while_typing=Condition(
lambda: is_true(self.complete_while_typing)),
auto_suggest=DynamicAutoSuggest(lambda: self.auto_suggest),
accept_handler=accept_handler,
history=history)
self.control = BufferControl(
buffer=self.buffer,
lexer=DynamicLexer(lambda: self.lexer),
input_processors=[
ConditionalProcessor(
AppendAutoSuggestion(),
has_focus(self.buffer) & is_done), #
ConditionalProcessor(
processor=PasswordProcessor(),
filter=to_filter(password)
),
BeforeInput(prompt, style='class:text-area.prompt'),
] + input_processors,
search_buffer_control=search_control,
preview_search=preview_search,
focusable=focusable,
focus_on_click=focus_on_click)
if multiline:
if scrollbar:
right_margins = [ScrollbarMargin(display_arrows=True)]
else:
right_margins = []
if line_numbers:
left_margins = [NumberedMargin()]
else:
left_margins = []
else:
height = D.exact(1)
left_margins = []
right_margins = []
style = 'class:text-area ' + style
self.window = Window(
height=height,
width=width,
dont_extend_height=dont_extend_height,
dont_extend_width=dont_extend_width,
content=self.control,
style=style,
wrap_lines=Condition(lambda: is_true(self.wrap_lines)),
left_margins=left_margins,
right_margins=right_margins,
get_line_prefix=get_line_prefix)
@property
def text(self):
"""
The `Buffer` text.
"""
return self.buffer.text
@text.setter
def text(self, value):
self.buffer.set_document(Document(value, 0), bypass_readonly=True)
@property
def document(self):
"""
The `Buffer` document (text + cursor position).
"""
return self.buffer.document
@document.setter
def document(self, value):
self.buffer.document = value
@property
def accept_handler(self):
"""
The accept handler. Called when the user accepts the input.
"""
return self.buffer.accept_handler
@accept_handler.setter
def accept_handler(self, value):
self.buffer.accept_handler = value
def __pt_container__(self):
return self.window