|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | """Keep a bottom toolbar on the screen while commands run, by letting Textual draw it using textual-tty. |
3 | 3 |
|
4 | | -cmd2's bottom toolbar is drawn by prompt-toolkit as part of the prompt, so it is only there while the prompt is. |
5 | | -This example shows a way to have one which stays, and keeps refreshing, while a command runs: the cmd2 |
6 | | -application doesn't draw the toolbar at all. A small Textual application owns the terminal instead. It shows the |
7 | | -cmd2 application in a terminal pane which fills the screen except for the bottom, where it draws the toolbar. |
| 4 | +cmd2 can keep its own bottom toolbar on the screen while a command runs. It draws that toolbar in the terminal |
| 5 | +which the command is using, so it has to hide it whenever something else takes over the terminal, as a shell |
| 6 | +command does. This example shows a way to have one which stays, and keeps refreshing, whatever runs there: the |
| 7 | +cmd2 application doesn't draw the toolbar at all. A small Textual application owns the terminal instead. It shows |
| 8 | +the cmd2 application in a terminal pane which fills the screen except for the bottom, where it draws the toolbar. |
8 | 9 |
|
9 | 10 | How it works: |
10 | 11 | - [textual-tty](https://github.com/ttygroup/textual-tty) provides the ``Terminal`` widget, a terminal |
|
22 | 23 | output. A toolbar which refreshes during a command is sent from another thread, and a window title written into |
23 | 24 | the terminal's stream from another thread could land in the middle of the command's output. |
24 | 25 |
|
25 | | -Things this approach gives up, which is why cmd2 doesn't do it for you: |
| 26 | +Things this approach gives up, which is why cmd2 draws its own toolbar in your terminal instead: |
26 | 27 | - Scrollback. The terminal pane keeps none, so output which scrolls off its top is gone, and Textual uses |
27 | 28 | the terminal's alternate screen, so none of the session is in your terminal's own scrollback either. |
28 | 29 | Pipe long output to a pager. |
|
38 | 39 | Otherwise, install textual-tty into your own environment with ``pip install textual-tty`` and then run |
39 | 40 | ``python examples/textual_tty_toolbar.py``. |
40 | 41 |
|
41 | | -Things to try: ``slow``, ``burst 2000 1``, ``page``, ``ask``, resizing the window while a command runs, and |
42 | | -Ctrl-C during ``slow``. To compare with what cmd2 does on its own, run just the cmd2 application, on any platform: |
| 42 | +Things to try: ``slow``, ``burst 2000 1``, ``page``, ``ask``, ``shell sleep 5``, resizing the window while a |
| 43 | +command runs, and Ctrl-C during ``slow``. To compare with the toolbar cmd2 draws itself, run just the cmd2 |
| 44 | +application, on any platform: |
43 | 45 |
|
44 | 46 | python examples/textual_tty_toolbar.py --cmd2-only |
45 | 47 |
|
@@ -171,8 +173,7 @@ def __init__(self, toolbar_socket: str | None) -> None: |
171 | 173 | """Initialize the cmd2 application. |
172 | 174 |
|
173 | 175 | :param toolbar_socket: the Unix socket of the Textual application which draws the toolbar, or None if this |
174 | | - application isn't running inside one. Then prompt-toolkit draws the toolbar as usual, |
175 | | - which means only while the prompt is on the screen. |
| 176 | + application isn't running inside one. Then cmd2 draws the toolbar itself. |
176 | 177 | """ |
177 | 178 | refresh_interval = 0.5 |
178 | 179 | super().__init__( |
|
0 commit comments