本文整理匯總了Python中prompt_toolkit.token.Token.TrailingInput方法的典型用法代碼示例。如果您正苦於以下問題:Python Token.TrailingInput方法的具體用法?Python Token.TrailingInput怎麽用?Python Token.TrailingInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類prompt_toolkit.token.Token
的用法示例。
在下文中一共展示了Token.TrailingInput方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_tokens
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import TrailingInput [as 別名]
def _get_tokens(self, cli, text):
m = self.compiled_grammar.match_prefix(text)
if m:
characters = [[self.default_token, c] for c in text]
for v in m.variables():
# If we have a `Lexer` instance for this part of the input.
# Tokenize recursively and apply tokens.
lexer = self.lexers.get(v.varname)
if lexer:
document = Document(text[v.start:v.stop])
lexer_tokens_for_line = lexer.lex_document(cli, document)
lexer_tokens = []
for i in range(len(document.lines)):
lexer_tokens.extend(lexer_tokens_for_line(i))
lexer_tokens.append((Token, '\n'))
if lexer_tokens:
lexer_tokens.pop()
i = v.start
for t, s in lexer_tokens:
for c in s:
if characters[i][0] == self.default_token:
characters[i][0] = t
i += 1
# Highlight trailing input.
trailing_input = m.trailing_input()
if trailing_input:
for i in range(trailing_input.start, trailing_input.stop):
characters[i][0] = Token.TrailingInput
return characters
else:
return [(Token, text)]