Ask Your Question
3

How can I change the sage console prompt?

asked 6 years ago

sageuser1732 gravatar image

updated 6 years ago

tmonteil gravatar image

How can I change the sage console prompt from 'sage: ' to '>>> ' ?

I'm running Sage 8.1 (binary install) in Windows 7.

I assume I need to edit a configuration file, or perhaps it's controlled by an environmental variable.

If it's controlled by an environmental variable, which one, and what setting?

If it needs a configuration file edit, which file, where is the file located, and what edit is needed?

Thanks in advance.

Preview: (hide)

Comments

If relevant to anyone with a dark background in their terminal wanting to change the color in the prompt, an option is to go to colors under src/sage/repl/prompts.py. Possible values to return are any of [u'Neutral', u'NoColor', u'LightBG', u'Linux'].

fidbc gravatar imagefidbc ( 6 years ago )
1

@fidbc, or after starting Sage, just type one of %colors LightBG, %colors Linux, %colors Neutral, %colors NoColor. Or you could put such a line in a file called init.sage inside the .sage folder in your home directory.

slelievre gravatar imageslelievre ( 6 years ago )

1 Answer

Sort by » oldest newest most voted
4

answered 6 years ago

tmonteil gravatar image

updated 6 years ago

The sage prompt is set in the file src/sage/repl/prompts.py, you can just modify the line 23 and rebuild (make buildfrom Sage root). See the file at https://git.sagemath.org/sage.git/tre...

Alternatively, within Sage console (or in your ~/.sage/init.sage file), you can type:

from IPython.terminal.prompts import ClassicPrompts
ip = get_ipython()
ip.prompts = ClassicPrompts(ip)

If you want to make your own custom prompt (not the Python classical one), you can do:

from IPython.terminal.prompts import Prompts, Token
class MyPrompt(Prompts):
    def in_prompt_tokens(self, cli=None):
        return [(Token.Prompt, 'hello: ')]
ip = get_ipython()
ip.prompts = MyPrompt(ip)

See the documentation at https://ipython.readthedocs.io/en/sta...

Preview: (hide)
link

Comments

Works perfectly! (I used the init.sage method.) Thank you very much!

sageuser1732 gravatar imagesageuser1732 ( 6 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 6 years ago

Seen: 1,332 times

Last updated: Jul 02 '18