本文整理汇总了Python中pygments.token.Token.Prompt方法的典型用法代码示例。如果您正苦于以下问题:Python Token.Prompt方法的具体用法?Python Token.Prompt怎么用?Python Token.Prompt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.token.Token
的用法示例。
在下文中一共展示了Token.Prompt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: in_prompt_tokens
# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Prompt [as 别名]
def in_prompt_tokens(self, cli=None):
session = self.shell.user_module.session
style = session.GetParameter("highlighting_style")
old_style = self.shell.highlighting_style
if style != old_style:
try:
self.shell.highlighting_style = style
except Exception:
self.shell.highlighting_style = old_style
session.logging.error(
"Style %s not valid. Valid styles are %s" %
(style, list(styles.get_all_styles())))
return [
(Token.Prompt, "["),
(Token.Name.Variable, str(session.session_id)),
(Token.Prompt, "] "),
(Token.Name.Class, str(session.session_name)),
(Token.Prompt, " "),
(Token.Comment, time.strftime("%H:%M:%S")),
(Token.Prompt, "> "),
]
示例2: get_tokens
# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Prompt [as 别名]
def get_tokens(x):
return [(Token.Prompt, "> ")]
示例3: configure_ipython_prompt
# 需要导入模块: from pygments.token import Token [as 别名]
# 或者: from pygments.token.Token import Prompt [as 别名]
def configure_ipython_prompt(
config, prompt: typing.Optional[str] = None, output: typing.Optional[str] = None
) -> None:
import IPython
if IPython.version_info[0] >= 5: # Custom prompt API changed in IPython 5.0
from pygments.token import Token
# https://ipython.readthedocs.io/en/stable/config/details.html#custom-prompts # noqa: B950
class CustomPrompt(IPython.terminal.prompts.Prompts):
def in_prompt_tokens(self, *args, **kwargs):
if prompt is None:
return super().in_prompt_tokens(*args, **kwargs)
if isinstance(prompt, (str, bytes)):
return [(Token.Prompt, prompt)]
else:
return prompt
def out_prompt_tokens(self, *args, **kwargs):
if output is None:
return super().out_prompt_tokens(*args, **kwargs)
if isinstance(output, (str, bytes)):
return [(Token.OutPrompt, output)]
else:
return prompt
config.TerminalInteractiveShell.prompts_class = CustomPrompt
else:
prompt_config = config.PromptManager
if prompt:
prompt_config.in_template = prompt
if output:
prompt_config.out_template = output
return None