shadow_terminal/
lib.rs

1//! # Shadow Terminal
2//! A fully-functional, fully-rendered terminal purely in memory.
3//!
4//! Useful for terminal multiplexers (a la `tmux`, `zellij`) and end to end testing TUI
5//! applications.
6//!
7//! There are 2 convenience modules for using this library: [`ActiveTerminal`] and
8//! [`SteppableTerminal`]. The former is run in a thread and can only be interacted with through
9//! channels, it's aimed more towards real world applications. Whilst the latter must be stepped
10//! through and is aimed more at end to end testing.
11//!
12//! The underlying [`ShadowTerminal`] is also designed to be used directly, but requires a bit
13//! more setup. See `ActiveTerminal` and `SteppableTerminal` to see how.
14
15#![expect(
16    clippy::self_named_module_files,
17    reason = "I just couldn't think of another name apart from ShadowTerminal"
18)]
19#![expect(clippy::pub_use, reason = "How else are you supposed re-export??")]
20
21pub use wezterm_term;
22
23pub mod active_terminal;
24pub mod errors;
25pub mod output;
26mod pty;
27pub mod shadow_terminal;
28pub mod steppable_terminal;
29
30/// Tests
31pub mod tests {
32    pub mod helpers;
33}
34
35/// All the control signals
36#[derive(Debug, Clone)]
37#[non_exhaustive]
38pub enum Protocol {
39    /// End all loops to allow graceful shutdown
40    End,
41    /// Resize the PTY and shadow terminal
42    Resize {
43        /// Width of the shadow terminal
44        width: u16,
45        /// Height of the shadow terminal
46        height: u16,
47    },
48    /// Scrolling of the terminal scrollback
49    Scroll(Scroll),
50}
51
52/// The various states of scrolling
53#[derive(Debug, Clone)]
54#[non_exhaustive]
55pub enum Scroll {
56    /// Scroll the Wezterm terminal frontend up
57    Up,
58    /// Scroll the Wezterm terminal frontend down
59    Down,
60    /// Exit the scroll, returning the terminal to how it was before scrolling started.
61    Cancel,
62}