Re: [IPython 5] [Docs] Custom Terminal Prompts
Matthias Bussonnier <[email protected]> Sun, 10 Jul 2016 21:25:06 -0700
| Newsgroups | gmane.comp.python.ipython.devel |
|---|---|
| Message-ID | <CANJQusUoVLt+KTuR_NtoEB3paJx+RsbRCeC4bC2cYDP_SOY2Rw@mail.gmail.com> |
https://github.com/asmeurer/iterm2-tools. Might be a good resource if you looks at (unfinished) PR. This week is SciPy, so I'll be low bandwidth, but if you issue a draft example PR, I can an try to review. -- M On Jul 10, 2016 19:04, "Carl Smith" <[email protected]> wrote: > It seems to be unrelated to the prompt customisation stuff. I removed the > code from my last email, so now have the standard prompt again, but the > execution count still fails to update, even though the prompt is working > properly: > > > In [*1*]: *import* IPython > > > In [*2*]: Shell = > IPython.terminal.interactiveshell.TerminalInteractiveShell > > > In [*3*]: shell = Shell() > > > In [*4*]: shell.execution_count > > > Out[*4*]: 1 > > > In [*5*]: shell.execution_count > > Out[*5*]: 1 > > Maybe the prompt class is supposed to increment the count whenever the ` > in_prompt_tokens` method is called, but I need to get to bed. It's 3am > here. > > G'night, > > -- Carl Smith > [email protected] > > On 11 July 2016 at 02:27, Carl Smith <[email protected]> wrote: > >> Just to help move things along, this is what I have. It works, except for >> the input number always being `1`. I don't know much about some of the >> parts, so have no idea why the count doesn't increment. >> >> import IPython >> from pygments.token import Token >> >> Prompts = IPython.terminal.prompts.Prompts >> Shell = IPython.terminal.interactiveshell.TerminalInteractiveShell >> >> class CustomPrompts(Prompts): >> >> def in_prompt_tokens(self, cli=None): return [ >> (Token.Prompt, "CustomIn["), >> (Token.PromptNum, str(self.shell.execution_count)), >> (Token.Prompt, "]: ") >> ] >> >> get_ipython().prompts = CustomPrompts(Shell()) >> >> This code creates an input prompt like `CustomIn[1]: `, but the number is >> always `1`. Interestingly, the output prompt, which is inherited >> unmodified, is also stuck at `1` now. Everything works correctly; you can >> input code and so on, but the execution count never updates. >> >> If anyone has any ideas... >> >> Best, >> >> -- Carl Smith >> [email protected] >> >> On 11 July 2016 at 00:20, Carl Smith <[email protected]> wrote: >> >>> Thanks Fernando, but please don't put yourself out on my account. >>> Obviously, it's something that needs figuring out, but there's no urgency >>> here. >>> >>> Best, >>> >>> -- Carl Smith >>> [email protected] >>> >>> On 11 July 2016 at 00:15, Fernando Perez <[email protected]> wrote: >>> >>>> On Sun, Jul 10, 2016 at 4:11 PM, Carl Smith <[email protected]> >>>> wrote: >>>> >>>>> No problem at all, Fernando. >>>>> >>>> >>>> Great, thanks! >>>> >>>> >>>>> I did have a go at it based on the code Thomas pointed to, but >>>>> couldn't figure out how to use the reference to >>>>> `self.shell.execution_count`. When it's used directly, as it is in the >>>>> IPython source (passed through `str`), you end up with something like this: >>>>> >>>>> In [<traitlets.traitlets.Int at 0x104800b70>]: >>>>> >>>>> Using the `default_value` and `default_value_repr` methods, gives you >>>>> the number, but it was always `1`, no matter what the actual input number >>>>> was. >>>>> >>>> >>>> Mmh, I'm afraid I haven't really done any significant prompt >>>> customizations in years, way before we made the system traitlets-based... I >>>> don't have a quick solution handy. But let's see if someone else can pitch >>>> in and we get a solution, otherwise I'll try to dig in later... >>>> >>>> -- >>>> Fernando Perez (@fperez_org; http://fperez.org) >>>> fperez.net-at-gmail: mailing lists only (I ignore this when swamped!) >>>> fernando.perez-at-berkeley: contact me here for any direct mail >>>> >>>> _______________________________________________ >>>> IPython-dev mailing list >>>> [email protected] >>>> https://mail.scipy.org/mailman/listinfo/ipython-dev >>>> >>>> >>> >> > > _______________________________________________ > IPython-dev mailing list > [email protected] > https://mail.scipy.org/mailman/listinfo/ipython-dev > > _______________________________________________ IPython-dev mailing list [email protected] https://mail.scipy.org/mailman/listinfo/ipython-dev