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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
//! The terminal as the core sees it (docs/next-terminal.md, Phase 0): the
//! entries the core calls and the plain records they take and give. A
//! terminal pane holds a `*State` the core never looks into: what it knows
//! of one it is told here, as numbers, bytes and text. The emulator
//! (ghostty-vt) and what it brings stay behind this file, in src/term/;
//! this is the one file outside it that names a file inside it (and so
//! the one place Phase 1 turns into the module's registration).
const std = @import("std");
const plain = @import("plain");
const terminal = @import("term/terminal.zig");
const pager = @import("term/pager.zig");
const echo = @import("term/echo.zig");
/// The screen state replicas are sent (its encoder, a terminal's versions,
/// what a peer holds, a replica's side), and its streams and soak for the
/// replica tests outside src/.
pub const screen_state = @import("term/screen_state.zig");
/// A terminal pane's emulator, its parse and what pardes keeps beside it.
pub const State = terminal.State;
// ---- lifecycle ----
/// A new emulator, `cols` by `rows`, allocated with `gpa` (its own from
/// then on).
pub const open = terminal.open;
/// Its emulator and what it holds, freed; the kitty images' caches were
/// `gpa`'s.
pub const close = terminal.close;
/// When its next kitty animation frame is due (ms on the core's clock), as
/// its last drawn frame left it; null when nothing plays.
pub const due = terminal.due;
/// Loaded from a dump without its shell: its program's modes reset, its
/// history marked off from what the next shell prints.
pub const revive = terminal.revive;
/// The PNG resize workers kitty images are decoded with, started and
/// stopped with the host.
pub const start = terminal.TerminalImages.start;
pub const stop = terminal.TerminalImages.stop;
// ---- output and view ----
/// One read of its program's output (`Told` says where the tracked rows
/// went).
pub const feed = terminal.feed;
/// Where the view and the cursor are (`Grid`).
pub const grid = terminal.grid;
/// Its view to a row of its history, or onto its output (null).
pub const viewTo = terminal.viewTo;
/// Its view moved by a number of rows (negative scrolls back).
pub const scroll = terminal.scroll;
/// Its view back onto its output.
pub const follow = terminal.follow;
/// Its grid reflowed, now or when `resizeDeferred` makes it.
pub const resize = terminal.resize;
pub const resizeDeferred = terminal.resizeDeferred;
/// Its cells' size in pixels (kitty graphics, CSI 14/16 t).
pub const cellPixels = terminal.cellPixels;
/// What it answered its program since the last call, to be written to its
/// pty.
pub const replies = terminal.replies;
/// Where the view and the cursor are, in rows counted from the top of the
/// history: `total` rows, the view's top at `offset`, `len` of them shown.
/// All zero without a terminal.
pub const Grid = struct {
total: usize = 0,
offset: usize = 0,
len: usize = 0,
/// The cursor, in cells of the active area (the history's last `len`
/// rows).
cursor_x: u16 = 0,
cursor_y: u16 = 0,
/// The program shows the cursor (DECTCEM).
cursor_visible: bool = false,
/// The view's top row while it is scrolled to one, null while it
/// follows the output.
view: ?usize = null,
/// Its grid's width (a pane's may differ while a resize is deferred).
cols: u16 = 0,
};
/// What a `feed` told the rows the core keeps positions on: each tracked
/// row where it is after the read, whether the program erased it, whether
/// it cleared the screen, whether the pages the rows were on lived through
/// it (a reset can take them) and whether a row could not be followed (no
/// memory for its pin). Taped: a screen-state replica, which feeds
/// nothing, is told its authority's.
pub const Told = struct { rows: []const i32, erased: []const bool, cleared: bool, alive: bool, failed: bool };
// ---- input ----
/// One key for its program, as the program's keyboard protocol and modes
/// ask for it, written out.
pub const key = terminal.key;
/// One mouse event for its program, as the mode and format it set ask for
/// it; empty when the program does not hear of it.
pub const mouse = terminal.mouse;
/// A wheel turn for its program; null when the wheel is not the program's.
pub const wheel = terminal.wheel;
/// A paste as xterm makes one: three parts, the text between the brackets
/// when the program set 2004.
pub const paste = terminal.paste;
/// The modes its program set that the core decides by (`Modes`).
pub const modes = terminal.modes;
/// How far left or right a click on the prompt line moves the shell's
/// cursor, at the prompt the cursor is at.
pub const promptMoves = terminal.promptMoves;
/// The key a frontend read (Event.zig).
pub const Key = @import("Event.zig").Key;
pub const MouseMods = struct { shift: bool = false, alt: bool = false, ctrl: bool = false };
pub const MouseButton = enum { left, middle, right, wheel_up, wheel_down, wheel_left, wheel_right };
pub const MouseAction = enum { press, release, motion };
/// Cursor-key presses: so many left, so many right.
pub const Moves = struct { left: usize = 0, right: usize = 0 };
/// The modes a program set that the core decides by.
pub const Modes = struct {
/// It tracks the mouse itself (1000, 1002, 1003).
mouse: bool = false,
/// ...every move of it (1003).
all_motion: bool = false,
/// A wheel over it is its own: it tracks the mouse, or it is on the
/// alternate screen with alternate scroll (1007).
wheel: bool = false,
/// It wants to hear focus in and out (1004).
focus: bool = false,
/// It wants its pastes bracketed (2004).
bracketed_paste: bool = false,
/// It has the alternate screen (1049).
alternate: bool = false,
};
// ---- prompt and commands ----
/// Where its shell is in its command cycle (`Prompt`).
pub const prompt = terminal.prompt;
/// What the newest finished command printed (`CommandOutput`), read from
/// at most so many rows above its end.
pub const commandOutput = terminal.commandOutput;
/// The shell exited in the middle of a command: its output ends at the
/// cursor.
pub const endOutputHere = terminal.endOutputHere;
/// Where a shell is in its command cycle, as pardes's own OSC 133 marks
/// tell it (marks carrying its `aid` alone: a nested shell's pass it by),
/// and what is at its cursor. All zero without a terminal.
pub const Prompt = struct {
phase: enum { none, prompt, input, running } = .none,
/// Commands started (C at the input phase), prompts drawn (B), and D
/// marks outside a running command (a line the shell handled without
/// starting it).
started: u32 = 0,
prompts: u32 = 0,
declined: u32 = 0,
/// The newest prompt continues an unfinished line (bash's PS2).
continuation: bool = false,
/// The newest command to end: which one, and its status if given.
finished: ?struct { seq: u32, status: ?i32 } = null,
/// The cursor is at a prompt's input, on either screen.
input_ready: bool = false,
/// ...and nothing is typed on its line up to the cursor.
input_empty: bool = false,
/// The cursor is on a prompt's row or at its input, on the primary
/// screen.
at_prompt: bool = false,
};
/// What a command printed. `text` is the caller's.
pub const CommandOutput = struct {
text: [:0]const u8,
/// Whether `text` starts where the command did. It does not when that
/// start is not there to read: cut off by the rows asked for, scrolled
/// out of the history or erased from it (ED 3), erased under it while
/// it ran, or never marked (a C or D on the alternate screen).
whole: bool,
};
// ---- text ----
/// Its whole scrollback as plain text, logical lines (rows it wrapped
/// joined again), ending in a newline: what its body reads and Save
/// writes. The caller's.
pub const scrollback = terminal.scrollback;
/// How long `scrollback` would be, counted without keeping it.
pub const scrollbackLen = terminal.scrollbackLen;
/// Its rows from the top of its history as text, a prompt's own cells cut
/// off (`Rows`).
pub const textRows = terminal.textRows;
/// The rows its view shows as text, prompts cut off or not.
pub const viewport = terminal.viewport;
/// How many bytes of one of its rows, as `viewport` and `textRows` give it
/// uncut, are the prompt it starts with.
pub const promptPrefix = terminal.promptPrefix;
/// A step read its rows: its replicas must hold them for the step's
/// replay.
pub const markRead = terminal.markRead;
/// A terminal's rows as text: `rows` slices into `text`, which is a prefix
/// of `text_alloc` (a prompt cut off shortens the join), the last row the
/// empty one after the cursor's.
pub const Rows = struct {
text_alloc: []u8,
text: []const u8,
rows: [][]const u8,
};
// ---- the pager ----
/// A program's output, as a terminal reads it, paged (`pardes -`, a
/// /pager write): its printed text and its SGR colours as spans over it
/// (`Page`), every other control dropped. The emulator's own parse, so a
/// +Pager pages what a terminal pane would print.
pub const page = pager.parse;
pub const Page = pager.Page;
/// Bytes `start..end` of a page's text, drawn in `style`.
pub const Span = pager.Span;
// ---- draw ----
//
// Plain data both ways: the core hands the theme's colours (`Ink`) and a
// buffer, and is given its view's cells (`Painted`, `PaintedRow`) and its
// images as placements; which of the body's rows they stand under is the
// core's (src/ansi.zig).
/// Its view's rows as cells in the theme's colours, through the theme's
/// filter when the pane has it on.
pub const paint = terminal.paint;
/// Its kitty graphics over the body's rows, as placements.
pub const images = terminal.images;
/// Its rows `first` and the `count` after it as text, prompts cut off (the
/// edit copy's rows, as they were).
pub const editRows = terminal.editRows;
/// The Petscii builtin on it: its kitty graphics as glyph art, or back to
/// pixels; null for none.
pub const petscii = terminal.petscii;
pub const togglePetscii = terminal.togglePetscii;
/// Whether the screen showing holds any kitty graphics image.
pub const hasImages = terminal.hasImages;
/// The filter a +Pager's spans are drawn through, and a span's colour
/// through it.
pub const filter = terminal.pagerFilter;
pub const spanColor = terminal.spanColor;
pub const Ink = plain.term.Ink;
pub const FilterPalette = plain.term.FilterPalette;
pub const Filter = plain.term.Filter;
pub const Painted = plain.term.Painted;
pub const PaintedRow = plain.term.PaintedRow;
pub const ImagesAt = plain.term.ImagesAt;
// ---- its replicas ----
/// What a peer is owed of it, a delta against what the peer was sent.
pub const encode = terminal.encode;
/// Rows of it a replica holds as holes.
pub const encodeRows = terminal.encodeRows;
/// A peer's track of it let go.
pub const untrack = terminal.untrack;
/// Whether a step read its rows since `clearRead`.
pub const wasRead = terminal.wasRead;
pub const clearRead = terminal.clearRead;
/// A replica's side: a delta applied, rows applied, the rows its view
/// shows, rows blank until they come.
pub const apply = terminal.apply;
pub const applyRows = terminal.applyRows;
pub const shown = terminal.shown;
pub const blank = terminal.blank;
pub const dumpScreen = terminal.dumpScreen;
pub const Encoder = screen_state.Encoder;
pub const Track = screen_state.Track;
pub const Peer = screen_state.Peer;
pub const Replica = screen_state.Replica;
/// A replica's keys into a terminal drawn at once, before its authority
/// says (predicted echo).
pub const Echo = echo.Echo;
test {
_ = terminal;
_ = pager;
_ = echo;
_ = screen_state;
}
|