summaryrefslogtreecommitdiff
path: root/src/surface.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 03:06:49 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit98f84f99e79cccc2344aff2efe10823540d0c7b7 (patch)
tree0e11fcb0a2252858dc8c7b442a9c78152af5a585 /src/surface.zig
parentf749eb712d990a9b03f1db372d5311e77bd32edd (diff)
downloadpardes-98f84f99e79cccc2344aff2efe10823540d0c7b7.tar.gz
pardes-98f84f99e79cccc2344aff2efe10823540d0c7b7.zip
plain: the records the core and the terminal both name, a leaf module (docs/next-terminal.md, Phase 1, its first step): src/plain/plain.zig takes Color, FontRole, CellStyle, Cell, RectPx, RectCell, Raster and Placement from surface.zig and Key from Event.zig, moved as they are, and imports std alone; surface.zig and Event.zig re-export them under their old names, so no caller changes; src/term/'s files name them through `plain` (pager.zig and TerminalImages.zig no longer reach surface.zig); build.zig's wireCore gives every core module the `plain` import; locations.Row stays (it names look.Spot and walk's digest: not free); core-test 985 of 985, lib-test
Diffstat (limited to 'src/surface.zig')
-rw-r--r--src/surface.zig126
1 files changed, 11 insertions, 115 deletions
diff --git a/src/surface.zig b/src/surface.zig
index b832222f..73789dce 100644
--- a/src/surface.zig
+++ b/src/surface.zig
@@ -2,6 +2,7 @@
//! the image placements laid over them, and the Surface that holds a frame.
const pardes = @import("pardes.zig");
const std = @import("std");
+const plain = @import("plain");
const layout = @import("layout.zig");
const uucode = @import("uucode");
const vaxis = @import("vaxis");
@@ -11,56 +12,16 @@ const MAX_PANES = pardes.MAX_PANES;
const Layer = @import("Layer.zig");
const MAX_TAG_LAYERS = pardes.MAX_TAG_LAYERS;
-pub const Color = union(enum) { default, index: u8, rgb: [3]u8 };
-
-pub const FontRole = enum(u8) { body, tagline };
-
-pub const CellStyle = struct {
- fg: Color = .default,
- bg: Color = .default,
- bold: bool = false,
- dim: bool = false,
- italic: bool = false,
- blink: bool = false,
- reverse: bool = false,
- invisible: bool = false,
- strikethrough: bool = false,
- ul: enum(u3) { off, single, double, curly, dotted, dashed } = .off,
- font_role: FontRole = .body,
-};
-
-pub const Cell = struct {
- text: [7]u8 = @splat(' '),
- len: u8 = 1,
- style: CellStyle = .{},
- default: bool = true,
-
- pub fn grapheme(c: *const Cell) []const u8 {
- return c.text[0..c.len];
- }
-
- pub fn visuallyEqual(a: *const Cell, b: *const Cell) bool {
- if (a.default or b.default) return a.default and b.default;
- return a.len == b.len and
- std.mem.eql(u8, a.grapheme(), b.grapheme()) and
- std.meta.eql(a.style, b.style);
- }
-
- pub fn printableAscii(c: *const Cell) ?u8 {
- if (c.default) return ' ';
- if (c.len != 1) return null;
- const byte = c.text[0];
- return if (byte >= ' ' and byte <= '~') byte else null;
- }
-};
-
-/// A rectangle in pixels.
-pub const RectPx = struct {
- x: u32 = 0,
- y: u32 = 0,
- w: u32 = 0,
- h: u32 = 0,
-};
+// The plain records (src/plain/plain.zig) both the core and the terminal
+// name, under the names the core has always called them.
+pub const Color = plain.Color;
+pub const FontRole = plain.FontRole;
+pub const CellStyle = plain.CellStyle;
+pub const Cell = plain.Cell;
+pub const RectPx = plain.RectPx;
+pub const RectCell = plain.RectCell;
+pub const Raster = plain.Raster;
+pub const Placement = plain.Placement;
pub const PixelPoint = struct { x: u32, y: u32 };
@@ -113,73 +74,8 @@ pub fn containGeometry(iw: usize, ih: usize, max_w: u32, max_h: u32) ?NativeGeom
return .{ .src = .{ .w = src_w, .h = src_h }, .dst = dst };
}
-/// A rectangle in the frame's cells.
-pub const RectCell = struct { x: u16 = 0, y: u16 = 0, w: u16 = 0, h: u16 = 0 };
-/// The pixels a placement shows: RGBA, straight alpha, `stride` bytes a
-/// row. They are the pane's, and stay put until its next frame.
-pub const Raster = struct {
- ptr: [*]const u8,
- w: u32,
- h: u32,
- stride: u32,
- pub fn of(rgba: []const u8, w: usize, h: usize) Raster {
- return .{ .ptr = rgba.ptr, .w = @intCast(w), .h = @intCast(h), .stride = @intCast(w * 4) };
- }
-
- pub fn bytes(r: Raster) []const u8 {
- return r.ptr[0 .. @as(usize, r.stride) * r.h];
- }
-};
-
-/// A picture over the frame's cells, which a frontend realises: the window
-/// as a texture kept by `key`, the tty as a kitty image, or either as glyph
-/// art in `dst`'s cells (Art.zig, the frontends' own) where it cannot show
-/// pixels or the pane asks for art. The frame lists them a pane at a time,
-/// lowest first.
-pub const Placement = struct {
- pane: u8,
- raster: Raster,
- /// The part of `raster` shown.
- src: RectPx,
- /// The cells it lies over, which clip it.
- dst: RectCell,
- /// Where it goes in `dst`, in pixels from `dst`'s top left corner;
- /// null: the frontend fits `src` there, no larger than it is, at the
- /// top left (as glyph art, centred).
- at: ?RectPx = null,
- /// The pixels' identity (`keyOf`): one key is one picture, so a
- /// frontend keeps what it uploaded under it.
- key: u64,
- /// A terminal program's kitty `z=`: below 0 it is under the text,
- /// which a tty passes on to the terminal outside.
- z: i32 = 0,
- /// Rows of `raster` that alone differ from the picture under the key
- /// `from`: a frontend still holding that one updates those rows.
- dirty: ?Dirty = null,
- art: Art = .{},
-
- pub const Dirty = struct { from: u64, y: u32, h: u32 };
-
- /// How the pane wants it drawn as glyph art: the Petscii, Palette and
- /// Ascii words on an image pane, Petscii and TermImages on a terminal.
- pub const Art = struct {
- /// Glyph art even where pixels could be shown (Petscii on).
- glyph: bool = false,
- palette: Palette = .commodore,
- /// Letters and signs among the glyphs, not only blocks and lines.
- ascii: bool = true,
-
- pub const Palette = enum { commodore, terminal };
- };
-
- /// A pane's picture `page` (a PDF's page, a terminal's image id; 0 for
- /// an image) as of `revision`.
- pub fn keyOf(serial: u32, page: u32, revision: u32) u64 {
- return std.hash.Wyhash.hash(0, std.mem.asBytes(&[3]u32{ serial, page, revision }));
- }
-};
/// One part of the frame and where it is, placed once by `draw.place`
/// before anything is painted: every painter and every shell reads the