summaryrefslogtreecommitdiff
path: root/src/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/File.zig')
-rw-r--r--src/File.zig375
1 files changed, 69 insertions, 306 deletions
diff --git a/src/File.zig b/src/File.zig
index 5150f1cd..d049fc27 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 uucode = @import("uucode");
+const vaxis = @import("vaxis");
const builtin = @import("builtin");
const pardes = @import("pardes.zig");
const config = @import("config.zig");
@@ -13,6 +13,7 @@ const filesystem = @import("fs.zig");
const syntax = @import("syntax.zig");
const diff = @import("diff.zig");
const tracy = @import("tracy.zig");
+const ansi = @import("ansi.zig");
const limits = @import("memory.zig").limits;
const locations = @import("locations.zig");
const Colors = @import("colors.zig");
@@ -21,7 +22,6 @@ const Stream = @import("Stream.zig");
const Pane = panes.Pane;
const Output = panes.Output;
const Mini = panes.mini;
-const terminal = panes.terminal;
const Text = panes.Text;
const SYNTAX_CONTEXT_AFTER_ROWS: usize = 2;
@@ -128,11 +128,11 @@ pub const State = struct {
/// A +Pager whose text is a diff (`git diff`, `show`, `log -p`): drawn
/// and looked at as a diff (Pane.colorAlgo).
pager_diff: bool = false,
- /// A +Pager's colours, as its program printed them (pager.zig): drawn
+ /// A +Pager's colours, as its program printed them (Term.page): drawn
/// over its text by recolorSyntax, never read over 9P. ponytail: any
/// edit drops them (setContentSpan); shifting them through the splice,
/// as pane.zig's shiftOne moves dot, would keep them.
- pager_spans: []pardes.pager.Span = &.{},
+ pager_spans: []pardes.Term.Span = &.{},
/// Seconds of the last content change, for the filesystem's stat; zero until edited.
mtime: u32 = 0,
/// Non-null for a generated output buffer rather than an on-disk file.
@@ -181,13 +181,15 @@ pub const State = struct {
follow: bool = false,
};
-pub const NodeStep = struct { ranges: []modal.Selection, primary: usize };
+pub const NodeStep = @import("Editor.zig").NodeStep;
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, utf8Width(grapheme)));
- // Each invalid byte is a cell, as surface.zig draws it, and each valid
+ 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
// run between is measured alone.
var width: usize = 0;
var run: usize = 0;
@@ -198,60 +200,15 @@ pub fn graphemeDisplayWidth(grapheme: []const u8) usize {
i += n;
continue;
}
- if (run < i) width += utf8Width(grapheme[run..i]);
+ if (run < i) width += vaxis.gwidth.gwidth(grapheme[run..i], .unicode);
width += 1;
i += 1;
run = i;
}
- if (run < grapheme.len) width += utf8Width(grapheme[run..]);
+ if (run < grapheme.len) width += vaxis.gwidth.gwidth(grapheme[run..], .unicode);
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;
@@ -598,7 +555,7 @@ pub fn open(p: *Pardes, id: usize, path: []const u8, line: usize) !*Pane {
std.debug.assert(p.panes[id] == null and !p.reserved_slots[id]);
const path_copy = try p.gpa.dupe(u8, path);
errdefer p.gpa.free(path_copy);
- const pane = try terminal.createDoc(p.gpa, p.view().screen_w, p.view().screen_h);
+ const pane = try panes.createDoc(p.gpa, p.view().screen_w, p.view().screen_h);
errdefer p.gpa.destroy(pane);
const history = try History.create(p.gpa);
errdefer p.gpa.destroy(history);
@@ -660,6 +617,29 @@ pub fn setContent(p: *Pardes, f: *State, new: []u8) void {
setContentSpan(p, f, new, null);
}
+/// `rows`, a row a line of the text from its first (where each points, how
+/// it is coloured: locations.Row), made the pane's, taken: the one way a
+/// pane's rows are set, by a producer in the editor (Output.fillRows, a
+/// query pane) or from outside (the pane's `rows` file). RowsMismatch, the
+/// rows still the caller's, for rows the text cannot hold: more of them
+/// than it has lines, or an offset or styles past its line's end. Rows
+/// equal to the pane's keep its painting; others drop it, to be painted
+/// from them. An edit of the text drops them (setContentSpan).
+pub fn setRows(p: *Pardes, f: *State, rows: []locations.Row) error{RowsMismatch}!void {
+ var lines = std.mem.splitScalar(u8, f.content, '\n');
+ for (rows) |row| {
+ const line = lines.next() orelse return error.RowsMismatch;
+ if (row.location_end > line.len or row.code_start > line.len or row.colors.len > line.len - row.code_start) return error.RowsMismatch;
+ }
+ if (locations.equalRows(f.location_rows, rows)) return locations.freeRows(p.gpa, rows);
+ locations.freeRows(p.gpa, f.location_rows);
+ f.location_rows = rows;
+ if (f.highlights.len > 0) p.tree_sitter_gpa.free(f.highlights);
+ f.highlights = &.{};
+ f.highlight_start = 0;
+ f.syntax_dirty = true;
+}
+
/// `setContent` for a splice that knows what it left alone at either end,
/// so it is not found again by comparing the whole text. The edit is what
/// lies between them, made by `edit`, which takes `new`, a whole text its
@@ -1833,62 +1813,9 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool)
return written;
}
-const SynStyle = struct { fg: [3]u8, bold: bool };
-
-/// How added and removed diff lines are told apart in every theme: a row
-/// ground a little way from the page toward green or red (the theme's own
-/// ANSI green and red where it has a palette), and the prefix column in
-/// that hue, pushed toward the ink until it reads on that ground. The
-/// syntax colours are drawn over the ground unchanged.
-pub const DiffTints = struct {
- added_bg: [3]u8,
- removed_bg: [3]u8,
- /// The words a changed line changed (hunks.zig), on a stronger ground.
- added_emph_bg: [3]u8,
- removed_emph_bg: [3]u8,
- /// A +Diff line added or removed whole: a faint ground.
- added_line_bg: [3]u8,
- removed_line_bg: [3]u8,
- added_fg: [3]u8,
- removed_fg: [3]u8,
+pub const SynStyle = struct { fg: [3]u8, bold: bool };
- pub fn of(p: *Pardes) DiffTints {
- const th = p.theme();
- const page = th.bg orelse th.tag_bg;
- const ink = th.fg orelse th.tag_fg;
- const green: [3]u8 = if (th.palette) |pal| pal[2] else .{ 0x2e, 0xa0, 0x43 };
- const red: [3]u8 = if (th.palette) |pal| pal[1] else .{ 0xcf, 0x22, 0x2e };
- const added_bg = Colors.mixOklab(page, green, 0.18);
- const removed_bg = Colors.mixOklab(page, red, 0.18);
- return .{
- .added_bg = added_bg,
- .removed_bg = removed_bg,
- .added_emph_bg = Colors.mixOklab(page, green, 0.28),
- .removed_emph_bg = Colors.mixOklab(page, red, 0.28),
- .added_line_bg = Colors.mixOklab(page, green, 0.07),
- .removed_line_bg = Colors.mixOklab(page, red, 0.07),
- .added_fg = legible(green, ink, added_bg),
- .removed_fg = legible(red, ink, removed_bg),
- };
- }
-
- fn legible(hue: [3]u8, ink: [3]u8, ground: [3]u8) [3]u8 {
- var fg = hue;
- var step: usize = 0;
- while (step < 4 and Colors.contrast(fg, ground) < 3) : (step += 1) fg = Colors.mixOklab(fg, ink, 0.4);
- return fg;
- }
-
- /// The row ground and prefix ink for a line's style byte, if it is an
- /// added or removed line.
- pub fn forStyle(t: *const DiffTints, style: u8) ?struct { bg: [3]u8, fg: [3]u8, emph_bg: [3]u8, line_bg: [3]u8 } {
- if (style & syntax.diff_added != 0) return .{ .bg = t.added_bg, .fg = t.added_fg, .emph_bg = t.added_emph_bg, .line_bg = t.added_line_bg };
- if (style & syntax.diff_removed != 0) return .{ .bg = t.removed_bg, .fg = t.removed_fg, .emph_bg = t.removed_emph_bg, .line_bg = t.removed_line_bg };
- return null;
- }
-};
-
-fn synStyle(p: *Pardes, sy: syntax.Syn) ?SynStyle {
+pub fn synStyle(p: *Pardes, sy: syntax.Syn) ?SynStyle {
return .{ .fg = Colors.synInk(p.theme(), sy) orelse return null, .bold = false };
}
@@ -1902,15 +1829,13 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
const prefix_width = gutterWidth(pane);
const tz_recolor = tracy.zone(@src(), "synRecolor");
defer tz_recolor.end();
- // A diff's rows, and a +Diff's (hunks.zig): their markers coloured.
- // A diff's whole row is tinted; a +Diff tints only the words a
- // changed line changed.
- const algo = pane.colorAlgo();
- const tints: ?DiffTints = if ((algo == .diff or algo == .locations) and highlights.len > 0) DiffTints.of(p) else null;
- const row_tint = algo == .diff;
- var filtered_storage: terminal.FilteredColors = undefined;
- const filtered: ?*terminal.FilteredColors = if (pane.tty_filter and spans.len > 0) blk: {
- filtered_storage = .init(p, null);
+ // A row whose first byte names a hue (syntax.ground_add, _del): its
+ // grounds, the theme's, worked out once a frame and only for one.
+ var grounds: ?Colors.Grounds = null;
+ const ink = ansi.inkOf(p.theme());
+ var filtered_storage: pardes.Term.Filter = undefined;
+ const filtered: ?*pardes.Term.Filter = if (pane.tty_filter and spans.len > 0) blk: {
+ filtered_storage = pardes.Term.filter(&ink, &p.tty_filter_palette);
break :blk &filtered_storage;
} else null;
// indexed start, same as bodyText — an empty tail simply paints nothing
@@ -1945,21 +1870,22 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
const metadata: ?locations.Row = if (row_index < f.location_rows.len) f.location_rows[row_index] else null;
const decoration = Output.decorateRow(f.output, line, metadata);
const chrome: ?*const pardes.ChromeTheme = if (decoration.plain()) null else p.bodyChrome();
- // An added or removed line's row, every wrapped row of it, is tinted.
- const tint = if (tints) |*t| if (base >= highlight_start and base - highlight_start < highlights.len)
- t.forStyle(highlights[base - highlight_start])
- else
- null else null;
+ // The row's first byte: its hue and its ground, on every wrapped
+ // row of it (syntax.ground_add).
+ const lead: u8 = if (base >= highlight_start and base - highlight_start < highlights.len) highlights[base - highlight_start] else 0;
+ const tint: ?Colors.Grounds.Ground = if (lead & (syntax.ground_add | syntax.ground_del) == 0) null else (grounds orelse ground: {
+ grounds = .of(p.theme());
+ break :ground grounds.?;
+ }).forStyle(lead);
if (tint) |t| if (prefix_width < tw) {
- // A +Diff line added or removed whole: faintly (hunks.zig).
- const whole = highlights[base - highlight_start] & syntax.diff_whole != 0;
- if (row_tint or whole) s.tint(tx + @as(u16, @intCast(prefix_width)), body_y + vr, tw -| @as(u16, @intCast(prefix_width)), if (row_tint) t.bg else t.line_bg, null);
+ const ground: ?[3]u8 = if (lead & syntax.ground_emph != 0) t.row else if (lead & syntax.ground_line != 0) t.line else null;
+ if (ground) |g| s.tint(tx + @as(u16, @intCast(prefix_width)), body_y + vr, tw -| @as(u16, @intCast(prefix_width)), g, null);
};
- // A +Pager's own colours (pager.zig) on every row but one the diff
- // look tints: an added or removed line is drawn as pardes draws a
- // diff, and git's red and green on it would only fight the tint.
- var span_at = if (tint != null) spans.len else std.sort.partitionPoint(pardes.pager.Span, spans, base + hs, struct {
- fn before(at: usize, span: pardes.pager.Span) bool {
+ // A +Pager's own colours (Term.page) on every row but one in a hue:
+ // an added or removed line is drawn as pardes draws a diff, and
+ // git's red and green on it would only fight the tint.
+ var span_at = if (tint != null) spans.len else std.sort.partitionPoint(pardes.Term.Span, spans, base + hs, struct {
+ fn before(at: usize, span: pardes.Term.Span) bool {
return span.end <= at;
}
}.before);
@@ -1991,7 +1917,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
const hidx = idx - highlight_start;
if (hidx < highlights.len) {
if (if (tint != null and hs + c == 0)
- SynStyle{ .fg = tint.?.fg, .bold = true }
+ SynStyle{ .fg = tint.?.ink, .bold = true }
else
synStyle(p, @fromBackingInt(@intCast(highlights[hidx] & syntax.syn_bits)))) |ss|
{
@@ -2003,10 +1929,10 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
cell.style.bold = ss.bold;
}
}
- if (tint) |t| if (highlights[hidx] & syntax.diff_emph != 0) {
+ if (tint) |t| if (highlights[hidx] & syntax.ground_emph != 0 and hs + c > 0) {
var fill: usize = 0;
while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1)
- s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr).style.bg = .{ .rgb = t.emph_bg };
+ s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr).style.bg = .{ .rgb = t.emph };
};
}
}
@@ -2033,11 +1959,11 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
// palette colour through the theme's sixteen and
// truecolor as it is.
if (filtered) |colors| {
- if (st.fg != .default) cell.style.fg = colors.spanColor(st.fg, false);
- if (st.bg != .default) cell.style.bg = colors.spanColor(st.bg, true);
+ if (st.fg != .default) cell.style.fg = pardes.Term.spanColor(colors, st.fg, false);
+ if (st.bg != .default) cell.style.bg = pardes.Term.spanColor(colors, st.bg, true);
} else {
- if (st.fg != .default) cell.style.fg = if (st.fg == .index) terminal.palColor(p, st.fg.index) else st.fg;
- if (st.bg != .default) cell.style.bg = if (st.bg == .index) terminal.palColor(p, st.bg.index) else st.bg;
+ if (st.fg != .default) cell.style.fg = if (st.fg == .index) ink.palColor(st.fg.index) else st.fg;
+ if (st.bg != .default) cell.style.bg = if (st.bg == .index) ink.palColor(st.bg.index) else st.bg;
}
cell.style.bold = cell.style.bold or st.bold;
cell.style.dim = st.dim;
@@ -2055,169 +1981,6 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
}
}
-/// What finished command panes printed, kept while it cannot change: a
-/// copy of the terminal's rows, and whether they are a diff. Taken once
-/// when a finished pane is first drawn, so neither a frame nor a look dumps
-/// the whole scrollback again; a still running command is shown as it
-/// printed. Keyed by the pane and its width (a resize rewraps every row);
-/// a rerun in the pane drops it (exec.runCommand).
-pub const DiffOutput = struct {
- const Entry = struct {
- serial: u32,
- cols: u16,
- is_diff: bool,
- /// The rows joined by '\n'; `rows` are slices of it.
- text: []u8,
- rows: [][]const u8,
- used: u64,
- };
- slots: [4]?Entry = @splat(null),
- clock: u64 = 0,
-
- pub fn reset(o: *DiffOutput, gpa: std.mem.Allocator) void {
- for (&o.slots) |*slot| {
- if (slot.*) |e| {
- gpa.free(e.text);
- gpa.free(e.rows);
- }
- slot.* = null;
- }
- }
-
- /// A pane's command runs again: what it printed before is gone.
- pub fn drop(o: *DiffOutput, gpa: std.mem.Allocator, serial: u32) void {
- for (&o.slots) |*slot| if (slot.*) |e| if (e.serial == serial) {
- gpa.free(e.text);
- gpa.free(e.rows);
- slot.* = null;
- };
- }
-
- /// A finished command pane's rows when they are a diff, else null.
- pub fn lines(o: *DiffOutput, p: *Pardes, pane: *Pane) ?[]const []const u8 {
- if (pane.command == null or !pane.command_done or pane.command_pty or pane.terminal == null) return null;
- o.clock += 1;
- for (&o.slots) |*slot| if (slot.*) |*e| if (e.serial == pane.serial and e.cols == pane.cols) {
- e.used = o.clock;
- return if (e.is_diff) e.rows else null;
- };
- const shown = terminal.shellRows(p, pane) catch return null;
- const is_diff = diff.looksLikeDiff(shown);
- var total: usize = 0;
- if (is_diff) for (shown) |row| {
- total += row.len + 1;
- };
- const text = p.gpa.alloc(u8, total) catch return null;
- const rows = p.gpa.alloc([]const u8, if (is_diff) shown.len else 0) catch {
- p.gpa.free(text);
- return null;
- };
- var at: usize = 0;
- for (rows, 0..) |*row, i| {
- @memcpy(text[at..][0..shown[i].len], shown[i]);
- row.* = text[at..][0..shown[i].len];
- at += shown[i].len;
- text[at] = '\n';
- at += 1;
- }
- // An empty slot, else the least recently used.
- var oldest: usize = 0;
- for (&o.slots, 0..) |*slot, i| {
- const e = slot.* orelse {
- oldest = i;
- break;
- };
- if (e.used < o.slots[oldest].?.used) oldest = i;
- }
- if (o.slots[oldest]) |old| {
- p.gpa.free(old.text);
- p.gpa.free(old.rows);
- }
- o.slots[oldest] = .{ .serial = pane.serial, .cols = pane.cols, .is_diff = is_diff, .text = text, .rows = rows, .used = o.clock };
- return if (is_diff) rows else null;
- }
-};
-
-/// A command pane whose output is a diff (`git diff`, `diff -u`): its
-/// rows coloured as a .diff file's are, over what the program printed.
-/// The rows are the terminal's own, so a line it wrapped goes on in the
-/// row below (syntax.highlightDiffRows).
-pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16, body: []const u8) void {
- if (pane.command == null) return;
- const tz = tracy.zone(@src(), "diffRecolor");
- defer tz.end();
- const rows = p.diff_output.lines(p, pane) orelse return;
- // The copy's rows are one text, joined as a file's lines are.
- const flat_start = @intFromPtr(rows[0].ptr);
- const last = rows[rows.len - 1];
- const flat = rows[0].ptr[0 .. @intFromPtr(last.ptr) + last.len - flat_start];
- const raw = pane.body.mode == .tty;
- const View = struct { row: usize, at: usize };
- const arena = p.scratch.allocator();
- const views = arena.alloc(?View, body_h) catch return;
- var lo: usize = std.math.maxInt(usize);
- var hi: usize = 0;
- var shown = std.mem.splitScalar(u8, body, '\n');
- for (views, 0..) |*view, vi| {
- view.* = null;
- const line = shown.next() orelse continue;
- const vr: i32 = @intCast(vi);
- const w = pane.wrapAt(vr);
- const row_i: i32 = if (raw) terminal.gridOffset(pane) + vr else w.line;
- if (row_i < 0 or row_i >= @as(i64, @intCast(rows.len))) continue;
- const row: usize = @intCast(row_i);
- const from: usize = if (raw) 0 else @intCast(@max(0, w.at));
- if (from > rows[row].len or !std.mem.startsWith(u8, rows[row][from..], line)) continue;
- view.* = .{ .row = row, .at = from };
- const start = @intFromPtr(rows[row].ptr) - flat_start;
- lo = @min(lo, start);
- hi = @max(hi, start + rows[row].len);
- }
- if (lo > hi) return;
- const styles = syntax.highlightDiffRows(arena, flat, lo, hi, true) catch return;
- const tints = DiffTints.of(p);
- const ink = p.theme().fg orelse p.theme().tag_fg;
- const body_y = p.bodyTop(pane, r);
- shown = std.mem.splitScalar(u8, body, '\n');
- for (views, 0..) |maybe, vr| {
- const line = shown.next() orelse break;
- const view = maybe orelse continue;
- const base = @intFromPtr(rows[view.row].ptr) - flat_start - lo;
- const tint = if (base < styles.len) tints.forStyle(styles[base]) else null;
- if (tint) |t| s.tint(tx, body_y + @as(u16, @intCast(vr)), tw, t.bg, null);
- var c: usize = 0;
- var screen_c: usize = 0;
- while (c < line.len and screen_c < tw) {
- const grapheme_end = modal.nextGrapheme(line, c);
- if (grapheme_end <= c) break;
- const cells = graphemeDisplayWidth(line[c..grapheme_end]);
- const style = styles[base + view.at + c];
- const prefix = view.at + c == 0 and (line[0] == '+' or line[0] == '-');
- // On an added or removed line, what the program coloured red or
- // green is the tint's to say now: its code takes the page's ink.
- const paint: ?SynStyle = if (tint != null and prefix)
- .{ .fg = tint.?.fg, .bold = true }
- else if (synStyle(p, @fromBackingInt(@intCast(style & syntax.syn_bits)))) |ss|
- ss
- else if (tint != null)
- .{ .fg = ink, .bold = false }
- else
- null;
- if (paint) |ss| {
- var fill: usize = 0;
- while (fill < cells and screen_c + fill < tw) : (fill += 1) {
- const cell = s.at(tx + @as(u16, @intCast(screen_c + fill)), body_y + @as(u16, @intCast(vr)));
- if (cell.default) continue;
- cell.style.fg = .{ .rgb = ss.fg };
- cell.style.bold = ss.bold;
- }
- }
- screen_c += cells;
- c = grapheme_end;
- }
- }
-}
-
pub fn paintWordSelection(
p: *Pardes,
s: *Surface,
@@ -2249,7 +2012,7 @@ pub fn paintWordSelection(
}
}
-test "an invalid byte in a grapheme is one cell, and never reaches utf8Width" {
+test "an invalid byte in a grapheme is one cell, and never reaches vaxis's width" {
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"));
@@ -2288,11 +2051,11 @@ test "indexed source rows match uncached scans across content changes" {
}
}
-test "the ASCII arm of graphemeDisplayWidth matches the utf8Width it skips" {
+test "the ASCII arm of graphemeDisplayWidth matches the gwidth 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, utf8Width(grapheme)));
+ return @max(1, @as(usize, vaxis.gwidth.gwidth(grapheme, .unicode)));
}
}.width;
@@ -2307,7 +2070,7 @@ test "the ASCII arm of graphemeDisplayWidth matches the utf8Width 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
- // one U+FFFD for the pair would give one.
+ // vaxis's own count gives the pair one.
try std.testing.expectEqual(@as(usize, 2), graphemeDisplayWidth("\xe4\xb8"));
}