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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! Idiomatic, safe Rust bindings for
//! [`libghostty-vt`](https://libghostty.tip.ghostty.org/),
//! a terminal emulation library extracted from the
//! [Ghostty](https://ghostty.org) terminal emulator.
//!
//! `libghostty-vt` contains the logic for handling the core parts of a
//! terminal emulator: parsing terminal escape sequences, maintaining terminal
//! state, encoding input events, etc. It can handle scrollback, line wrapping,
//! reflow on resize, and more.
//!
//! <div class="warning">
//!
//! This library is currently in development and the API is not yet stable.
//! Breaking changes are expected in future versions.
//! Use with caution in production code.
//!
//! </div>
//!
//! The core type of `libghostty-vt` is the [`Terminal`] — start there to get a
//! better sense of how everything is structured. You can also check out
//! a list of all top-level modules and their functions below.
//!
//! # Examples
//!
//! [`ghostling-rs`](https://github.com/Uzaaft/libghostty-rs/blob/master/example/ghostling_rs/src/main.rs)
//! is a minimal yet functional terminal emulator built with `libghostty-vt`,
//! written as a single file with only around 1000 lines of heavily commented,
//! easily digestible code. It is based on the original [Ghostling](https://github.com/ghostty-org/ghostling)
//! which is built on the same underlying C API.
//!
//! Other examples are currently work-in-progress — if you have any ideas for
//! examples, feel free to share them with us as an issue or pull request.
//!
//! # Memory management and lifetimes
//!
//! When creating the terminal and various other objects, you can control their
//! memory management via a **custom allocator**, usually specified with
//! methods like [`Terminal::new_with_alloc`]. Objects that accept allocators
//! are also bound by the `'alloc` lifetime, since they internally contain
//! a reference to the allocator. If you do not use a custom allocator,
//! feel free to always set the lifetime to `'static`.
//!
//! ## Using the unstable `Allocator` API
//!
//! You can adapt the existing, unstable `Allocator` API into a
//! [libghostty-friendly allocator](alloc::Allocator) via its `From`
//! implementation. Note that the `'alloc` lifetime must at least
//! live as long as the `Allocator` instance itself.
//!
//! # Thread safety
//!
//! The entire `libghostty-vt` library is **not** thread-safe unless otherwise
//! noted. This is because the underlying C API is not designed with thread
//! safety in mind, and we as binding authors must rather conservatively
//! avoid making any assumptions beyond what is presently guaranteed by the
//! C API.
//!
//! In particular, all `libghostty-vt` types are `!Send`, meaning they cannot
//! be *transferred* across threads, since the C API is allowed to use
//! thread-local state; they are also `!Sync`, meaning they cannot be *shared*
//! across threads, since data races may occur as the C API is not guarded with
//! mutexes or other synchronization mechanisms.
//! We currently do not expect to lift these limitations unless the C API starts
//! to make stronger guarantees regarding thread safety.
//!
//! Note that this does *not* mean that `libghostty-vt` can only be used on
//! the main thread. On the contrary, in a complex program we encourage you to
//! create the terminal on a separate thread (or task in async programming),
//! and use [channels](std::sync::mpsc::channel) to communicate between the
//! terminal emulation thread/task and the main program. Under sufficient load, it is
//! generally more efficient to offload terminal emulation to its own operating
//! system-level thread, in order to reduce competition with other business logic.
pub use libghostty_vt_sys as ffi;
// Make sure that `Terminal`'s own impl blocks (i.e. core functions)
// are placed *before* any extra impl blocks from other modules,
// e.g. Kitty Graphics extensions, Selection APIs
pub use crate::;
pub