freya-terminal 0.5.4

Terminal emulator integration for Freya
Documentation
//! # Freya Terminal 🖥️
//!
//! Terminal emulator integration for Freya applications.
//!
//! A [`TerminalHandle`](handle::TerminalHandle) drives a [`rio_vt`] grid and talks to any
//! [`TerminalBackend`](backends::TerminalBackend), such as the built-in [`PtyBackend`](backends::pty::PtyBackend).
//!
//! ## Features
//!
//! - **PTY Integration**: Spawn and interact with shell processes
//! - **Custom backends**: Attach the terminal to anything that produces output, not only a PTY
//! - **Reflowing terminal**: Lines reflow on width change and scrollback is preserved across resizes
//! - **256-Color Support**: ANSI 16 colors, 6x6x6 RGB cube, and 24-level grayscale
//! - **Keyboard Input**: Handle all standard terminal key sequences
//! - **Auto-resize**: Terminal automatically resizes based on available space
//! - **Focus reporting**: Focus changes are reported to programs that enable mode 1004
//!
//! ## Basic Usage
//!
//! ```rust,no_run
//! use freya::prelude::*;
//! use freya_terminal::prelude::*;
//!
//! fn main() {
//!     launch(LaunchConfig::new().with_window(WindowConfig::new(app)))
//! }
//!
//! fn app() -> impl IntoElement {
//!     let mut handle = use_state(|| {
//!         let mut cmd = CommandBuilder::new("bash");
//!         cmd.env("TERM", "xterm-256color");
//!         TerminalHandle::new(TerminalId::new(), PtyBackend::new(cmd), None).ok()
//!     });
//!
//!     let a11y_id = use_a11y();
//!
//!     rect().expanded().background((30, 30, 30)).child(
//!         if let Some(handle) = handle.read().clone() {
//!             rect()
//!                 .child(
//!                     Terminal::new(handle.clone())
//!                         .a11y_id(a11y_id)
//!                         .on_mouse_down(move |_| a11y_id.request_focus())
//!                         .on_key_down(move |e: Event<KeyboardEventData>| {
//!                             let _ = handle.write_key(&e.key, e.modifiers);
//!                         }),
//!                 )
//!                 .expanded()
//!                 .into_element()
//!         } else {
//!             "Failed to start Terminal.".into_element()
//!         },
//!     )
//! }
//! ```
//!
//! ## Handling Terminal Exit
//!
//! You can detect when the terminal closes using `TerminalHandle::closed`:
//!
//! ```rust,ignore
//! use_future(move || async move {
//!     terminal_handle.closed().await;
//!     // Terminal has exited, update UI state
//! });
//! ```
//!
//! ## Advance usage
//!
//! Check the `feature_terminal.rs` example in the repository, and `feature_terminal_custom.rs`
//! for a custom [`TerminalBackend`](backends::TerminalBackend). The `pty` feature, on by default,
//! provides [`PtyBackend`](backends::pty::PtyBackend).
pub mod backends;
mod cell;
pub mod colors;
pub mod element;
pub mod handle;
pub mod parser;
mod rendering;
mod url;

/// Prelude module for convenient imports.
pub mod prelude {
    #[cfg(feature = "pty")]
    pub use portable_pty::CommandBuilder;
    pub use rio_vt::selection::SelectionType;

    #[cfg(feature = "pty")]
    pub use crate::backends::pty::PtyBackend;
    pub use crate::{
        backends::{
            TerminalBackend,
            TerminalOutput,
        },
        element::Terminal,
        handle::{
            TerminalError,
            TerminalHandle,
            TerminalId,
        },
        parser::TerminalMouseButton,
    };
}