VT

vyncint/termlens

Developer tools

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

27 stars 品質 60 トレンド 31Apache-2.0

RustのCLIとTUIアプリのヘッドレスエンドツーエンドテスト:実際のPTY、レンダリング画面アサーション、スナップショット、および画面の差分.

概要

termlens は、実際の擬似ターミナルで実際のバイナリをスプーンし、VT エミュレータを通して出力をメモリ内画面グリッドにレンダリングし、テストの待ち時間を与え、そのグリッドをアサートし、スナップショットする — ユーザが表示されるのは、その生成されたバイトではありません。 Ratatuiのsnapshot-testingレシピは、PTYを通じてコンパイルされたアプリケーションをテストするための用語集の例が含まれています。 TestBackend スナップショットと一緒に使用して、インタラクションとプロセスの動作をカバーします。 処理中のウィジェットテストでは、描画機能をバッファにレンダリングします。 迅速かつ正確で、ドローとユーザーの目の間には見えない。 termlens は 2 番目のレイヤーで、実際のバイナリを通したエンドツーエンドフローの最小数です。 - — 未加工モードと、入力および左の代替画面、q または panic 後に復元されたカーソルは、アプリケーションがオンになったモードとオフになっているかどうか。 - — 箱の描画、色、広い文字、クリアで印刷されるのではなく隠されているパスワードフィールド、ストレイのプリント!

概要(AI 翻訳)

ターミナルプログラムの統合テスト、Webをテストする方法 app. termlens は、実際の擬似ターミナル、レンダリングで、実際のバイナリをスポーン VTエミュレータをメモリ内画面グリッドに出力し、 テストの待ち時間, 主張し、そのグリッドをスナップショット — ユーザが何をするか see は、その生成されたバイトではありません。

Ratatuiのスナップショットテストレシピ PTY を通じてコンパイルされたアプリケーションをテストするための termlens の例が含まれています。 [TestBackend] スナップショットでインタラクションとプロセスをカバー 行動。

なぜ

draw をバッファにレンダリングする in-process ウィジェットのテストです。 お問い合わせ drawとユーザーの間では、迅速かつ正確には何も表示されない 目。 termlens は 2 層で、エンドツーエンドフローの数が少ない 実際のバイナリを通して:

  • 末端の状態 — 生モードおよび交互なスクリーンは入り、左、 [q] またはパニック後に復元されたカーソル、アプリケーションがオンになったモード それらをオフにするかどうか。
  • 実際に描画されるもの — ボックスの描画、色、広い文字、 concealed ではなく、明確に印刷されているパスワードフィールド、stray

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。

README

以下は原文 README の抜粋です。原文を見る。

termlens

Integration testing for terminal programs, the way you would test a web app. termlens spawns your real binary in a real pseudo-terminal, renders its output through a VT emulator into an in-memory screen grid, and lets a test wait on, assert against and snapshot that grid — what a user would see, not the bytes that produced it.

Ratatui’s snapshot-testing recipe includes a termlens example for testing a compiled application through a PTY. Use it alongside TestBackend snapshots to cover interactions and process behaviour.

Why

An in-process widget test renders your draw function into a buffer. It is fast and precise, and it cannot see anything between draw and the user’s eyes. termlens is the second layer, for a small number of end-to-end flows through the real binary:

  • Terminal state — raw mode and the alternate screen entered and left, the cursor restored after q or a panic, the modes the application turned on and whether it turned them off.
  • What is actually drawn — box drawing, colours, wide characters, a password field that is concealed rather than printed in clear, a stray println! or panic message that never went through the framework.
  • Real input and real signals — keys, mouse and paste encoded exactly as the terminal encodes them under the modes the application enabled; a SIGWINCH that the application must survive.
  • Behaviour that changes no cell — a repaint that drew nothing, a bell on a rejected key, an image that went out as pixels when it should have been text.

Every wait is deadline-bounded, and every failure carries the screen: a CI log shows what the application was displaying, not assertion failed: false.

Quick start

cargo add termlens --dev
cargo add insta --dev    # used by the snapshot assertions below
use std::time::Duration;
use termlens::{Key, Terminal};

#[test]
fn quits_from_the_main_screen() -> termlens::Result {
    let mut t = Terminal::builder()
        .size(80, 24)
        .env_clear()                       // hermetic: no host env leaks in
        .timeout(Duration::from_secs(5))   // every wait_* has this deadline
        .spawn(env!("CARGO_BIN_EXE_myapp"))?;

    // Wait for the app's ready marker, let the picture settle, then snapshot
    // it with its styles — the three decisions every TUI snapshot needs.
    termlens::assert_screen_snapshot!(t, after = |s| s.contains("Ready"));
GitHub で README 全文を見る

推奨ツール

別のキーワードを試すか、フィルタを外してください。

インストール

npx skillfish add vyncint/termlens
MCP 初心者?mcpskill.org のガイドから始めましょう →