summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Art.zig32
-rw-r--r--src/CHANGELOG.md16
-rw-r--r--src/File.zig65
-rw-r--r--src/Text.zig36
-rw-r--r--src/body_layer.zig2
-rw-r--r--src/colors.zig30
-rw-r--r--src/draw.zig98
-rw-r--r--src/gui/gui.zig24
-rw-r--r--src/layout.zig14
-rw-r--r--src/mouse.zig261
-rw-r--r--src/ninep/ctl.zig2
-rw-r--r--src/pager.zig379
-rw-r--r--src/panes.zig2
-rw-r--r--src/surface.zig21
-rw-r--r--src/terminal.zig25
-rw-r--r--src/tui/tui.zig14
16 files changed, 498 insertions, 523 deletions
diff --git a/src/Art.zig b/src/Art.zig
index 6cc33e2e..2e2941c6 100644
--- a/src/Art.zig
+++ b/src/Art.zig
@@ -6,7 +6,7 @@
//! the same on every client. One of these a frontend keeps the art of the
//! pictures it shows, while it shows them.
const std = @import("std");
-const ghostty_vt = @import("ghostty-vt");
+const colors = @import("colors.zig");
const pardes = @import("pardes.zig");
const Art = @This();
@@ -76,7 +76,7 @@ fn gridOf(art: *Art, gpa: std.mem.Allocator, place: Placement, cell_h: u32) ?Gri
}
const colours = switch (place.art.palette) {
.commodore => commodore,
- .terminal => terminal_palette,
+ .terminal => colors.xterm[0..16].*,
};
const grid = (if (place.at == null)
fitted(gpa, place.raster, place.src, place.dst.w, place.dst.h, colours, place.art.ascii)
@@ -466,34 +466,6 @@ fn renderRect(gpa: std.mem.Allocator, raster: Raster, src: RectPx, cols: usize,
return .{ .cells = cells, .cols = cols, .rows = rows };
}
-pub const terminal_palette = [16][3]u8{
- .{ 0x1D, 0x1F, 0x21 }, // black
- .{ 0xCC, 0x66, 0x66 }, // red
- .{ 0xB5, 0xBD, 0x68 }, // green
- .{ 0xF0, 0xC6, 0x74 }, // yellow
- .{ 0x81, 0xA2, 0xBE }, // blue
- .{ 0xB2, 0x94, 0xBB }, // magenta
- .{ 0x8A, 0xBE, 0xB7 }, // cyan
- .{ 0xC5, 0xC8, 0xC6 }, // white
- .{ 0x66, 0x66, 0x66 }, // bright black
- .{ 0xD5, 0x4E, 0x53 }, // bright red
- .{ 0xB9, 0xCA, 0x4A }, // bright green
- .{ 0xE7, 0xC5, 0x47 }, // bright yellow
- .{ 0x7A, 0xA6, 0xDA }, // bright blue
- .{ 0xC3, 0x97, 0xD8 }, // bright magenta
- .{ 0x70, 0xC0, 0xB1 }, // bright cyan
- .{ 0xEA, 0xEA, 0xEA }, // bright white
-};
-
-comptime {
- for (terminal_palette, 0..) |rgb, i| {
- const c = ghostty_vt.color.default[i];
- if (rgb[0] != c.r or rgb[1] != c.g or rgb[2] != c.b) @compileError(
- "terminal palette differs from the emulator",
- );
- }
-}
-
test "sextant codepoints: blocks + endpoints" {
try std.testing.expectEqual(@as(u21, ' '), sextantCp(0));
try std.testing.expectEqual(@as(u21, 0x2588), sextantCp(63));
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 3b139f00..da489b82 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -2,12 +2,28 @@
## Unreleased
+- A drag draws no guide lines: no dashes where a pane or column would
+ land, no rail for a carried column, no dashed seam under a pane rule
+ held. The line between two columns no longer resizes them (nor, at a
+ pane's corner, the panes too): a press there is a press in the pane.
+ A column resizes by its box, left of its tag; a pane by its own box,
+ or in a window by the rule above it.
+
- An edit to the core recompiles it about 3 s sooner (`core-test`, 13 s to
10 s): the build keeps each grammar's highlight patterns that pardes
colours once, where every compile of every program that takes the core
did it again, a quarter of its time. A package that depends on pardes
is given the same filtered queries.
+- The core measures a grapheme's cells over uucode itself
+ (`File.utf8Width`, libvaxis's `gwidth` to the cell on every scalar
+ value), so libvaxis is the tui's and the gui's alone, not the core
+ module's. The 256-colour palette Petscii art and the window draw a
+ palette colour with is pardes's own (`colors.xterm`), ghostty-vt's
+ default to the entry. A `+Pager` (`pardes -`) reads its program's colour
+ codes with a parser of its own, which pages what ghostty-vt's did, byte
+ for byte, about 10% faster.
+
- Commit patches open as `+Diff-<short-hash>` and reuse only their own
commit's pane, so another paged patch no longer replaces one already open.
diff --git a/src/File.zig b/src/File.zig
index d1cfe088..5150f1cd 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -2,7 +2,7 @@
//! index, syntax highlights and the body it fills.
const panes = @import("panes.zig");
const std = @import("std");
-const vaxis = @import("vaxis");
+const uucode = @import("uucode");
const builtin = @import("builtin");
const pardes = @import("pardes.zig");
const config = @import("config.zig");
@@ -186,10 +186,8 @@ pub const NodeStep = struct { ranges: []modal.Selection, primary: usize };
pub fn graphemeDisplayWidth(grapheme: []const u8) usize {
if (std.mem.eql(u8, grapheme, "\t")) return config.tab_now;
if (grapheme.len == 1 and grapheme[0] >= 0x20 and grapheme[0] < 0x7f) return 1;
- if (std.unicode.utf8ValidateSlice(grapheme)) return @max(1, @as(usize, vaxis.gwidth.gwidth(grapheme, .unicode)));
- // vaxis's gwidth counts back a replacement rune's 3 bytes over the one
- // invalid byte it stood for (`\xee` before `e\u{301}` overflowed it):
- // each invalid byte is a cell, as surface.zig draws it, and each valid
+ if (std.unicode.utf8ValidateSlice(grapheme)) return @max(1, @as(usize, utf8Width(grapheme)));
+ // Each invalid byte is a cell, as surface.zig draws it, and each valid
// run between is measured alone.
var width: usize = 0;
var run: usize = 0;
@@ -200,15 +198,60 @@ pub fn graphemeDisplayWidth(grapheme: []const u8) usize {
i += n;
continue;
}
- if (run < i) width += vaxis.gwidth.gwidth(grapheme[run..i], .unicode);
+ if (run < i) width += utf8Width(grapheme[run..i]);
width += 1;
i += 1;
run = i;
}
- if (run < grapheme.len) width += vaxis.gwidth.gwidth(grapheme[run..], .unicode);
+ if (run < grapheme.len) width += utf8Width(grapheme[run..]);
return @max(1, width);
}
+/// The cells valid UTF-8 takes, summed over its graphemes: a grapheme is
+/// as wide as its widest code point (a control, a nonspacing or enclosing
+/// mark and the joiners, selectors and other format characters below add
+/// none; East Asian wide and fullwidth two, the rest one), then at least
+/// one under the text selector U+FE0E, else at least two under the emoji
+/// selector U+FE0F, with an emoji-presentation code point, or as a flag's
+/// two regional indicators. It is libvaxis's `gwidth(.unicode)` over the
+/// same uucode tables, which the tui renders with in mode 2027.
+pub fn utf8Width(valid: []const u8) u16 {
+ var total: u16 = 0;
+ var widest: u16 = 0;
+ var text_vs = false;
+ var emoji = false;
+ var flags: u8 = 0;
+ var it = uucode.grapheme.utf8Iterator(valid);
+ while (it.nextCodePoint()) |r| {
+ const cp = r.code_point;
+ if (cp == 0xfe0e) {
+ text_vs = true;
+ } else if (cp == 0xfe0f) {
+ emoji = true;
+ } else {
+ if (uucode.get(.is_emoji_presentation, cp)) emoji = true;
+ if (cp >= 0x1f1e6 and cp <= 0x1f1ff) flags += 1;
+ widest = @max(widest, @as(u16, switch (cp) {
+ 0...0x1f, 0x7f...0x9f, 0xad, 0x34f, 0x180b...0x180d, 0x200b...0x200d, 0x2060, 0xfe00...0xfe0d, 0xfeff, 0xe0100...0xe01ef => 0,
+ else => switch (uucode.get(.general_category, cp)) {
+ .mark_nonspacing, .mark_enclosing => 0,
+ else => switch (uucode.get(.east_asian_width, cp)) {
+ .fullwidth, .wide => 2,
+ else => 1,
+ },
+ },
+ }));
+ }
+ if (!r.is_break) continue;
+ total += if (text_vs) @max(1, widest) else if (emoji or flags == 2) @max(2, widest) else widest;
+ widest = 0;
+ text_vs = false;
+ emoji = false;
+ flags = 0;
+ }
+ return total;
+}
+
pub fn displayWidth(text: []const u8) usize {
var width: usize = 0;
var at: usize = 0;
@@ -2206,7 +2249,7 @@ pub fn paintWordSelection(
}
}
-test "an invalid byte in a grapheme is one cell, and never reaches vaxis's width" {
+test "an invalid byte in a grapheme is one cell, and never reaches utf8Width" {
try std.testing.expectEqual(@as(usize, 2), graphemeDisplayWidth("\xeee\xcc\x81"));
try std.testing.expectEqual(@as(usize, 3), graphemeDisplayWidth("\xee\xffe"));
try std.testing.expectEqual(@as(usize, 3), graphemeDisplayWidth("\u{4e16}\x80"));
@@ -2245,11 +2288,11 @@ test "indexed source rows match uncached scans across content changes" {
}
}
-test "the ASCII arm of graphemeDisplayWidth matches the gwidth it skips" {
+test "the ASCII arm of graphemeDisplayWidth matches the utf8Width it skips" {
const ref = struct {
fn width(grapheme: []const u8) usize {
if (std.mem.eql(u8, grapheme, "\t")) return config.tab_now;
- return @max(1, @as(usize, vaxis.gwidth.gwidth(grapheme, .unicode)));
+ return @max(1, @as(usize, utf8Width(grapheme)));
}
}.width;
@@ -2264,7 +2307,7 @@ test "the ASCII arm of graphemeDisplayWidth matches the gwidth it skips" {
"\u{1f642}", "\u{1f1e6}\u{1f1e7}", "\xff",
}) |g| try std.testing.expectEqual(ref(g), graphemeDisplayWidth(g));
// Two invalid bytes are two cells, as surface.zig draws them, where
- // vaxis's own count gives the pair one.
+ // one U+FFFD for the pair would give one.
try std.testing.expectEqual(@as(usize, 2), graphemeDisplayWidth("\xe4\xb8"));
}
diff --git a/src/Text.zig b/src/Text.zig
index 43a515e1..271269ab 100644
--- a/src/Text.zig
+++ b/src/Text.zig
@@ -14,7 +14,6 @@ const config = @import("config.zig");
const memory = @import("memory.zig");
const Pane = panes.Pane;
const File = panes.File;
-const terminal = panes.terminal;
const Text = @This();
pub const Mode = enum { normal, insert, tty };
@@ -30,6 +29,25 @@ pub const CharSel = struct {
explicit: bool = false,
};
+/// The owned text standing in for `rows` live terminal rows, beginning at
+/// absolute surface row `row`. The emulator grid remains untouched underneath.
+pub const EditBuffer = struct {
+ row: i32 = 0,
+ rows: i32 = 1,
+ text: []u8 = &.{},
+};
+
+/// One whole-state terminal edit boundary. Null means the pane has not yet
+/// materialized an edit buffer; non-null snapshots own their text.
+pub const Snapshot = struct {
+ ovl: ?EditBuffer,
+ cur_row: i32,
+ cur_col: i32,
+ vsel: CharSel,
+};
+
+pub const history_max = 64;
+
pub const max_selections = memory.limits.selections;
pub const SelRange = struct {
@@ -80,9 +98,9 @@ normal: modal.Normal.State = .{},
/// last f/F/t/T motion, for Alt-. repeat
find_op: ?modal.Normal.Find = null,
find_ch: u21 = 0,
-ed_undo: [terminal.history_max]terminal.Snapshot = undefined,
+ed_undo: [history_max]Snapshot = undefined,
ed_undo_len: usize = 0,
-ed_redo: [terminal.history_max]terminal.Snapshot = undefined,
+ed_redo: [history_max]Snapshot = undefined,
ed_redo_len: usize = 0,
/// Set when an edit would have changed characters this text does not own
/// (a tag's computed prefix) and was refused; the key that tried it puts
@@ -604,10 +622,10 @@ fn unchanged(gpa: std.mem.Allocator, entries: []const Entry, text: []const u8) e
return std.mem.eql(u8, window.items, text[lo..hi]);
}
-fn pushHistory(gpa: std.mem.Allocator, slots: []terminal.Snapshot, len: *usize, value: terminal.Snapshot) void {
+fn pushHistory(gpa: std.mem.Allocator, slots: []Snapshot, len: *usize, value: Snapshot) void {
if (len.* == slots.len) {
if (slots[0].ovl) |overlay| gpa.free(overlay.text);
- std.mem.copyForwards(terminal.Snapshot, slots[0 .. slots.len - 1], slots[1..]);
+ std.mem.copyForwards(Snapshot, slots[0 .. slots.len - 1], slots[1..]);
len.* -= 1;
}
slots[len.*] = value;
@@ -617,14 +635,14 @@ fn pushHistory(gpa: std.mem.Allocator, slots: []terminal.Snapshot, len: *usize,
/// Record an edit buffer (a terminal's overlay, a tag's own text) as it
/// stands before an edit, once per change of it, and forget what could have
/// been redone. Null is a buffer not made yet.
-pub fn remember(t: *Text, gpa: std.mem.Allocator, current: ?terminal.EditBuffer) error{OutOfMemory}!void {
+pub fn remember(t: *Text, gpa: std.mem.Allocator, current: ?EditBuffer) error{OutOfMemory}!void {
if (t.ed_undo_len > 0) {
const top = t.ed_undo[t.ed_undo_len - 1];
const same = if (top.ovl) |overlay| if (current) |now| overlay.row == now.row and
overlay.rows == now.rows and std.mem.eql(u8, overlay.text, now.text) else false else current == null;
if (same) return;
}
- const copy: ?terminal.EditBuffer = if (current) |now| .{ .row = now.row, .rows = now.rows, .text = try gpa.dupe(u8, now.text) } else null;
+ const copy: ?EditBuffer = if (current) |now| .{ .row = now.row, .rows = now.rows, .text = try gpa.dupe(u8, now.text) } else null;
pushHistory(gpa, &t.ed_undo, &t.ed_undo_len, .{ .ovl = copy, .cur_row = t.cur_row, .cur_col = t.cur_col, .vsel = t.vsel });
for (t.ed_redo[0..t.ed_redo_len]) |item| if (item.ovl) |overlay| gpa.free(overlay.text);
t.ed_redo_len = 0;
@@ -634,13 +652,13 @@ pub fn remember(t: *Text, gpa: std.mem.Allocator, current: ?terminal.EditBuffer)
/// other history and the state to return to comes back, its cursor and
/// selection already restored here. The caller installs its buffer, which
/// it then owns. Null when there is nothing to step to.
-pub fn step(t: *Text, gpa: std.mem.Allocator, current: ?terminal.EditBuffer, back: bool) error{OutOfMemory}!?terminal.Snapshot {
+pub fn step(t: *Text, gpa: std.mem.Allocator, current: ?EditBuffer, back: bool) error{OutOfMemory}!?Snapshot {
const from, const from_len, const to, const to_len = if (back)
.{ &t.ed_undo, &t.ed_undo_len, &t.ed_redo, &t.ed_redo_len }
else
.{ &t.ed_redo, &t.ed_redo_len, &t.ed_undo, &t.ed_undo_len };
if (from_len.* == 0) return null;
- const copy: ?terminal.EditBuffer = if (current) |now| .{ .row = now.row, .rows = now.rows, .text = try gpa.dupe(u8, now.text) } else null;
+ const copy: ?EditBuffer = if (current) |now| .{ .row = now.row, .rows = now.rows, .text = try gpa.dupe(u8, now.text) } else null;
pushHistory(gpa, to, to_len, .{ .ovl = copy, .cur_row = t.cur_row, .cur_col = t.cur_col, .vsel = t.vsel });
from_len.* -= 1;
const back_to = from[from_len.*];
diff --git a/src/body_layer.zig b/src/body_layer.zig
index 76aec179..dbf0156d 100644
--- a/src/body_layer.zig
+++ b/src/body_layer.zig
@@ -195,7 +195,7 @@ pub fn joinBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
layer.id = @intCast(id);
layer.serial = pane.serial;
const body = s.region(.body, id).?;
- layer.viewport = .{ .x = body.rect.x, .y = body.rect.y, .w = body.rect.w - body.clip, .h = body.rect.h };
+ layer.viewport = .{ .x = body.rect.x, .y = body.rect.y, .w = body.rect.w, .h = body.rect.h };
layer.cols = width;
layer.rows = @intCast(logical_rows);
layer.context_rows = pane.context_rows;
diff --git a/src/colors.zig b/src/colors.zig
index e679f4a5..1713ba24 100644
--- a/src/colors.zig
+++ b/src/colors.zig
@@ -12,6 +12,36 @@ const MAX_PANES = pardes.MAX_PANES;
const BOX_H = pardes.BOX_H;
const Pardes = pardes.Pardes;
+/// The 256-colour palette a terminal starts from (ghostty-vt's default):
+/// sixteen named colours, a 6x6x6 cube at xterm's levels (0, then 95 to
+/// 255 by 40) and a ramp of 24 greys from 8 by 10.
+pub const xterm: [256][3]u8 = blk: {
+ var p: [256][3]u8 = undefined;
+ p[0..16].* = .{
+ .{ 0x1D, 0x1F, 0x21 }, // black
+ .{ 0xCC, 0x66, 0x66 }, // red
+ .{ 0xB5, 0xBD, 0x68 }, // green
+ .{ 0xF0, 0xC6, 0x74 }, // yellow
+ .{ 0x81, 0xA2, 0xBE }, // blue
+ .{ 0xB2, 0x94, 0xBB }, // magenta
+ .{ 0x8A, 0xBE, 0xB7 }, // cyan
+ .{ 0xC5, 0xC8, 0xC6 }, // white
+ .{ 0x66, 0x66, 0x66 }, // bright black
+ .{ 0xD5, 0x4E, 0x53 }, // bright red
+ .{ 0xB9, 0xCA, 0x4A }, // bright green
+ .{ 0xE7, 0xC5, 0x47 }, // bright yellow
+ .{ 0x7A, 0xA6, 0xDA }, // bright blue
+ .{ 0xC3, 0x97, 0xD8 }, // bright magenta
+ .{ 0x70, 0xC0, 0xB1 }, // bright cyan
+ .{ 0xEA, 0xEA, 0xEA }, // bright white
+ };
+ for (0..216) |i| {
+ for (0..3, [3]usize{ i / 36, i / 6 % 6, i % 6 }) |c, v| p[16 + i][c] = if (v == 0) 0 else 55 + 40 * v;
+ }
+ for (0..24) |i| p[232 + i] = @splat(8 + 10 * i);
+ break :blk p;
+};
+
/// sRGB channel to linear light.
pub const to_linear: [256]f32 = blk: {
@setEvalBranchQuota(100_000);
diff --git a/src/draw.zig b/src/draw.zig
index 7d199155..2fabff06 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -4,7 +4,6 @@
//! chips, the workspace and column tags, the tag layers, drag overlays, the
//! debug box, then the cursor.
const std = @import("std");
-const vaxis = @import("vaxis");
const pardes = @import("pardes.zig");
const layout = @import("layout.zig");
const config = @import("config.zig");
@@ -116,24 +115,6 @@ pub fn place(p: *Pardes, s: *Surface) void {
}
if (p.settings.workspace_tag)
s.addRegion(.{ .kind = .workspace_tag, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = p.topBarHeight() } });
- // A column carried to the window's right edge shows where it lands as a
- // rail in the last cell: the layers under it stop a cell short.
- if (v.drag == .column_move) rail: {
- const d = v.drag.column_move;
- const source = layout.columnBySerial(p, d.serial) orelse break :rail;
- const edge: u16 = switch (layout.columnDrop(p, source, d.cur_x, d.grab)) {
- .stay => break :rail,
- .reorder => |target| if (target < source) v.col_x[target] else v.col_x[target] + v.col_w[target],
- .edge => |x| x,
- };
- if (edge != s.cols) break :rail;
- for (s.regions[0..s.nregions]) |*region| switch (region.kind) {
- .body, .tag, .notice, .column_tag => if (region.rect.x + region.rect.w == s.cols) {
- region.clip = 1;
- },
- else => {},
- };
- }
}
/// A pane's grip in the grid: `box` focused, else halfway between its ring
@@ -252,8 +233,6 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
if (layer.cursor) |caret| {
if (caret.x >= skip) s.cursor = .{ .x = region.rect.x + caret.x - @as(u16, @intCast(skip)), .y = region.rect.y, .bar = caret.bar };
}
- // Laid out at its full width; only shown short of the rail.
- layer.viewport.w -|= region.clip;
}
pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
@@ -328,77 +307,6 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
try paintHeaders(p, s);
- switch (v.drag) {
- .border_v => |d| {
- if (d.cur_x < s.cols) {
- var row: u16 = p.topBarHeight();
- while (row < s.rows) : (row += 1) s.overlayDash(d.cur_x, row, "╎");
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = d.cur_x, .y = p.topBarHeight(), .w = 1, .h = s.rows -| p.topBarHeight() } });
- }
- if (d.corner) |k| if (d.cur_y < s.rows) {
- const first = if (k.col == d.left_col) v.col_x[k.col] else d.cur_x +| 1;
- const end = if (k.col == d.left_col) d.cur_x else v.col_x[k.col] +| v.col_w[k.col] -| 1;
- var col = first;
- while (col <= end and col < s.cols) : (col += 1) s.overlayDash(col, d.cur_y, "╌");
- if (col > first) s.addRegion(.{ .kind = .guide, .rect = .{ .x = first, .y = d.cur_y, .w = col - first, .h = 1 } });
- };
- },
- // A column that went away mid-drag has nothing to guide.
- .border_h => |d| if (d.cur_y < s.rows and d.col < v.ncol and v.col_x[d.col] < s.cols) {
- const end = @min(s.cols, v.col_x[d.col] + v.col_w[d.col]);
- var col = v.col_x[d.col];
- while (col < end) : (col += 1) s.overlayDash(col, d.cur_y, "╌");
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = v.col_x[d.col], .y = d.cur_y, .w = end - v.col_x[d.col], .h = 1 } });
- },
- .column_move => |d| rail: {
- const source = layout.columnBySerial(p, d.serial) orelse break :rail;
- if (s.cols == 0) break :rail;
- // Where the column's left edge would land, reordered or not.
- const edge: u16 = switch (layout.columnDrop(p, source, d.cur_x, d.grab)) {
- .stay => break :rail,
- .reorder => |target| if (target < source) v.col_x[target] else v.col_x[target] + v.col_w[target],
- .edge => |x| x,
- };
- // The layers under an outside rail stop a cell short of it:
- // `place` clipped them.
- // The rail runs in the seam cell left of the edge, where a
- // border drag's does: the edge cell itself is a gutter, which
- // the GUI paints as a scroll rail that swallowed the dashes.
- // At the window's left edge there is no seam, so it runs just
- // past that scroll rail instead. It takes the lit grip's
- // color: this is where the grabbed column lands.
- const x = @min(if (edge == 0) config.GUTTER - 1 else edge - 1, s.cols -| 1);
- var row: u16 = p.topBarHeight();
- // A guide region for each run of it the tags do not break.
- var run: u16 = row;
- while (row < s.rows) : (row += 1) {
- // Past the left edge's scroll rail the rail would cut
- // through column 0's grip and pane boxes: leave them whole.
- if (edge == 0 and s.at(x, row).style.font_role == .tagline) {
- if (row > run) s.addRegion(.{ .kind = .guide, .rect = .{ .x = x, .y = run, .w = 1, .h = row - run } });
- run = row + 1;
- continue;
- }
- s.overlayDash(x, row, "╎");
- s.at(x, row).style.fg = .{ .rgb = chrome.column_box };
- }
- if (row > run) s.addRegion(.{ .kind = .guide, .rect = .{ .x = x, .y = run, .w = 1, .h = row - run } });
- },
- .move => |d| if (d.cur_x < s.cols) {
- if (layout.movePlacement(p, d.id, d.cur_x, d.cur_y)) |placement| if (placement.row < s.rows and v.col_x[placement.preview_col] + v.col_w[placement.preview_col] <= s.cols) {
- var col: u16 = v.col_x[placement.preview_col];
- while (col < v.col_x[placement.preview_col] + v.col_w[placement.preview_col]) : (col += 1) {
- s.set(col, placement.row, "╌", .{ .fg = .{ .rgb = chrome.lineno } });
- }
- s.set(d.cur_x, placement.row, "▌", .{ .fg = .{ .rgb = chrome.lineno } });
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = v.col_x[placement.preview_col], .y = placement.row, .w = v.col_w[placement.preview_col], .h = 1 } });
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = d.cur_x, .y = placement.row, .w = 1, .h = 1 } });
- };
- },
- // A hover draws no hint: columns resize by their grips.
- .none, .select => {},
- }
-
// debug overlay: a small stats box drawn last, top-right ("Debug")
if (p.settings.debug) if (p.panes[v.active]) |at| {
var nlive: usize = 0;
@@ -607,8 +515,6 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void {
const layer = &s.tag_layers[MAX_PANES + c];
try renderHeaderLayer(p, layer, .column, @intCast(c), region.rect, tagline.columnTag(p, c), top, bg, fg);
if (v.col_x[c] < s.cols) joinHeaderRows(s, layer, fg);
- // Laid out at its full width; only shown short of the rail.
- layer.viewport.w -|= region.clip;
};
}
@@ -810,7 +716,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
layer.kind = .pane;
layer.id = @intCast(id);
layer.serial = pane.serial;
- layer.viewport = .{ .x = region.rect.x, .y = region.rect.y, .w = region.rect.w - region.clip, .h = rows };
+ layer.viewport = .{ .x = region.rect.x, .y = region.rect.y, .w = region.rect.w, .h = rows };
layer.cols = columns;
layer.rows = rows;
layer.context_rows = 0;
@@ -1330,7 +1236,7 @@ test "a wide glyph cut by a tag's or a notice's edge is joined into the grid as
const head = !cell.default and cell.len > 1 and i + 1 < row.len and !row[i + 1].default and row[i + 1].len == 0;
// A spacer has its head before it; a head its spacer after.
if (spacer) try std.testing.expect(i > 0 and row[i - 1].len > 1);
- if (i + 1 == row.len) try std.testing.expect(!head and !(cell.len > 1 and vaxis.gwidth.gwidth(cell.grapheme(), .unicode) == 2));
+ if (i + 1 == row.len) try std.testing.expect(!head and !(cell.len > 1 and panes.File.utf8Width(cell.grapheme()) == 2));
}
// The right edge of each is the band, blank where a glyph was cut.
try std.testing.expectEqual(FontRole.tagline, row[row.len - 1].style.font_role);
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 51ec6bbf..45157dd3 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -7,7 +7,6 @@ const posix = std.posix;
/// libc: pipes and fcntl for the window's wakes, and a test harness's capture files written from the render thread.
const libc = std.c;
const vaxis = @import("vaxis"); // test modes only: the stdin escape-seq parser
-const ghostty_vt = @import("ghostty-vt"); // 256-color palette for .index cells
const pardes = @import("../pardes.zig");
const vaxis_input = @import("../vaxis_input.zig");
const dump = @import("../dump.zig");
@@ -869,12 +868,12 @@ const Group = struct {
};
/// The frame's draw groups, bottom to top: the page and the panes, the
-/// notices floating over them, the guides and the debug box the core paints
-/// over those, and ink (the bar cursors; the cursor's glide draws after it).
+/// notices floating over them, the debug box the core paints over those,
+/// and ink (the bar cursors; the cursor's glide draws after it).
const Groups = struct {
items: [4]Group = @splat(.{}),
notices: usize = 1,
- guides: usize = 2,
+ debug: usize = 2,
ink: usize = 3,
len: usize = 4,
};
@@ -884,7 +883,7 @@ const Groups = struct {
const Cover = packed struct(u16) {
/// A layer draws it; the grid's copy is not drawn.
layer: bool = false,
- /// Under a guide or the debug box: drawn from the grid over the panes.
+ /// Under the debug box: drawn from the grid over the panes.
floating: bool = false,
/// In a pane's grip, `grip_offset` cells from its left: the grip's
/// glyph is the cell that far to the left.
@@ -951,7 +950,7 @@ fn coverFrame(cover: []Cover, cols: u16, rows: u16, body_layers: []const pardes.
mark.rect(cover, cols, rows, .{ .x = region.rect.x, .y = 0, .w = 1, .h = rows }, "anchor", true);
if (region.active) if (bar) |b| mark.rect(cover, cols, rows, .{ .x = region.rect.x, .y = b.y, .w = region.rect.w, .h = b.h }, "focus", true);
},
- .guide, .debug => mark.rect(cover, cols, rows, region.rect, "floating", true),
+ .debug => mark.rect(cover, cols, rows, region.rect, "floating", true),
else => {},
};
}
@@ -4560,7 +4559,7 @@ fn renderFrame(
while (col < surface.cols) : (col += 1) {
const at = @as(usize, row) * surface.cols + col;
if (covered[at].layer and !covered[at].floating) continue;
- const group_index = if (covered[at].floating) groups.guides else 0;
+ const group_index = if (covered[at].floating) groups.debug else 0;
groups.items[group_index].cell_count = std.math.add(u32, groups.items[group_index].cell_count, cellInstanceCount(&surface.cells[at])) catch return error.GpuCapacity;
}
}
@@ -4609,7 +4608,7 @@ fn renderFrame(
while (col < surface.cols) : (col += 1) {
const at = @as(usize, row) * surface.cols + col;
if (covered[at].layer and !covered[at].floating) continue;
- const group_index = if (covered[at].floating) groups.guides else 0;
+ const group_index = if (covered[at].floating) groups.debug else 0;
emitSurfaceCell(
g,
chrome,
@@ -4762,12 +4761,12 @@ fn resolveCell(g: *Gui, line: []const pardes.Cell, at: usize, cursor: ?usize, ro
const st = cell.style;
fg = switch (st.fg) {
.default => fg_default,
- .index => |i| palColor(i),
+ .index => |i| pardes.colors.xterm[i],
.rgb => |rgb| rgb,
};
switch (st.bg) {
.default => {},
- .index => |i| bg = palColor(i),
+ .index => |i| bg = pardes.colors.xterm[i],
.rgb => |rgb| bg = rgb,
}
if (st.reverse) reverse = !reverse;
@@ -5139,11 +5138,6 @@ fn cellCodepoint(cell: *const pardes.Cell) u32 {
return if (cell.default or grapheme.len == 0) ' ' else firstCp(grapheme);
}
-fn palColor(idx: u8) [3]u8 {
- const p = ghostty_vt.color.default[idx];
- return .{ p.r, p.g, p.b };
-}
-
fn firstCp(s: []const u8) u32 {
if (s.len == 0) return ' ';
const n = std.unicode.utf8ByteSequenceLength(s[0]) catch return ' ';
diff --git a/src/layout.zig b/src/layout.zig
index fca4c846..0cfbf04a 100644
--- a/src/layout.zig
+++ b/src/layout.zig
@@ -180,8 +180,8 @@ pub fn columnDrop(p: *const Pardes, source: usize, x: u16, grab: u16) ColumnDrop
}
/// Share out the width of columns `left` and `left + 1` so the left one is
-/// `left_width` cells, neither below MINW. A border drag and a column grip
-/// dropped inside its own place both end here.
+/// `left_width` cells, neither below MINW. A column grip dropped inside its
+/// own place ends here.
pub fn setColumnPairWidth(p: *Pardes, left: usize, left_width: u64) void {
const v = p.view();
if (left + 1 >= v.ncol) return;
@@ -2099,15 +2099,7 @@ test "repeated non-dyadic column splits preserve every unrelated boundary" {
try std.testing.expect(splitColumn(p, 0, 1, false));
p.sync();
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- const untouched = weightsOf(p);
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = TOPBAR_H + 1 } });
- try std.testing.expectEqual(untouched, weightsOf(p));
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 417, .row = TOPBAR_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 417, .row = TOPBAR_H + 1 } });
+ setColumnPairWidth(p, 0, 418);
p.sync();
try std.testing.expectEqual(@as(u16, 418), p.view().rects[0].w);
diff --git a/src/mouse.zig b/src/mouse.zig
index 783b12b7..2ca984ba 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -1,6 +1,5 @@
//! The mouse: what a pointer is over, the three buttons' presses, drags and
-//! releases (acme's chords, border and seam drags, gestures), and the
-//! chrome targets a shell asks about.
+//! releases (acme's chords, grip and seam drags, gestures).
const pardes = @import("pardes.zig");
const tagline = @import("tagline.zig");
const exec = @import("exec.zig");
@@ -19,7 +18,6 @@ const Pane = panes.Pane;
const MAX_PANES = pardes.MAX_PANES;
const Layer = @import("Layer.zig");
const Jump = @import("Jump.zig");
-const TOPBAR_H = pardes.TOPBAR_H;
const BOX_H = pardes.BOX_H;
const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET;
const Builtin = pardes.Builtin;
@@ -29,7 +27,6 @@ const Pardes = pardes.Pardes;
pub const Drag = union(enum) {
none,
- border_v: struct { left_col: usize, cur_x: u16, corner: ?struct { col: usize, idx: usize } = null, cur_y: u16 = 0 },
border_h: struct { col: usize, top_idx: usize, cur_y: u16 },
move: struct { id: usize, cur_x: u16, cur_y: u16 },
/// `grab`: how far into the grip it was pressed, so the column's left
@@ -58,7 +55,7 @@ pub const Drag = union(enum) {
fn button(drag: Drag) ?Mouse.Button {
return switch (drag) {
.none => null,
- .border_v, .border_h, .move, .column_move => config.select_button,
+ .border_h, .move, .column_move => config.select_button,
.select => |selection| selection.button,
};
}
@@ -126,38 +123,6 @@ fn seamRowOf(p: *const Pardes, c: usize, k: usize) u16 {
return r.y + r.h -| 1;
}
-pub const ChromeTarget = struct { col: u16, row: u16 };
-
-/// The chrome a press at `col`, `row` takes: the tag rows; then,
-/// on the cell, a pane's grip, a column's handle or a seam; then a cell
-/// away, any of a pane's tag, a handle or a seam.
-pub fn chromeTarget(p: *const Pardes, col: u16, row: u16) ?ChromeTarget {
- const v = p.view();
- if (row < p.topBarHeight() + layout.columnBarHeight(p)) return .{ .col = col, .row = row };
- for ([_]u16{ 0, 1 }) |slack| {
- for (p.panes, 0..) |slot, id| {
- const pane = slot orelse continue;
- const rect = v.rects[id];
- const tag = p.tagTop(pane, rect);
- const edge = if (slack == 0) rect.x + config.GUTTER else rect.x + rect.w;
- if (row >= tag and row < tag + pane.tag_rows and col >= rect.x and col < rect.x + rect.w and col < edge)
- return .{ .col = col, .row = row };
- }
- for (0..p.view().ncol -| 1) |column| {
- const handle = v.col_x[column] + v.col_w[column] -| 1;
- if (@max(col, handle) - @min(col, handle) == slack) return .{ .col = handle, .row = row };
- }
- for (0..p.view().ncol) |column| {
- if (col < v.col_x[column] or col >= v.col_x[column] + v.col_w[column]) continue;
- for (0..p.view().cols[column].n -| 1) |index| {
- const seam = seamRowOf(p, column, index);
- if (@max(row, seam) - @min(row, seam) == slack) return .{ .col = col, .row = seam };
- }
- }
- }
- return null;
-}
-
pub fn paneAt(p: *const Pardes, col: u16, row: u16) ?usize {
for (p.panes, 0..) |slot, id| {
if (slot == null) continue;
@@ -781,18 +746,6 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
return;
}
}
- for (0..p.view().ncol -| 1) |c| {
- if (mcol == v.col_x[c] + v.col_w[c] -| 1) {
- const corner: @FieldType(@FieldType(Drag, "border_v"), "corner") = if (seamIdxAt(p, c, mrow)) |k|
- .{ .col = c, .idx = k }
- else if (seamIdxAt(p, c + 1, mrow)) |k|
- .{ .col = c + 1, .idx = k }
- else
- null;
- v.drag = .{ .border_v = .{ .left_col = c, .cur_x = mcol, .corner = corner, .cur_y = mrow } };
- return;
- }
- }
// Two panes are resized on the rule between them, never on a
// row of text; with no rule, by the grip, as acme moves a
// window by its button.
@@ -923,12 +876,6 @@ fn seamIdxAt(p: *const Pardes, c: usize, mrow: u16) ?usize {
return null;
}
-fn clampBorderCol(lx: u16, lw: u16, rw: u16, mcol: u16) u16 {
- const lo = lx + config.MINW;
- const hi = lx +| lw +| rw -| config.MINW;
- return if (lo <= hi) std.math.clamp(mcol, lo, hi) else mcol;
-}
-
fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16) u16 {
const lo = ay + BOX_H - 1;
const hi = ay +| ah +| bh -| (BOX_H + 1);
@@ -938,20 +885,6 @@ fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16) u16 {
pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) void {
const v = p.view();
switch (v.drag) {
- .border_v => |*d| {
- const c = d.left_col;
- d.cur_x = if (c + 1 < v.ncol)
- clampBorderCol(v.col_x[c], v.col_w[c], v.col_w[c + 1], mcol)
- else
- mcol;
- if (d.corner) |k| if (k.idx + 1 < v.cols[k.col].n) {
- const a = v.rects[v.cols[k.col].panes[k.idx]];
- const b = v.rects[v.cols[k.col].panes[k.idx + 1]];
- d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow);
- } else {
- d.cur_y = mrow;
- };
- },
.border_h => |*d| {
const cc = d.col;
const k = d.top_idx;
@@ -1239,18 +1172,6 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
defer v.drag = .none;
defer v.chord_hold = false;
switch (v.drag) {
- .border_v => |d| {
- const c = d.left_col;
- const old_seam = v.col_x[c] + v.col_w[c] -| 1;
- // the handle is the left pane's LAST column (inclusive), so
- // the new width includes it — a no-drag click changes nothing
- if (c + 1 < v.ncol and d.cur_x != old_seam)
- layout.setColumnPairWidth(p, c, (d.cur_x + 1) -| v.col_x[c]);
- if (d.corner) |k| {
- if (d.cur_y != seamRowOf(p, k.col, k.idx))
- layout.applyRowSplit(p, k.col, k.idx, d.cur_y);
- }
- },
.border_h => |d| if (d.cur_y != seamRowOf(p, d.col, d.top_idx))
layout.applyRowSplit(p, d.col, d.top_idx, d.cur_y),
.column_move => |d| if (layout.columnBySerial(p, d.serial)) |column| switch (layout.columnDrop(p, column, d.cur_x, d.grab)) {
@@ -1391,7 +1312,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
const test_metrics: pardes.RowMetrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 };
-fn cornerFixture(gpa: std.mem.Allocator) !*Pardes {
+fn twoColumns(gpa: std.mem.Allocator) !*Pardes {
const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30, .shells = 3 });
p.update(.{ .resize = .{ .cols = 100, .rows = 30 } });
p.view().active = p.view().cols[1].panes[0];
@@ -1463,7 +1384,7 @@ fn layerCenter(layer: *const Layer, col: u16, comptime tag: bool) [2]f32 {
}
test "a pane's last row of text is no resize handle; the rule over the next pane is" {
- const p = try cornerFixture(std.testing.allocator);
+ const p = try twoColumns(std.testing.allocator);
defer p.deinit();
const seam = seamRowOf(p, 1, 0);
const inside = p.view().col_x[1] + p.view().col_w[1] / 2;
@@ -1473,8 +1394,22 @@ test "a pane's last row of text is no resize handle; the rule over the next pane
try std.testing.expect(nudgeRightSeam(p, 2) == seam + 2);
}
+test "the line between two columns is no resize handle: a press there is a sweep in the pane" {
+ const p = try twoColumns(std.testing.allocator);
+ defer p.deinit();
+ const line = p.view().col_x[0] + p.view().col_w[0] - 1;
+ const row = p.view().rects[p.view().cols[0].panes[0]].y + BOX_H + 1;
+ const weight = p.view().cols[0].weight;
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = line, .row = row } });
+ try std.testing.expect(p.view().drag == .select);
+ p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = line + 8, .row = row } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = line + 8, .row = row } });
+ p.sync();
+ try std.testing.expectEqual(weight, p.view().cols[0].weight);
+}
+
test "a pane's grip dragged up or down its own column moves its top, down to the floor of the pane above" {
- const p = try cornerFixture(std.testing.allocator);
+ const p = try twoColumns(std.testing.allocator);
defer p.deinit();
const upper = p.view().cols[1].panes[0];
const lower = p.view().cols[1].panes[1];
@@ -1499,26 +1434,6 @@ test "a pane's grip dragged up or down its own column moves its top, down to the
try std.testing.expectEqual(to, p.view().rects[lower].y);
}
-test "a press near chrome takes it: the tag rows, a column's handle or a seam on its cell or a cell away, a pane's tag; nothing in a body" {
- const p = try cornerFixture(std.testing.allocator);
- defer p.deinit();
- // Column 0's two panes share its rows evenly; column 1's lower one is
- // tall, its middle a body row.
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- const seam = seamRowOf(p, 0, 0);
- const mid = p.view().col_x[0] + p.view().col_w[0] / 2;
- const top = p.view().rects[p.view().cols[0].panes[0]].y;
- const low = p.view().rects[p.view().cols[1].panes[1]];
- const body = low.y + low.h / 2;
- try std.testing.expectEqual(ChromeTarget{ .col = 5, .row = 0 }, chromeTarget(p, 5, 0).?);
- try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle, body).?);
- try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle + 1, body).?);
- try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = seam }, chromeTarget(p, mid, seam).?);
- try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = seam }, chromeTarget(p, mid, seam - 1).?);
- try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = top }, chromeTarget(p, mid, top).?);
- try std.testing.expect(chromeTarget(p, mid, seam - 3) == null);
-}
-
test "plain left click clears explicit modal selection" {
const gpa = std.testing.allocator;
// Wide enough for the tag on one row: the body starts under it.
@@ -1558,144 +1473,6 @@ test "a selection drag and its release leave the selection done" {
try std.testing.expectEqual(.done, pane.sel[sel_slot].state);
}
-test "a corner drag's two axes clamp independently" {
- // a 100-wide window split 50/50, and a 30-row column split 15/14 under the
- // topbar: the shape windowops.snap drives
- const lx: u16 = 0;
- const lw: u16 = 50;
- const rw: u16 = 50;
- const ay: u16 = TOPBAR_H;
- const ah: u16 = 15;
- const bh: u16 = 14;
- const row_lo: u16 = ay + BOX_H - 1;
- const row_hi: u16 = ay + ah + bh - (BOX_H + 1);
-
- // each axis alone, at both walls
- try std.testing.expectEqual(@as(u16, config.MINW), clampBorderCol(lx, lw, rw, 0));
- try std.testing.expectEqual(@as(u16, 100 - config.MINW), clampBorderCol(lx, lw, rw, 999));
- try std.testing.expectEqual(row_lo, clampBorderRow(ay, ah, bh, 0));
- try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999));
-
- // THE corner property: drag off the right edge while staying mid-height —
- // x sits at its wall, y still tracks the mouse row exactly
- try std.testing.expectEqual(@as(u16, 100 - config.MINW), clampBorderCol(lx, lw, rw, 999));
- try std.testing.expectEqual(@as(u16, 12), clampBorderRow(ay, ah, bh, 12));
- // and the mirror: pinned at the bottom, x still free
- try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999));
- try std.testing.expectEqual(@as(u16, 40), clampBorderCol(lx, lw, rw, 40));
- // both pinned at once is just both walls, not a stuck gesture
- try std.testing.expectEqual(@as(u16, config.MINW), clampBorderCol(lx, lw, rw, 0));
- try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999));
-
- // degenerate pairs pass through untouched, each on its own terms: a pane
- // pair with no room stays draggable even when the column pair has room
- try std.testing.expectEqual(@as(u16, 7), clampBorderCol(0, 5, 5, 7));
- try std.testing.expectEqual(@as(u16, 40), clampBorderCol(lx, lw, rw, 40));
- try std.testing.expectEqual(@as(u16, 9), clampBorderRow(TOPBAR_H, 1, 0, 9));
-}
-
-test "a v-handle press at the RIGHT column's seam drags both boundaries" {
- const p = try cornerFixture(std.testing.allocator);
- defer p.deinit();
- try std.testing.expectEqual(@as(usize, 2), p.view().cols[1].n);
-
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- const right_seam = nudgeRightSeam(p, 3);
- try std.testing.expect(right_seam != seamRowOf(p, 0, 0));
-
- const w0 = p.view().cols[0].weight;
- const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight;
- const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight;
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } });
- try std.testing.expect(p.view().drag == .border_v);
- const corner = p.view().drag.border_v.corner orelse return error.NoCorner;
- try std.testing.expectEqual(@as(usize, 1), corner.col);
- try std.testing.expectEqual(@as(usize, 0), corner.idx);
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle + 8, .row = right_seam - 4 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle + 8, .row = right_seam - 4 } });
- p.sync();
-
- // both halves committed: the column pair widened, and the RIGHT column's
- // pane pair reweighted — while the left column's panes stayed put
- try std.testing.expect(p.view().cols[0].weight > w0);
- try std.testing.expect(p.panes[p.view().cols[1].panes[0]].?.vweight != v_right);
- try std.testing.expectEqual(v_left, p.panes[p.view().cols[0].panes[0]].?.vweight);
-}
-
-test "a tie row still moves the LEFT column's pane pair only" {
- const p = try cornerFixture(std.testing.allocator);
- defer p.deinit();
-
- // put column 1's seam exactly on column 0's, the row the eye reads as one
- // line across the whole window
- const left_seam = seamRowOf(p, 0, 0);
- _ = nudgeRightSeam(p, @as(i32, left_seam) - @as(i32, seamRowOf(p, 1, 0)));
- try std.testing.expectEqual(left_seam, seamRowOf(p, 1, 0));
-
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight;
- const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight;
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = left_seam } });
- const corner = p.view().drag.border_v.corner orelse return error.NoCorner;
- try std.testing.expectEqual(@as(usize, 0), corner.col);
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = left_seam - 4 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = left_seam - 4 } });
- p.sync();
- try std.testing.expect(p.panes[p.view().cols[0].panes[0]].?.vweight != v_left);
- try std.testing.expectEqual(v_right, p.panes[p.view().cols[1].panes[0]].?.vweight);
-}
-
-test "a v-handle press at nobody's seam is still a plain edge drag" {
- const p = try cornerFixture(std.testing.allocator);
- defer p.deinit();
- const right_seam = nudgeRightSeam(p, 3);
- const left_seam = seamRowOf(p, 0, 0);
-
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- var row: u16 = TOPBAR_H + 1;
- while (row == left_seam or row == right_seam) row += 1;
-
- const w0 = p.view().cols[0].weight;
- const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight;
- const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight;
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = row } });
- try std.testing.expect(p.view().drag == .border_v);
- try std.testing.expect(p.view().drag.border_v.corner == null);
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle + 8, .row = row + 5 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle + 8, .row = row + 5 } });
- p.sync();
- // exactly ONE boundary moved
- try std.testing.expect(p.view().cols[0].weight > w0);
- try std.testing.expectEqual(v_left, p.panes[p.view().cols[0].panes[0]].?.vweight);
- try std.testing.expectEqual(v_right, p.panes[p.view().cols[1].panes[0]].?.vweight);
-}
-
-test "a RIGHT-column corner's two axes clamp independently" {
- const p = try cornerFixture(std.testing.allocator);
- defer p.deinit();
- const right_seam = nudgeRightSeam(p, 3);
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } });
- try std.testing.expectEqual(@as(usize, 1), (p.view().drag.border_v.corner orelse return error.NoCorner).col);
-
- // off the right edge at mid-height: x parks at its MINW wall, y is the mouse
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 999, .row = right_seam } });
- try std.testing.expectEqual(@as(u16, 100 - config.MINW), p.view().drag.border_v.cur_x);
- try std.testing.expectEqual(right_seam, p.view().drag.border_v.cur_y);
-
- // and the mirror: below the bottom at mid-width. y parks, x tracks again
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = 999 } });
- try std.testing.expectEqual(handle, p.view().drag.border_v.cur_x);
- const a = p.view().rects[p.view().cols[1].panes[0]];
- const b = p.view().rects[p.view().cols[1].panes[1]];
- try std.testing.expectEqual(clampBorderRow(a.y, a.h, b.h, 999), p.view().drag.border_v.cur_y);
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = 999 } });
-}
-
test "mouse thumb buttons navigate once and clear selection gestures" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
defer p.deinit();
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 699b7833..a72e7259 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -699,7 +699,7 @@ pub fn writePager(p: *Pardes, req: Req) Reply {
/// The text a /pager open wrote after its directory (`held`), a program's
/// output for a terminal, put in the +Pager `serial` as `pardes -` once
-/// wrote it to the body: through ghostty-vt (pager.zig), its colours kept
+/// wrote it to the body: through pager.zig's parse, its colours kept
/// as the pane's spans, one undo step, and left
/// clean. Reads of the pane are its plain text. The held bytes go either way.
pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfMemory}!void {
diff --git a/src/pager.zig b/src/pager.zig
index e4ccbab4..dd7e4032 100644
--- a/src/pager.zig
+++ b/src/pager.zig
@@ -1,13 +1,16 @@
//! A program's output, paged into a +Pager (`pardes -`): the text it
-//! prints, and its SGR colours as spans over that text. ghostty-vt, which
-//! terminal panes already drive, parses every escape; this keeps what is
-//! printed and how SGR styles it, and drops every other control (cursor
-//! motion, OSC titles and hyperlinks, modes). The spans are display state
-//! of the pane only: no 9P file reads them (File.recolorSyntax draws them).
+//! prints, and its SGR colours as spans over that text. It reads the bytes
+//! as a terminal does (ECMA-48's parse as ghostty-vt's table has it, UTF-8
+//! with each ill-formed part one U+FFFD) and keeps what is printed, how SGR
+//! styles it and the controls that move along a line (CR, LF, BS, HT and
+//! CSI's CHT, REP and the return in CNL and CPL); every other sequence is
+//! read to its end and dropped (cursor motion, OSC titles and hyperlinks,
+//! DCS, APC, modes). The spans are display state of the pane only: no 9P
+//! file reads them (File.recolorSyntax draws them).
const std = @import("std");
const pardes = @import("pardes.zig");
const CellStyle = @import("surface.zig").CellStyle;
-const ghostty_vt = @import("ghostty-vt");
+const Color = @import("surface.zig").Color;
/// Bytes `start..end` of the text, drawn in `style`. A palette colour stays
/// `.index`, resolved through the theme as it is drawn (terminal.palColor),
@@ -35,15 +38,75 @@ pub fn parse(gpa: std.mem.Allocator, raw: []const u8) !Page {
errdefer h.text.deinit(gpa);
errdefer h.spans.deinit(gpa);
try h.text.ensureTotalCapacity(gpa, raw.len);
- var stream: ghostty_vt.Stream(*Handler) = .init(.{ .handler = &h });
- defer stream.deinit();
- stream.nextSlice(raw);
+ // The printed code points since the last control, printed as one run.
+ var run: [4096]u32 = undefined;
+ var n: usize = 0;
+ var state: State = .ground;
+ var i: usize = 0;
+ feed: while (i < raw.len) {
+ const c = raw[i];
+ if (state != .ground or c == 0x1b) {
+ h.printRun(run[0..n]);
+ n = 0;
+ state = h.step(state, c);
+ i += 1;
+ continue;
+ }
+ // Printable ASCII, most of a page, straight into the run.
+ if (c >= 0x20 and c < 0x7f) {
+ const end = @min(raw.len, i + run.len - n);
+ while (i < end and raw[i] >= 0x20 and raw[i] < 0x7f) : (i += 1) {
+ run[n] = raw[i];
+ n += 1;
+ }
+ if (n < run.len) continue;
+ h.printRun(&run);
+ n = 0;
+ continue;
+ }
+ // UTF-8: an ill-formed part (a stray byte, or the longest start of
+ // a sequence that does not go on) is one U+FFFD; one the input ends
+ // inside may yet go on, and is not printed.
+ var cp: u21 = c;
+ var len: usize = 1;
+ if (c >= 0x80) {
+ cp = 0xfffd;
+ if (c >= 0xc2 and c <= 0xf4) {
+ const want: usize = if (c < 0xe0) 2 else if (c < 0xf0) 3 else 4;
+ const lo: u8 = if (c == 0xe0) 0xa0 else if (c == 0xf0) 0x90 else 0x80;
+ const hi: u8 = if (c == 0xed) 0x9f else if (c == 0xf4) 0x8f else 0xbf;
+ var acc: u21 = c & (@as(u8, 0x7f) >> @intCast(want));
+ while (len < want) : (len += 1) {
+ if (i + len == raw.len) break :feed;
+ const b = raw[i + len];
+ if (b < (if (len == 1) lo else 0x80) or b > (if (len == 1) hi else 0xbf)) break;
+ acc = acc << 6 | (b & 0x3f);
+ }
+ if (len == want) cp = acc;
+ }
+ }
+ i += len;
+ // A C1 control that came as UTF-8 is dropped, as xterm drops it.
+ if (cp >= 0x20 and (cp < 0x80 or cp > 0x9f)) {
+ run[n] = cp;
+ n += 1;
+ if (n < run.len) continue;
+ }
+ h.printRun(run[0..n]);
+ n = 0;
+ if (cp < 0x20) h.execute(@intCast(cp));
+ }
+ h.printRun(run[0..n]);
if (h.failed) return error.OutOfMemory;
const text = try h.text.toOwnedSlice(gpa);
errdefer gpa.free(text);
return .{ .text = text, .spans = try h.spans.toOwnedSlice(gpa) };
}
+/// Where the parse is in a sequence: ECMA-48's states, the DCS's data and
+/// its ignored tail one (`dcs_body`) and SOS, PM and APC one (`apc`).
+const State = enum { ground, esc, esc_inter, csi_entry, csi_param, csi_inter, csi_ignore, osc, dcs_entry, dcs_param, dcs_inter, dcs_body, apc };
+
const Handler = struct {
gpa: std.mem.Allocator,
text: std.ArrayList(u8) = .empty,
@@ -60,43 +123,240 @@ const Handler = struct {
/// A backspace: the next print strikes over the character before it.
bs: bool = false,
failed: bool = false,
+ /// The control sequence being read: its parameters as ghostty-vt keeps
+ /// them (24 at most, each saturating at 65535, a bit in `colons` for
+ /// each one a colon ends), and whether it has an intermediate or a
+ /// private marker, which no sequence kept here takes.
+ csi: struct {
+ params: [24]u16 = undefined,
+ n: u8 = 0,
+ acc: u16 = 0,
+ digits: bool = false,
+ colons: u32 = 0,
+ inter: bool = false,
+ } = .{},
- const Action = ghostty_vt.StreamAction;
-
- pub fn vt(h: *Handler, comptime action: Action.Tag, value: Action.Value(action)) void {
- switch (action) {
- .print => h.print(value.cp),
- .print_slice => h.printRun(value.cps),
- // CSI b repeats the last character, as a terminal draws it;
- // a terminal stops at its edge, and this at a line's worth.
- .print_repeat => if (h.text.items.len > h.last) {
- const cp = std.unicode.utf8Decode(h.text.items[h.last..]) catch return;
- for (0..@min(value, 1024)) |_| h.print(cp);
+ /// The state after byte `c` in `state` (not ground's printing, which
+ /// `parse` decodes), acting on the controls and sequences a page keeps.
+ fn step(h: *Handler, state: State, c: u8) State {
+ switch (c) {
+ 0x18, 0x1a => return .ground,
+ 0x1b => {
+ h.csi = .{};
+ return .esc;
+ },
+ // A C1 control byte, in all but an OSC's or a DCS's data.
+ 0x80...0x9f => return if (state == .osc or state == .dcs_body) state else switch (c) {
+ 0x90 => .dcs_entry,
+ 0x9b => csi: {
+ h.csi = .{};
+ break :csi .csi_entry;
+ },
+ 0x9d => .osc,
+ 0x98, 0x9e, 0x9f => .apc,
+ else => .ground,
+ },
+ 0xa0...0xff => return state,
+ else => {},
+ }
+ switch (state) {
+ .osc => return if (c == 0x07) .ground else .osc,
+ .apc, .dcs_body => return state,
+ .dcs_entry, .dcs_param, .dcs_inter => return switch (c) {
+ 0...0x1f, 0x7f => state,
+ 0x20...0x2f => .dcs_inter,
+ '0'...'9', ';' => if (state == .dcs_inter) .dcs_body else .dcs_param,
+ '<'...'?' => if (state == .dcs_entry) .dcs_param else .dcs_body,
+ else => .dcs_body,
+ },
+ else => {},
+ }
+ if (c < 0x20) {
+ h.execute(c);
+ return state;
+ }
+ if (c == 0x7f) return state;
+ switch (state) {
+ .esc => return switch (c) {
+ '[' => .csi_entry,
+ ']' => .osc,
+ 'P' => .dcs_entry,
+ 'X', '^', '_' => .apc,
+ 0x20...0x2f => .esc_inter,
+ else => .ground,
+ },
+ .esc_inter => return if (c < 0x30) state else .ground,
+ .csi_ignore => return if (c < 0x40) state else .ground,
+ else => {},
+ }
+ const p = &h.csi;
+ switch (c) {
+ 0x20...0x2f => {
+ p.inter = true;
+ return .csi_inter;
+ },
+ '0'...'9', ':', ';' => {
+ if (state == .csi_inter or (c == ':' and state == .csi_entry)) return .csi_ignore;
+ if (p.n == p.params.len) return .csi_param;
+ if (c <= '9') {
+ p.acc = p.acc *| 10 +| (c - '0');
+ p.digits = true;
+ return .csi_param;
+ }
+ p.params[p.n] = p.acc;
+ if (c == ':') p.colons |= @as(u32, 1) << @intCast(p.n);
+ p.n += 1;
+ p.acc = 0;
+ p.digits = false;
+ return .csi_param;
+ },
+ '<'...'?' => {
+ if (state != .csi_entry) return .csi_ignore;
+ p.inter = true;
+ return .csi_param;
+ },
+ else => {
+ h.dispatch(c);
+ return .ground;
},
- .set_attribute => h.attribute(value),
- .linefeed => {
+ }
+ }
+
+ /// A C0 control: the line feeds (LF, VT and FF), CR, BS and HT.
+ fn execute(h: *Handler, c: u8) void {
+ switch (c) {
+ '\n', 0x0b, 0x0c => {
h.append("\n");
h.line_start = h.text.items.len;
h.last = h.line_start;
h.cr = false;
h.bs = false;
},
- .carriage_return => h.cr = true,
- .backspace => h.bs = h.text.items.len > h.line_start,
- .horizontal_tab => for (0..@min(value, 64)) |_| h.print('\t'),
+ '\r' => h.cr = true,
+ 0x08 => h.bs = h.text.items.len > h.line_start,
+ '\t' => h.print('\t'),
else => {},
}
}
- pub fn deinit(_: *Handler) void {}
+ /// The control sequence ending in `f`: SGR, and of the rest what moves
+ /// along a line, dropped as ghostty-vt drops a malformed one.
+ fn dispatch(h: *Handler, f: u8) void {
+ const p = &h.csi;
+ if (p.n == p.params.len) return;
+ if (p.digits) {
+ p.params[p.n] = p.acc;
+ p.n += 1;
+ }
+ if (p.inter or (f != 'm' and p.colons != 0)) return;
+ if (f == 'm') return h.sgr(p.params[0..p.n], p.colons);
+ if (p.n > 1) return;
+ const count: u16 = if (p.n == 0) 1 else p.params[0];
+ switch (f) {
+ // CNL and CPL: down or up, which a page has not, and a return.
+ 'E', 'F' => h.cr = true,
+ // CHT; and REP, the last character again, as a terminal draws
+ // it: a terminal stops at its edge, and this at a line's worth.
+ 'I' => for (0..@min(count, 64)) |_| h.print('\t'),
+ 'b' => if (h.text.items.len > h.last) {
+ const cp = std.unicode.utf8Decode(h.text.items[h.last..]) catch return;
+ for (0..@min(count, 1024)) |_| h.print(cp);
+ },
+ else => {},
+ }
+ }
- // ponytail: bytes that are not UTF-8 reach here as U+FFFD (ghostty's
- // decoder replaces them, as a terminal shows them); a raw-byte pass
- // through the stream if a +Pager must keep them.
+ /// SGR's parameters into the style, read as ghostty-vt's sgr.Parser
+ /// reads them: a colour short of its values leaves them to be read as
+ /// SGRs of their own, and a colon list it does not know is skipped.
+ fn sgr(h: *Handler, params: []const u16, colons: u32) void {
+ const s = &h.style;
+ if (params.len == 0) s.* = .{};
+ var i: usize = 0;
+ while (i < params.len) {
+ const p = params[i..];
+ const colon = colons >> @intCast(i) & 1 != 0;
+ i += 1;
+ // The colons on from p[1], short of the last parameter.
+ var subs: usize = 0;
+ while (i + subs < params.len - 1 and colons >> @intCast(i + subs) & 1 != 0) subs += 1;
+ if (colon and p[0] != 4 and p[0] != 38 and p[0] != 48 and p[0] != 58) {
+ while (colons >> @intCast(i) & 1 != 0) i += 1;
+ i += 1;
+ continue;
+ }
+ switch (p[0]) {
+ 0 => s.* = .{},
+ 1 => s.bold = true,
+ 2 => s.dim = true,
+ 3 => s.italic = true,
+ 4 => if (!colon) {
+ s.ul = .single;
+ } else if (p.len >= 2) {
+ if (colons >> @intCast(i) & 1 != 0) {
+ i += subs + 1;
+ } else {
+ i += 1;
+ s.ul = if (p[1] <= 5) @enumFromInt(p[1]) else .single;
+ }
+ },
+ 5, 6 => s.blink = true,
+ 7 => s.reverse = true,
+ 8 => s.invisible = true,
+ 9 => s.strikethrough = true,
+ 21 => s.ul = .double,
+ // SGR 22 ends faint as well as bold.
+ 22 => {
+ s.bold = false;
+ s.dim = false;
+ },
+ 23 => s.italic = false,
+ 24 => s.ul = .off,
+ 25 => s.blink = false,
+ 27 => s.reverse = false,
+ 28 => s.invisible = false,
+ 29 => s.strikethrough = false,
+ 30...37 => s.fg = .{ .index = @intCast(p[0] - 30) },
+ 39 => s.fg = .default,
+ 40...47 => s.bg = .{ .index = @intCast(p[0] - 40) },
+ 49 => s.bg = .default,
+ 90...97 => s.fg = .{ .index = @intCast(p[0] - 82) },
+ 100...107 => s.bg = .{ .index = @intCast(p[0] - 92) },
+ // A colour: 5 and an index, or 2 and red, green and blue,
+ // after a colour space's slot when colons give one. A cell
+ // has no underline colour (58) to take.
+ 38, 48, 58 => if (p.len >= 2) {
+ var color: ?Color = null;
+ if (p[1] == 5 and p.len >= 3) {
+ i += 2;
+ color = .{ .index = @truncate(p[2]) };
+ } else if (p[1] == 2 and p.len >= 5) {
+ if (colon and subs != 3 and subs != 4) {
+ i += subs + 1;
+ continue;
+ }
+ const at: usize = if (colon and subs == 4) 3 else 2;
+ i += at + 2;
+ color = .{ .rgb = .{ @truncate(p[at]), @truncate(p[at + 1]), @truncate(p[at + 2]) } };
+ }
+ if (color) |ink| switch (p[0]) {
+ 38 => s.fg = ink,
+ 48 => s.bg = ink,
+ else => {},
+ };
+ },
+ else => {},
+ }
+ }
+ }
+
+ // ponytail: bytes that are not UTF-8 reach here as U+FFFD (`parse`
+ // replaces them, as a terminal shows them); a raw-byte pass if a
+ // +Pager must keep them.
fn print(h: *Handler, cp: u21) void {
- // A control a terminal acts on and never draws: ghostty's fast path
- // hands those past 0x0f (CAN, DEL, the C1 set) on as printed text.
- // A tab is HT's, printed here.
+ // A control a terminal acts on and never draws: DEL comes in a run
+ // of printed text, as a terminal's parse hands it on. A tab is
+ // HT's, printed here.
if ((cp < 0x20 and cp != '\t') or (cp >= 0x7f and cp < 0xa0)) return;
if (h.cr) {
h.text.shrinkRetainingCapacity(h.line_start);
@@ -204,42 +464,6 @@ const Handler = struct {
_ = h.spans.pop();
}
}
-
- fn attribute(h: *Handler, attr: ghostty_vt.Attribute) void {
- const s = &h.style;
- switch (attr) {
- .unset => s.* = .{},
- .bold => s.bold = true,
- // SGR 22 ends faint as well as bold.
- .reset_bold => {
- s.bold = false;
- s.dim = false;
- },
- .faint => s.dim = true,
- .italic => s.italic = true,
- .reset_italic => s.italic = false,
- // SGR's styles in a cell's order (terminal.zig checks it).
- .underline => |u| s.ul = @enumFromInt(@intFromEnum(u)),
- .blink => s.blink = true,
- .reset_blink => s.blink = false,
- .inverse => s.reverse = true,
- .reset_inverse => s.reverse = false,
- .invisible => s.invisible = true,
- .reset_invisible => s.invisible = false,
- .strikethrough => s.strikethrough = true,
- .reset_strikethrough => s.strikethrough = false,
- .direct_color_fg => |c| s.fg = .{ .rgb = .{ c.r, c.g, c.b } },
- .direct_color_bg => |c| s.bg = .{ .rgb = .{ c.r, c.g, c.b } },
- .@"8_fg", .@"8_bright_fg" => |name| s.fg = .{ .index = @backingInt(name) },
- .@"8_bg", .@"8_bright_bg" => |name| s.bg = .{ .index = @backingInt(name) },
- .@"256_fg" => |i| s.fg = .{ .index = i },
- .@"256_bg" => |i| s.bg = .{ .index = i },
- .reset_fg => s.fg = .default,
- .reset_bg => s.bg = .default,
- // A cell has no overline and no underline colour to take.
- .overline, .reset_overline, .underline_color, .@"256_underline_color", .reset_underline_color, .unknown => {},
- }
- }
};
// ---- tests ----
@@ -334,7 +558,7 @@ test "every other escape is dropped, and a stray or broken one loses no text aft
.{ "a\r\nb\r\n", "a\nb\n" },
.{ "10%\r50%\r\x1b[K100%\ndone\n", "100%\ndone\n" },
.{ "x\x00y\x07z\x0e\x0f\n", "xyz\n" },
- // Controls ghostty's fast path prints: CAN, FS, DEL and a C1.
+ // Controls that are dropped: CAN, FS, DEL and a C1 as UTF-8.
.{ "x\x18y\x1cz\x7f!\u{85}?\n", "xyz!?\n" },
// A broken CSI: its parameter bytes are eaten up to a final byte, as
// a terminal eats them; CAN abandons one, and the text goes on.
@@ -352,3 +576,20 @@ test "bytes that are not UTF-8 page as U+FFFD, the text around them kept" {
test "a carriage return's rewrite takes the spans of what it rewrote with it" {
try expectPage("\x1b[31m10%\r\x1b[32m100%\x1b[m\n", "100%\n", &.{.{ "100%", .{ .fg = .{ .index = 2 } } }});
}
+
+test "colon colours, an 8-bit CSI, REP, CHT, CNL, a colour short of its values and UTF-8 cut short" {
+ try expectPage("\x1b[38:2::1:2:3mx\x1b[48:5:7my\x1b[m", "xy", &.{
+ .{ "x", .{ .fg = .{ .rgb = .{ 1, 2, 3 } } } },
+ .{ "y", .{ .fg = .{ .rgb = .{ 1, 2, 3 } }, .bg = .{ .index = 7 } } },
+ });
+ // 0x9b in text is a stray byte, U+FFFD; in a sequence (after ESC
+ // here) it is CSI; as UTF-8 (C2 9B) it is a C1 control, dropped.
+ try expectPage("x\x9b\x1b\x9b31mr\xc2\x9b32mg", "x\u{fffd}r32mg", &.{.{ "r32mg", .{ .fg = .{ .index = 1 } } }});
+ // REP and CHT go on along the line; CNL returns, and `d` starts it over.
+ try expectPage("ab\x1b[3b\x1b[2Ic\n", "abbbb\t\tc\n", &.{});
+ try expectPage("ab\x1b[Ed\n", "d\n", &.{});
+ // 38;5 with no index: 38 is unknown and 5 is blink.
+ try expectPage("\x1b[38;5mx", "x", &.{.{ "x", .{ .blink = true } }});
+ try expectPage("ok\xe2\x82", "ok", &.{});
+ try expectPage("\xe2\x82x", "\u{fffd}x", &.{});
+}
diff --git a/src/panes.zig b/src/panes.zig
index 99652b04..29a9f051 100644
--- a/src/panes.zig
+++ b/src/panes.zig
@@ -292,7 +292,7 @@ pub const Pane = struct {
next_pointer_selection: u64 = 0,
/// terminals only: the typed-text buffer standing in for shell rows
- ovl: ?terminal.EditBuffer = null,
+ ovl: ?Text.EditBuffer = null,
tty_filter: bool = false,
msg: [256]u8 = undefined,
msg_len: u16 = 0,
diff --git a/src/surface.zig b/src/surface.zig
index a5dbea8e..c0f352ee 100644
--- a/src/surface.zig
+++ b/src/surface.zig
@@ -4,7 +4,6 @@ const pardes = @import("pardes.zig");
const std = @import("std");
const layout = @import("layout.zig");
const uucode = @import("uucode");
-const vaxis = @import("vaxis");
const panes = @import("panes.zig");
const config = @import("config.zig");
const MAX_PANES = pardes.MAX_PANES;
@@ -205,8 +204,6 @@ pub const Region = struct {
/// A column below the workspace tag, its bar and panes: its left
/// edge is the spine a pixel shell rules down it.
column,
- /// A drag's guide or a seam's hover hint, drawn over the panes.
- guide,
/// The debug stats box, drawn over the panes.
debug,
};
@@ -244,15 +241,9 @@ pub const Region = struct {
/// it shows, in pixels. Its placements are laid at the whole pixel; a
/// pixel frontend draws them the fraction higher.
scroll_px: f64 = 0,
- /// Cells the column-move rail takes off the right edge while it runs
- /// there: layers and pixel shells stop short of them, the grid does not.
- clip: u16 = 0,
};
-/// Guides a frame can draw: a run of a column-move rail per pane it skips
-/// the tags of, and a handful of border and hover dashes.
-pub const MAX_GUIDES = MAX_PANES + 4;
-pub const MAX_REGIONS = 1 + MAX_PANES * (4 + panes.Pane.Notices.max) + pardes.MAX_COLS * 3 + 1 + MAX_GUIDES + 1;
+pub const MAX_REGIONS = 1 + MAX_PANES * (4 + panes.Pane.Notices.max) + pardes.MAX_COLS * 3 + 1 + 1;
/// The colours a pixel shell draws its chrome in (rules, rails, grips, the
/// tag underlay), resolved by the core each frame, so a frontend attached
@@ -425,7 +416,7 @@ pub const Surface = struct {
const width: u16 = if (decoded == null or (cp < 0x80 and cp_slice.len == 1))
1
else
- @max(1, vaxis.gwidth.gwidth(cp_slice, .unicode));
+ @max(1, panes.File.utf8Width(cp_slice));
if (width == 2 and col + 1 >= end) return null;
var shown = cp_slice;
if (shown.len > @typeInfo(@FieldType(Cell, "text")).array.len) {
@@ -472,14 +463,6 @@ pub const Surface = struct {
while (xx < x + w) : (xx += 1) s.at(xx, yy).* = .{};
}
}
-
- /// swap ONLY the glyph, keeping the cell's colors — the resize-handle hint
- pub fn overlayDash(s: *Surface, x: u16, y: u16, glyph: []const u8) void {
- const c = s.at(x, y);
- @memcpy(c.text[0..glyph.len], glyph);
- c.len = @intCast(glyph.len);
- c.default = false;
- }
};
test "cell visual equality ignores dead grapheme tail bytes" {
diff --git a/src/terminal.zig b/src/terminal.zig
index 68b3adde..4ee2e9fa 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -16,7 +16,9 @@ const File = panes.File;
const ghostty_vt = @import("ghostty-vt");
-pub const history_max = 64;
+const EditBuffer = panes.Text.EditBuffer;
+const Snapshot = panes.Text.Snapshot;
+const history_max = panes.Text.history_max;
pub const VtSlot = ghostty_vt.Terminal;
/// A cell of an emulator's pages, as `getCell` reads it (src/echo.zig).
@@ -416,23 +418,6 @@ fn asGhostRgb(rgb: [3]u8) GColor.RGB {
return .{ .r = rgb[0], .g = rgb[1], .b = rgb[2] };
}
-/// The owned text standing in for `rows` live terminal rows, beginning at
-/// absolute surface row `row`. The emulator grid remains untouched underneath.
-pub const EditBuffer = struct {
- row: i32 = 0,
- rows: i32 = 1,
- text: []u8 = &.{},
-};
-
-/// One whole-state terminal edit boundary. Null means the pane has not yet
-/// materialized an edit buffer; non-null snapshots own their text.
-pub const Snapshot = struct {
- ovl: ?EditBuffer,
- cur_row: i32,
- cur_col: i32,
- vsel: panes.Text.CharSel,
-};
-
pub const PendingCommand = struct {
bytes: []u8 = &.{},
wait: enum { none, spawn, input } = .none,
@@ -3420,3 +3405,7 @@ test "a program asking the cell size in pixels (CSI 16 t) is told the shell's" {
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[16t" } });
try std.testing.expectEqualStrings("0:\x1b[6;20;10t\n", try ptyWritesByPane(p, &out));
}
+
+test "colors.xterm is the palette the emulator starts from, all 256" {
+ for (pardes.colors.xterm, ghostty_vt.color.default) |ours, its| try std.testing.expectEqual(ours, [3]u8{ its.r, its.g, its.b });
+}
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index 0daac14b..77c8ce2b 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -3344,3 +3344,17 @@ test "the tty draws a glide at whole rows: once a flick or a spin slows, its ste
try std.testing.expectEqual(row, (shown.cursor orelse return error.NoCursor).y);
}
}
+
+test "the tui's vaxis measures a grapheme as wide as the core lays it out" {
+ // vaxis renders a cell at gwidth(.unicode) in mode 2027; the core's
+ // File.utf8Width is that function over the same uucode tables. A vaxis
+ // that measures otherwise would draw past or short of the core's cells.
+ for ([_][]const u8{
+ "a", "\u{4e16}", "e\u{301}", "\u{301}",
+ "\u{1f642}", "\u{1f44b}\u{1f3ff}", "\u{1f469}\u{200d}\u{1f680}", "\u{1f1fa}\u{1f1f8}",
+ "\u{1f1fa}", "\u{2764}\u{fe0e}", "\u{2764}\u{fe0f}", "1\u{fe0f}\u{20e3}",
+ "\u{1100}\u{1161}", "\u{ff21}", "\u{b1}", "\u{200b}",
+ "\u{ad}", "\u{fffd}", "\u{85}", "\x7f",
+ "a\u{4e16}\u{1f642}", "\u{e0100}", "\u{231a}", "\u{2600}",
+ }) |g| try std.testing.expectEqual(vaxis.gwidth.gwidth(g, .unicode), pardes.panes.File.utf8Width(g));
+}