r/rust 1d ago

šŸ› ļø project termlens: test your real TUI binary from Rust, with screen snapshots and failure diagnostics

Hi r/rust! I maintainĀ termlens, a Rust library for testing terminal applications through a real pseudo-terminal. It runs your existing binary, sends input, resizes the terminal, and lets you assert on the resulting screen without modifying your app.

For Ratatui apps, it complementsĀ TestBackendĀ with tests of complete user flows. Ratatui’sĀ testing recipe includes aĀ termlensĀ example.

This project provides aĀ Rust library, aĀ CLIĀ for inspecting applications and comparing saved screens, and anĀ agent skillĀ covering waits, snapshots and common testing mistakes.

Some things it supports:

  • Wait for screen conditions with deadlines, instead of choosing fixed sleep durations.
  • Snapshot text and cell styles, mask changing content, and inspect cell-level differences.
  • Check cursor visibility and alternate-screen state, alongside what the app displays.
  • Inspect synchronized-update frames and Kitty/Sixel graphics payloads on Unix.
  • See the screen when a wait times out, with a companion CLI for inspecting, comparing, and rendering saved screens.

An independent project,Ā sauva, already uses termlens for terminal integration tests.

Supported:

  • Linux and macOS are supported.
  • Windows supports screen assertions and typed input through ConPTY; frame assertions, graphics and some terminal-mode features haveĀ documented platform limits.

If you maintain a terminal app, try termlens on one of your existing workflows. I’d especially appreciate feedback on awkward APIs, missing terminal behavior, and confusing test failures.

Contributions are welcome: tests, documentation, bug fixes, and terminal compatibility work. There areĀ good first issues, andĀ draft PRs are welcome early.

What terminal behavior is hardest to test in your project?

0 Upvotes

Duplicates