diff options
Diffstat (limited to 'src/plain/term.zig')
| -rw-r--r-- | src/plain/term.zig | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/plain/term.zig b/src/plain/term.zig new file mode 100644 index 00000000..2f1323f0 --- /dev/null +++ b/src/plain/term.zig @@ -0,0 +1,110 @@ +//! The terminal as the core sees it (docs/next-terminal.md, Phase 1): the +//! records its draw group takes and gives, plain data. src/Term.zig is the +//! core's side of it. +const std = @import("std"); +const plain = @import("plain.zig"); +const Color = plain.Color; +const CellStyle = plain.CellStyle; + +/// How much of a row the prompt it starts with is. +pub const PromptCut = union(enum) { + /// no prompt: the row as the emulator dumps it + keep, + /// all prompt, nothing typed yet: show nothing of it + blank, + /// this many leading COLUMNS are the prompt; the rest is what was typed + /// at it + cut: usize, +}; + +// ---- its colours on the body ---- + +/// A theme's colours as a terminal's paint takes them. +pub const Ink = struct { + fg: ?[3]u8, + bg: ?[3]u8, + tag_fg: [3]u8, + tag_bg: [3]u8, + /// The theme's own sixteen, when it has them. + palette: ?[16][3]u8, + /// The sixteen the filter keys a program's colours to: `palette`, else + /// made of the theme's roles. + base: [16][3]u8, + + /// A palette index as the theme draws it: its own sixteen, else the + /// index. + pub fn palColor(ink: *const Ink, idx: u8) Color { + if (ink.palette) |pal| if (idx < 16) return .{ .rgb = pal[idx] }; + return .{ .index = idx }; + } +}; + +/// The theme's 256 colours as the filter maps onto them, kept while the +/// theme is the same (`Pardes.tty_filter_palette`). +pub const FilterPalette = struct { + key: ?Key = null, + colors: [256][3]u8 = undefined, + + pub const Key = struct { bg: [3]u8, fg: [3]u8, base: [16][3]u8 }; +}; + +/// A program's colours mapped to the theme, once a frame: what a +Pager's +/// spans are drawn through (`spanColor`), as a terminal's cells are. +pub const Filter = struct { + target: *const [256][3]u8, + /// The theme's page and ink, and the page a program's colours are + /// drawn on (its OSC 11, keyed to the theme, else the theme's). + theme_bg: [3]u8, + theme_fg: [3]u8, + default_bg: [3]u8, + /// What a foreground too near the page's background becomes instead. + fallback_fg: [3]u8, + default_bg_luminance: f64, + fg_for_palette: [256]Color, + bg_for_palette: [256]Color, + /// The two answers for a cell that names no colour of its own. + fg_default: Color, + bg_default: Color, + cache_rgb: [256][3]u8 = undefined, + cache_key: [256]u8 = undefined, + cache_valid: [256]bool = @splat(false), +}; + +/// One cell of a terminal's view as its paint gives it: its style (its +/// colours the theme's already), the bytes it spells in the view's text, +/// and whether it is half of a wide one. +pub const Painted = struct { + style: CellStyle, + bytes: u16, + wide: enum(u2) { narrow, wide, spacer_tail, spacer_head }, +}; + +/// One row of a terminal's view as its paint gives it. +pub const PaintedRow = struct { + /// The shell marked it a prompt's: how much of it the prompt is. + prompt: ?PromptCut, + /// It holds kitty placeholder cells. + placeholder: bool, + /// Its cells given, from its first: the grid's past them are none. + len: u16, +}; + +/// Where a terminal's kitty images go, as the body lays out its rows: +/// `rows_of[v]` is the body row its view's row `v` shows on, null for one +/// not shown. +pub const ImagesAt = struct { + pane: u8, + serial: u32, + tx: u16, + body_y: u16, + cols: u16, + rows_of: []const ?u16, + /// The pane shows its terminal's rows as they are (tty mode): a prompt + /// row is the grid's then, and its images show. + tty_mode: bool, + /// The core's clock (animations step on it), and a cell's size in + /// pixels. + now_ms: u64, + cell_w: u32, + cell_h: u32, +}; |
