1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! # 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).
/// Prelude module for convenient imports.