bottom_toolbar

This module begins the section of the repository that entails more advanced customization of prompt_toolkit.

Lower level constructs like widgets, toolbars and eventually the Layout classes are utilized quite heavily.

Be careful what the bottom toolbar is set to.

It’s not very difficult to crash the entire application as a result of giving it the wrong type.

The InteractiveShell.`pt_app.bottom_toolbar` type is expected to be some kind of FormattedText. Unfortunately, feeding it an already populated control like a FormattedTextToolbar will break the application.

Don’t run.:

bottom_toolbar = FormattedTextToolbar(bottom_text)
shell.pt_app.bottom_toolbar = bottom_toolbar

Note that a similar expression is used to assign the BottomToolbar to the shell’s pt_app.bottom_toolbar attribute.:

from prompt_toolkit.formatted_text import FormattedText
from IPython import get_ipython

bottom_text = BottomToolbar()
bottom_toolbar = FormattedText(bottom_text.rerender())

However, the FormattedText in and of itself doesn’t provide any functionality. A FormattedText object is simply a subclass of list. The value is provided in defining a method __pt_formatted_text__.

As a result, BottomToolbar also defines this method and as a result an instance of the class can be passed directly as an assignment to the _ip.pt_app.bottom_toolbar.

Examples

>>> import time
>>> from pathlib import Path
>>> from default_profile.startup import bottom_toolbar_mod
>>> if bottom_toolbar_mod is not None:
>>>    from default_profile.startup.bottom_toolbar_mod
>>>    bt = BottomToolbar(get_app())
>>>    print(bt)
       <BottomToolbar:>
>>>    bt()
       f" [F4] Vi: {current_vi_mode!r} \n  cwd: {Path.cwd().stem!r}\n Clock: {time.ctime()!r}"

Toolbar API

TODO: currently initialize a titlebar, an exit button and a few other things that aren’t utilized at all.

get_app(shell=None) → prompt_toolkit.application.application.Application[source][source]

A patch to cover up the fact that get_app() returns a DummyApplication.

exit_clicked()[source][source]

Exit from the prompt_toolkit side of things.

init_style() → prompt_toolkit.styles.style.Style[source][source]

Merges the styles from default_pygments_style and the previously imported pygments_style.

show_header(header_text: Optional[AnyStr] = None) → prompt_toolkit.widgets.base.Frame[source][source]
terminal_width()int[source][source]

Returns shutil.get_terminal_size.columns.

class LineCounter[source][source]

Bases: object

Simple counter inspired by Doug Hellman. Could set it to sys.displayhook.

URL

https://pymotw.com/3/sys/interpreter.html

__init__()[source][source]
display()[source][source]
property time[source][source]
class BottomToolbar(_style: Optional[prompt_toolkit.styles.style.Style] = None, *args: List, **kwargs: Dict)[source][source]

Bases: object

Display the current input mode.

As the bottom_toolbar property exists in both a prompt_toolkit PromptSession and Application, both are accessible from the session and pt_app attributes.

Defines a method rerender() and calls it whenever the instance is called via __call__.

__init__(_style: Optional[prompt_toolkit.styles.style.Style] = None, *args: List, **kwargs: Dict)[source][source]

Require an ‘app’ for initialization.

This will eliminate all IPython code out of this class and make things a little more modular for the tests.

shell: IPython.core.interactiveshell.InteractiveShell[source]
property session[source][source]
property layout[source][source]
property is_vi_mode[source][source]
property style[source][source]
property reset_style[source][source]
full_width()bool[source][source]

Bool indicating bottom toolbar == shutil.get_terminal_size().columns.

rerender() → AnyStr[source][source]

Render the toolbar at the bottom for prompt_toolkit.

Warning

Simple reminder about the difference between running an expression and returning one. If you accidentally forget the return keyword, nothing will display. That’s all.

add_toolbar(toolbar=None)[source][source]

Get the running IPython instance and add ‘bottom_toolbar’.