如何更新 IPython 5.0 的 PromptManager 设置?

问题描述 投票:0回答:1

线条

# Output prompt. '\#' will be transformed to the prompt number
c.PromptManager.out_template = '{color.Green}Out[{count}]{color.Green} : {color.LightGray}'

# Continuation prompt.
c.PromptManager.in2_template = '{color.Yellow}   .\\D.{color.Green} : {color.LightGray}'

# If True (default), each prompt will be right-aligned with the preceding one.
c.PromptManager.justify = True

# Input prompt.  '\#' will be transformed to the prompt number
c.PromptManager.in_template = '{color.Green}In [{count}]{color.LightGreen} : {color.DarkGray}'

在我的

ipython_config.py
给予

usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py:440: UserWarning: As of IPython 5.0 `PromptManager` config will have no effect and has been replaced by TerminalInteractiveShell.prompts_class
  warn('As of IPython 5.0 `PromptManager` config will have no effect'

但将

PromptManager
替换为
TerminalInteractiveShell.prompts_class
没有效果。

如何更新 IPython 5.0 的

PromptManager
设置?

python-2.7 ipython settings
1个回答
0
投票

您需要创建一个包含成员的配置对象,如 iPython v5.x 文档中所述。 文档中给出的示例:

# sample ipython_config.py
c = get_config()

c.TerminalIPythonApp.display_banner = True
c.InteractiveShellApp.log_level = 20
c.InteractiveShellApp.extensions = [
    'myextension'
]
c.InteractiveShellApp.exec_lines = [
    'import numpy',
    'import scipy'
]
c.InteractiveShellApp.exec_files = [
    'mycode.py',
    'fancy.ipy'
]
c.InteractiveShell.autoindent = True
c.InteractiveShell.colors = 'LightBG'
c.InteractiveShell.confirm_exit = False
c.InteractiveShell.editor = 'nano'
c.InteractiveShell.xmode = 'Context'

c.PrefilterManager.multi_line_specials = True

c.AliasManager.user_aliases = [
 ('la', 'ls -al')
]

没有提及

prompt_manager
您的配置中的大部分内容涉及自定义提示,但关于 自定义提示 的部分确实准确地显示了如何执行您正在寻找的操作。

以下是未经测试的代码,因为我没有可以运行 Python 2.7 和 iPython 5 的系统:

from IPython.terminal.prompts import Prompts, Token
import os

class MyPrompt(Prompts):
     def in_prompt_tokens(self, cli=None):
         return [(Token, os.getcwd()),
                 (Token.Prompt, ' >>>')]
© www.soinside.com 2019 - 2024. All rights reserved.