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
|
//! 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 terminal = @import("term/terminal.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,
};
/// 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,
};
|