镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Add example embedding a cmd2 app in a Textual app with textual-tty - #1773

Open
DG-Elom wants to merge 4 commits into
python-cmd2:mainfrom
DG-Elom:textual-tty-example
Open

DG-Elom wants to merge 4 commits into
python-cmd2:mainfrom
DG-Elom:textual-tty-example

Conversation

@DG-Elom

@DG-Elom DG-Elom commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Adds examples/textual_tty_embed.py, showing how to embed a cmd2 app in a Textual app with textual-tty, with a realtime status panel next to the terminal.

  • The Textual app runs the cmd2 app (this same script with --cmd2-only) in a textual-tty Terminal, so the cmd2 app is a plain prompt-toolkit app that doesn't know it's embedded.
  • The cmd2 app reports its state (idle/running, commands run, last command and duration) with set_window_title() from precmd / command finalization hooks. The Terminal.TitleChanged message updates the panel, so no extra IPC is needed. A Textual-driven clock panel updates independently.
  • textual and textual-tty are not cmd2 dependencies. The module docstring shows how to run it: uv run --with textual-tty examples/textual_tty_embed.py.
  • Added to examples/README.md.

Tested headless with Textual's Pilot (textual 8.2.8, textual-tty 0.4.0, Linux): typing commands into the embedded terminal shows cmd2's output, and the status panel goes idle -> running -> idle with the command count updated. make test, make mypy, make docs-test and the prek hooks pass.

Note that textual-tty is still pre-alpha, so the example may need small updates if its API changes. Happy to adjust the approach (e.g. a socket instead of the window title) if you prefer.

Closes #1771

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.75%. Comparing base (93cfe81) to head (a35a055).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1773   +/-   ##
=======================================
  Coverage   99.75%   99.75%           
=======================================
  Files          23       23           
  Lines        6473     6473           
=======================================
  Hits         6457     6457           
  Misses         16       16           
Flag Coverage Δ
unittests 99.75% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@kmvanbrunt

Copy link
Copy Markdown
Member

Thanks for making this example. It works quite well, but I did run into one issue.

After running enough commands where the prompt should display at the bottom of the screen, it instead is hidden outside the CLI panel.

@DG-Elom

DG-Elom commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for catching this, I can reproduce it. The Terminal widget sizes its pseudo-terminal from its outer size, border included. With border: round on the Terminal itself, the PTY was 2 rows (and 2 columns) bigger than the visible area, so once the screen filled up prompt-toolkit drew the prompt on a row that was clipped. In a headless run at 100x30 the visible area was 26 rows, the PTY was 28, and the cursor ended on row 27.

I moved the border to a wrapping container in a35a055, so the PTY now matches the visible area (26 rows, cursor on row 25 after 40 commands).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create demo example app using textual-tty to embed a cmd2 app within a Textual app

2 participants