[IPython-user] Prompt

Tom Locke tom at livelogix.com
Wed Mar 9 20:35:51 CST 2005

Ville Vainio wrote:

>On Tue, 2005-03-08 at 17:29 +0100, Frédéric Mantegazza wrote:
>>I would like to know if it is possible to dynamically modify the prompt ? I 
>>tried to modified __IP.rc.prompt_in1, and __IP.shell.rc.prompt_in1, but it 
>>does not work...
I did this for Logix. I don't know if there's a better way, but my 
solution was a real mess. Works though :-)

The messy bit was hacking in a modified raw_input so the code below gets 
called at the right time. That might have been specific to my problem.

Here's a snippet, I'm setting the prompt to "[foo]" where foo is the 
current language name:

    prompt = '[%s]:' % langname
    # The same plus color info
    cprompt = '[${self.col_num}%s${self.col_p}]:' % langname
    p = IPython.Prompts.Prompt1(_ipy.outputcache, prompt=cprompt)
    p.p_str_nocolor = prompt
    _ipy.outputcache.prompt1 = p

(where _ipy is the IPython app object __IP)


More information about the IPython-user mailing list