Skip to content
This repository

PromptManager fixes #1078

Closed
wants to merge 1 commit into from

3 participants

Min RK Fernando Perez Thomas Kluyver
Min RK
Owner
  • InteractiveShell.prompt_foo traits show deprecation warning, and map to new PromptManager traits
  • PromptManager properly added to IPython App, so it will show up in config
  • add helpstrings to PromptManager traits.
  • Docs / embed references to Shell.prompt_foo also updated

Should close #1075

Min RK PromptManager fixes
* InteractiveShell.prompt_foo traits show deprecation warning, and map to new PromptManager traits
* PromptManager properly added to IPython App, so it will show up in config
* add helpstrings to PromptManager traits.
* Docs / embed references to Shell.prompt_foo also updated
38572c2
Fernando Perez
Owner

Code looks good, but before we close #1075, as Gokhan says, we're inserting weird space before the prompt with these other templates, I'm not sure why. I tried putting simply

c.PromptManager.in_template = r'>>> '
c.PromptManager.out_template = r''

but I get this output:

    >>> 3
        3

I haven't looked at the prompt display logic in ages, but there's something odd here...

Fernando Perez
Owner

Ah, never mind.. I see the issue with the justification. Thanks. But that makes me think something...

Fernando Perez
Owner

That this means the rewrite logic is a little flawed in @takluyver's rework, and I missed that. The rewrite prompt in the old code would be the one adjusting dynamically its length to that of the others, not the other way around. So users should be able to define prompts of any length they want, and the rewrite prompt will simply be '-------.... ---->' , as long as it needs to be to match the length of the prompt above it. I went to great lengths to make this work in the presence of ansi escapes.

It seems that now the rewrite prompt has a fixed length and the others ares simply justified to match it. That's definitely not the logic we want; it's ugly and it breaks the common case of people changing their prompts and getting that weird left-space.

I'm actually OK with the rewrite prompt not being a template at all, we're simply saying 'the line above got rewritten'. The rewrite prompt instead could be a simple boolean: if True, we rewrite with '---->' as long as it needs to be, if False we don't show any rewrite. There's no need for having a template there.

Sorry that I didn't realize this slipped in when reviewing #507; I was trying to flush so much code to get to the beta that I failed to see these issues. But we have time to fix them before release...

Thomas Kluyver takluyver commented on the diff December 01, 2011
docs/source/interactive/shell.txt
@@ -155,8 +155,8 @@ Prompt customization
155 155
 
156 156
 The sh profile uses the following prompt configurations::
157 157
 
158  
-    o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
159  
-    o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
  158
+    o.PromptManager.in_template= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
1
Thomas Kluyver Collaborator

These colour specifications won't work. See my changes to the pysh config in 00cffc4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Thomas Kluyver takluyver referenced this pull request December 01, 2011
Merged

Prompts #1083

Thomas Kluyver
Collaborator

Made PR #1083.

Min RK
Owner

superseded by #1083

Min RK minrk closed this December 01, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 30, 2011
Min RK PromptManager fixes
* InteractiveShell.prompt_foo traits show deprecation warning, and map to new PromptManager traits
* PromptManager properly added to IPython App, so it will show up in config
* add helpstrings to PromptManager traits.
* Docs / embed references to Shell.prompt_foo also updated
38572c2
This page is out of date. Refresh to see the latest.
35  IPython/core/interactiveshell.py
@@ -315,10 +315,37 @@ def _exiter_default(self):
315 315
         help="Save multi-line entries as one entry in readline history"
316 316
     )
317 317
 
318  
-    prompt_in1 = Unicode('In [\\#]: ', config=True)
319  
-    prompt_in2 = Unicode('   .\\D.: ', config=True)
320  
-    prompt_out = Unicode('Out[\\#]: ', config=True)
321  
-    prompts_pad_left = CBool(True, config=True)
  318
+    # deprecated prompt traits:
  319
+    
  320
+    prompt_in1 = Unicode('In [\\#]: ', config=True,
  321
+        help="Deprecated, use PromptManager.in_template")
  322
+    prompt_in2 = Unicode('   .\\D.: ', config=True,
  323
+        help="Deprecated, use PromptManager.in2_template")
  324
+    prompt_out = Unicode('Out[\\#]: ', config=True,
  325
+        help="Deprecated, use PromptManager.out_template")
  326
+    prompts_pad_left = CBool(True, config=True,
  327
+        help="Deprecated, use PromptManager.justify")
  328
+    
  329
+    def _prompt_trait_changed(self, name, old, new):
  330
+        table = {
  331
+            'prompt_in1' : 'in_template',
  332
+            'prompt_in2' : 'in2_template',
  333
+            'prompt_out' : 'out_template',
  334
+            'prompts_pad_left' : 'justify',
  335
+        }
  336
+        warn("InteractiveShell.{name} is deprecated, use PromptManager.{newname}\n".format(
  337
+                name=name, newname=table[name])
  338
+        )
  339
+        # protect against weird cases where self.config may not exist:
  340
+        if self.config is not None:
  341
+            # propagate to corresponding PromptManager trait
  342
+            setattr(self.config.PromptManager, table[name], new)
  343
+    
  344
+    _prompt_in1_changed = _prompt_trait_changed
  345
+    _prompt_in2_changed = _prompt_trait_changed
  346
+    _prompt_out_changed = _prompt_trait_changed
  347
+    _prompt_pad_left_changed = _prompt_trait_changed
  348
+    
322 349
     quiet = CBool(False, config=True)
323 350
 
324 351
     history_length = Integer(10000, config=True)
12  IPython/core/prompts.py
@@ -254,10 +254,14 @@ def _color_scheme_changed(self, name, new_value):
254 254
         """)
255 255
     def _lazy_evaluate_fields_default(self): return lazily_evaluate.copy()
256 256
     
257  
-    in_template = Unicode('In [\\#]: ', config=True)
258  
-    in2_template = Unicode('   .\\D.: ', config=True)
259  
-    out_template = Unicode('Out[\\#]: ', config=True)
260  
-    rewrite_template = Unicode("------> ", config=True)
  257
+    in_template = Unicode('In [\\#]: ', config=True,
  258
+        help="Input prompt.  '\\#' will be transformed to the prompt number")
  259
+    in2_template = Unicode('   .\\D.: ', config=True,
  260
+        help="Continuation prompt.")
  261
+    out_template = Unicode('Out[\\#]: ', config=True,
  262
+        help="Output prompt. '\\#' will be transformed to the prompt number")
  263
+    rewrite_template = Unicode("------> ", config=True,
  264
+        help="Rewrite prompt. When inputs are transformed, the rewritten input will follow this.")
261 265
     
262 266
     justify = Bool(True, config=True, help="""
263 267
         If True (default), each prompt will be right-aligned with the
8  IPython/frontend/terminal/ipapp.py
@@ -38,6 +38,7 @@
38 38
 from IPython.core.completer import IPCompleter
39 39
 from IPython.core.crashhandler import CrashHandler
40 40
 from IPython.core.formatters import PlainTextFormatter
  41
+from IPython.core.prompts import PromptManager
41 42
 from IPython.core.application import (
42 43
     ProfileDir, BaseIPythonApplication, base_flags, base_aliases
43 44
 )
@@ -133,9 +134,9 @@ def make_report(self,traceback):
133 134
 classic_config = Config()
134 135
 classic_config.InteractiveShell.cache_size = 0
135 136
 classic_config.PlainTextFormatter.pprint = False
136  
-classic_config.InteractiveShell.prompt_in1 = '>>> '
137  
-classic_config.InteractiveShell.prompt_in2 = '... '
138  
-classic_config.InteractiveShell.prompt_out = ''
  137
+classic_config.PromptManager.in_template = '>>> '
  138
+classic_config.PromptManager.in2_template = '... '
  139
+classic_config.PromptManager.out_template = ''
139 140
 classic_config.InteractiveShell.separate_in = ''
140 141
 classic_config.InteractiveShell.separate_out = ''
141 142
 classic_config.InteractiveShell.separate_out2 = ''
@@ -197,6 +198,7 @@ def _classes_default(self):
197 198
             InteractiveShellApp, # ShellApp comes before TerminalApp, because
198 199
             self.__class__,      # it will also affect subclasses (e.g. QtConsole)
199 200
             TerminalInteractiveShell,
  201
+            PromptManager,
200 202
             ProfileDir,
201 203
             PlainTextFormatter,
202 204
             IPCompleter,
6  IPython/testing/tools.py
@@ -202,9 +202,9 @@ def ipexec(fname, options=None):
202 202
 
203 203
     # For these subprocess calls, eliminate all prompt printing so we only see
204 204
     # output from script execution
205  
-    prompt_opts = [ '--InteractiveShell.prompt_in1=""',
206  
-                    '--InteractiveShell.prompt_in2=""',
207  
-                    '--InteractiveShell.prompt_out=""'
  205
+    prompt_opts = [ '--PromptManager.in_template=""',
  206
+                    '--PromptManager.in2_template=""',
  207
+                    '--PromptManager.out_template=""'
208 208
     ]
209 209
     cmdargs = ' '.join(default_argv() + prompt_opts + options)
210 210
 
18  docs/examples/core/example-embed.py
@@ -23,10 +23,10 @@
23 23
 except NameError:
24 24
     nested = 0
25 25
     cfg = Config()
26  
-    shell_config = cfg.InteractiveShellEmbed
27  
-    shell_config.prompt_in1 = 'In <\\#>: '
28  
-    shell_config.prompt_in2 = '   .\\D.: '
29  
-    shell_config.prompt_out = 'Out<\\#>: '
  26
+    prompt_config = cfg.PromptManager
  27
+    prompt_config.in_template = 'In <\\#>: '
  28
+    prompt_config.in2_template = '   .\\D.: '
  29
+    prompt_config.out_template = 'Out<\\#>: '
30 30
 else:
31 31
     print "Running nested copies of IPython."
32 32
     print "The prompts for the nested copy have been modified"
@@ -46,12 +46,12 @@
46 46
 
47 47
 # Make a second instance, you can have as many as you want.
48 48
 cfg2 = cfg.copy()
49  
-shell_config = cfg2.InteractiveShellEmbed
50  
-shell_config.prompt_in1 = 'In2<\\#>: '
  49
+prompt_config = cfg2.PromptManager
  50
+prompt_config.in_template = 'In2<\\#>: '
51 51
 if not nested:
52  
-    shell_config.prompt_in1 = 'In2<\\#>: '
53  
-    shell_config.prompt_in2 = '   .\\D.: '
54  
-    shell_config.prompt_out = 'Out<\\#>: '
  52
+    prompt_config.in_template = 'In2<\\#>: '
  53
+    prompt_config.in2_template = '   .\\D.: '
  54
+    prompt_config.out_template = 'Out<\\#>: '
55 55
 ipshell2 = InteractiveShellEmbed(config=cfg,
56 56
                         banner1 = 'Second IPython instance.')
57 57
 
8  docs/source/interactive/reference.txt
@@ -227,7 +227,7 @@ All options with a [no] prepended can be specified in negated form
227 227
 	circular file inclusions, IPython will stop if it reaches 15
228 228
 	recursive inclusions.
229 229
 
230  
-    ``InteractiveShell.prompt_in1=<string>``
  230
+    ``PromptManager.in_template=<string>``
231 231
 
232 232
 	Specify the string used for input prompts. Note that if you are using
233 233
 	numbered prompts, the number is represented with a '\#' in the
@@ -236,7 +236,7 @@ All options with a [no] prepended can be specified in negated form
236 236
 	discusses in detail all the available escapes to customize your
237 237
 	prompts.
238 238
 
239  
-    ``InteractiveShell.prompt_in2=<string>``
  239
+    ``PromptManager.in2_template=<string>``
240 240
 	Similar to the previous option, but used for the continuation
241 241
 	prompts. The special sequence '\D' is similar to '\#', but
242 242
 	with all digits replaced dots (so you can have your
@@ -244,9 +244,9 @@ All options with a [no] prepended can be specified in negated form
244 244
 	' .\D.:' (note three spaces at the start for alignment with
245 245
 	'In [\#]').
246 246
 
247  
-    ``InteractiveShell.prompt_out=<string>``
  247
+    ``PromptManager.out_template=<string>``
248 248
 	String used for output prompts, also uses numbers like
249  
-	prompt_in1. Default: 'Out[\#]:'
  249
+	in_template. Default: 'Out[\#]:'
250 250
 
251 251
     ``--quick``
252 252
         start in bare bones mode (no config file loaded).
4  docs/source/interactive/shell.txt
@@ -155,8 +155,8 @@ Prompt customization
155 155
 
156 156
 The sh profile uses the following prompt configurations::
157 157
 
158  
-    o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
159  
-    o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green>'
  158
+    o.PromptManager.in_template= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#>'
  159
+    o.PromptManager.in2_template= r'\C_Green|\C_LightGreen\D\C_Green>'
160 160
 
161 161
 You can change the prompt configuration to your liking by editing
162 162
 ipython_config.py.
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.