本文整理匯總了Python中prompt_toolkit.token.Token.SearchMatch方法的典型用法代碼示例。如果您正苦於以下問題:Python Token.SearchMatch方法的具體用法?Python Token.SearchMatch怎麽用?Python Token.SearchMatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類prompt_toolkit.token.Token
的用法示例。
在下文中一共展示了Token.SearchMatch方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: apply_transformation
# 需要導入模塊: from prompt_toolkit.token import Token [as 別名]
# 或者: from prompt_toolkit.token.Token import SearchMatch [as 別名]
def apply_transformation(self, cli, document, lineno, source_to_display, tokens):
search_text = self._get_search_text(cli)
searchmatch_current_token = (':', ) + Token.SearchMatch.Current
searchmatch_token = (':', ) + Token.SearchMatch
if search_text and not cli.is_returning:
# For each search match, replace the Token.
line_text = token_list_to_text(tokens)
tokens = explode_tokens(tokens)
flags = re.IGNORECASE if cli.is_ignoring_case else 0
# Get cursor column.
if document.cursor_position_row == lineno:
cursor_column = source_to_display(document.cursor_position_col)
else:
cursor_column = None
for match in re.finditer(re.escape(search_text), line_text, flags=flags):
if cursor_column is not None:
on_cursor = match.start() <= cursor_column < match.end()
else:
on_cursor = False
for i in range(match.start(), match.end()):
old_token, text = tokens[i]
if on_cursor:
tokens[i] = (old_token + searchmatch_current_token, tokens[i][1])
else:
tokens[i] = (old_token + searchmatch_token, tokens[i][1])
return Transformation(tokens)