diff --git a/IPython/Prompts.py b/IPython/Prompts.py index c0f2610..7cf62b1 100644 --- a/IPython/Prompts.py +++ b/IPython/Prompts.py @@ -2,7 +2,7 @@ """ Classes for handling input/output prompts. -$Id: Prompts.py 1850 2006-10-28 19:48:13Z fptest $""" +$Id: Prompts.py 2192 2007-04-01 20:51:06Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez @@ -124,56 +124,59 @@ ROOT_SYMBOL = "$#"[os.name=='nt' or os.getuid()==0] prompt_specials_color = { # Prompt/history count '%n' : '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}', - '\\#': '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}', + r'\#': '${self.col_num}' '${self.cache.prompt_count}' '${self.col_p}', + # Just the prompt counter number, WITHOUT any coloring wrappers, so users + # can get numbers displayed in whatever color they want. + r'\N': '${self.cache.prompt_count}', # Prompt/history count, with the actual digits replaced by dots. Used # mainly in continuation prompts (prompt_in2) - '\\D': '${"."*len(str(self.cache.prompt_count))}', + r'\D': '${"."*len(str(self.cache.prompt_count))}', # Current working directory - '\\w': '${os.getcwd()}', + r'\w': '${os.getcwd()}', # Current time - '\\t' : '${time.strftime("%H:%M:%S")}', + r'\t' : '${time.strftime("%H:%M:%S")}', # Basename of current working directory. # (use os.sep to make this portable across OSes) - '\\W' : '${os.getcwd().split("%s")[-1]}' % os.sep, + r'\W' : '${os.getcwd().split("%s")[-1]}' % os.sep, # These X are an extension to the normal bash prompts. They return # N terms of the path, after replacing $HOME with '~' - '\\X0': '${os.getcwd().replace("%s","~")}' % HOME, - '\\X1': '${self.cwd_filt(1)}', - '\\X2': '${self.cwd_filt(2)}', - '\\X3': '${self.cwd_filt(3)}', - '\\X4': '${self.cwd_filt(4)}', - '\\X5': '${self.cwd_filt(5)}', + r'\X0': '${os.getcwd().replace("%s","~")}' % HOME, + r'\X1': '${self.cwd_filt(1)}', + r'\X2': '${self.cwd_filt(2)}', + r'\X3': '${self.cwd_filt(3)}', + r'\X4': '${self.cwd_filt(4)}', + r'\X5': '${self.cwd_filt(5)}', # Y are similar to X, but they show '~' if it's the directory # N+1 in the list. Somewhat like %cN in tcsh. - '\\Y0': '${self.cwd_filt2(0)}', - '\\Y1': '${self.cwd_filt2(1)}', - '\\Y2': '${self.cwd_filt2(2)}', - '\\Y3': '${self.cwd_filt2(3)}', - '\\Y4': '${self.cwd_filt2(4)}', - '\\Y5': '${self.cwd_filt2(5)}', + r'\Y0': '${self.cwd_filt2(0)}', + r'\Y1': '${self.cwd_filt2(1)}', + r'\Y2': '${self.cwd_filt2(2)}', + r'\Y3': '${self.cwd_filt2(3)}', + r'\Y4': '${self.cwd_filt2(4)}', + r'\Y5': '${self.cwd_filt2(5)}', # Hostname up to first . - '\\h': HOSTNAME_SHORT, + r'\h': HOSTNAME_SHORT, # Full hostname - '\\H': HOSTNAME, + r'\H': HOSTNAME, # Username of current user - '\\u': USER, + r'\u': USER, # Escaped '\' '\\\\': '\\', # Newline - '\\n': '\n', + r'\n': '\n', # Carriage return - '\\r': '\r', + r'\r': '\r', # Release version - '\\v': __version__, + r'\v': __version__, # Root symbol ($ or #) - '\\$': ROOT_SYMBOL, + r'\$': ROOT_SYMBOL, } # A copy of the prompt_specials dictionary but with all color escapes removed, # so we can correctly compute the prompt length for the auto_rewrite method. prompt_specials_nocolor = prompt_specials_color.copy() prompt_specials_nocolor['%n'] = '${self.cache.prompt_count}' -prompt_specials_nocolor['\\#'] = '${self.cache.prompt_count}' +prompt_specials_nocolor[r'\#'] = '${self.cache.prompt_count}' # Add in all the InputTermColors color escapes as valid prompt characters. # They all get added as \\C_COLORNAME, so that we don't have any conflicts @@ -183,7 +186,7 @@ prompt_specials_nocolor['\\#'] = '${self.cache.prompt_count}' input_colors = ColorANSI.InputTermColors for _color in dir(input_colors): if _color[0] != '_': - c_name = '\\C_'+_color + c_name = r'\C_'+_color prompt_specials_color[c_name] = getattr(input_colors,_color) prompt_specials_nocolor[c_name] = '' @@ -422,8 +425,12 @@ class CachedOutput: # Set input prompt strings and colors if cache_size == 0: - if ps1.find('%n') > -1 or ps1.find('\\#') > -1: ps1 = '>>> ' - if ps2.find('%n') > -1 or ps2.find('\\#') > -1: ps2 = '... ' + if ps1.find('%n') > -1 or ps1.find(r'\#') > -1 \ + or ps1.find(r'\N') > -1: + ps1 = '>>> ' + if ps2.find('%n') > -1 or ps2.find(r'\#') > -1 \ + or ps2.find(r'\N') > -1: + ps2 = '... ' self.ps1_str = self._set_prompt_str(ps1,'In [\\#]: ','>>> ') self.ps2_str = self._set_prompt_str(ps2,' .\\D.: ','... ') self.ps_out_str = self._set_prompt_str(ps_out,'Out[\\#]: ','') diff --git a/IPython/Release.py b/IPython/Release.py index b05229a..58c1fbd 100644 --- a/IPython/Release.py +++ b/IPython/Release.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Release data for the IPython project. -$Id: Release.py 2160 2007-03-19 05:40:59Z fperez $""" +$Id: Release.py 2192 2007-04-01 20:51:06Z fperez $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez @@ -22,7 +22,7 @@ name = 'ipython' # because bdist_rpm does not accept dashes (an RPM) convention, and # bdist_deb does not accept underscores (a Debian convention). -revision = '2159' +revision = '2191' #version = '0.7.3' diff --git a/doc/ChangeLog b/doc/ChangeLog index ed497b2..c88159f 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,10 @@ +2007-04-01 Fernando Perez + + * IPython/Prompts.py (prompt_specials_color): Add \N for the + actual prompt number, without any coloring. This allows users to + produce numbered prompts with their own colors. Added after a + report/request by Thorsten Kampe . + 2007-03-31 Walter Doerwald * IPython/Extensions/igrid.py: Map the return key diff --git a/doc/manual_base.lyx b/doc/manual_base.lyx index b0c1b0b..60536ca 100644 --- a/doc/manual_base.lyx +++ b/doc/manual_base.lyx @@ -6372,7 +6372,17 @@ bash \begin_layout Description \backslash -# the prompt/history count number +# the prompt/history count number. + This escape is automatically wrapped in the coloring codes for the currently + active color scheme. +\end_layout + +\begin_layout Description + +\backslash +N the 'naked' prompt/history count number: this is just the number itself, + without any coloring applied to it. + This lets you produce numbered prompts with your own colors. \end_layout \begin_layout Description @@ -6699,7 +6709,7 @@ fperez ] \color green 1> -\color default +\color none 1+2 \newline @@ -6734,7 +6744,7 @@ hspace*{0mm} \color red <1> -\color default +\color none 3 \newline @@ -6748,7 +6758,7 @@ fperez ] \color green 2> -\color default +\color none for i in (1,2,3): \newline @@ -6782,7 +6792,7 @@ hspace*{0mm} \color green ...> -\color default +\color none \InsetSpace ~ \InsetSpace ~ \InsetSpace ~ @@ -6820,7 +6830,7 @@ hspace*{0mm} \color green ...> -\color default +\color none \newline 1 2 3