Ask Your Question
3

How can I change the sage console prompt?

asked 2018-06-30 09:27:27 +0200

sageuser1732 gravatar image

updated 2018-07-01 15:26:59 +0200

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.

edit retag flag offensive close merge delete

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 ( 2018-07-01 03:42:10 +0200 )edit
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 ( 2018-07-02 16:51:29 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2018-06-30 13:30:00 +0200

tmonteil gravatar image

updated 2018-07-02 13:15:41 +0200

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...

edit flag offensive delete link more

Comments

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

sageuser1732 gravatar imagesageuser1732 ( 2018-06-30 18:20:30 +0200 )edit

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: 2018-06-30 09:17:26 +0200

Seen: 1,218 times

Last updated: Jul 02 '18