diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-18 23:49:29 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 01:35:13 -0300 |
| commit | 1ca3e68f38385952fa5a2ccc3dac883ba0be71e8 (patch) | |
| tree | bffbbf9e5e5b2b929d79bd81ea805c5288896623 /core/mini.zig | |
| parent | e567aadc19f58b1e36098388483294321f3502dd (diff) | |
| download | pardes-1ca3e68f38385952fa5a2ccc3dac883ba0be71e8.tar.gz pardes-1ca3e68f38385952fa5a2ccc3dac883ba0be71e8.zip | |
core: nothing of a core is a process global, the three that were (pardes-probes P3, the reorganisation's 12c): config.tab_now goes, a tab's width is the core's settings.tab handed to every width function as `tab` (File.graphemeDisplayWidth and the 73 functions above it, test helpers among them, that had no core to read it from gained the parameter; an Editor, a Surface and the hunks' Ctx carry it; render sets Surface.tab; graphemeDisplayWidth asks its one printable ASCII byte before the tab, the two disjoint: with the tab first, as before, the parameter cost 0.2-1.7% instructions an operation in pardes-perf, with ASCII first the measured cells use 2-16% fewer than the base), so a rollback can no longer leave a stale width and replica.zig's hand-made put-back in toConfirmed goes; Addon.distrusted/ndistrusted become Addon.Distrusted, the client's own list, which its frontend owns across its joins and hands each core as Options.distrusted (in no tape, dump or digest: Options' replica .local); Kind.draw_tokens becomes each slot's `draws` (local: a draw is a frame's, so each process's count differs and no digest may hold it; the copy saves it with the slot); the two turn reads in a step stay, being shown unable to reach a client's state (the report); the soak's Proc keeps only the client's list (its tab_now and the global swaps go, forced); test/perf.zig follows three signatures, so unit-test's perf check now says BaselineHarnessMismatch until the baselines are recorded again; tui core-test 824/966 (142 skipped), shell-test 1001/1004, pane-test 183/184, behaviour-test 274/274 and --replay 274/274, process-test 2 of 144 failed (lspcomplete, lspcompletemoved), replicas --clients 5 diverged 0 unequal 0 deltas wrong 0 quiet differ 0 at 30/80/207 ms, gui unit-test 1598/1602, lib-test, daemon.py plain, --far, --games, --window-clients pass
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/mini.zig')
| -rw-r--r-- | core/mini.zig | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/core/mini.zig b/core/mini.zig index b4737f29..9a71bf4a 100644 --- a/core/mini.zig +++ b/core/mini.zig @@ -43,12 +43,12 @@ const Row = struct { ink: bool = false, color: u8 = 0, - fn dot(row: *Row, styles: []const u8) ?u8 { + fn dot(row: *Row, tab: u16, styles: []const u8) ?u8 { if (row.left == 0) { if (row.at == row.text.len) return null; const end = modal.nextGrapheme(row.text, row.at); const grapheme = row.text[row.at..end]; - row.left = File.graphemeDisplayWidth(grapheme); + row.left = File.graphemeDisplayWidth(tab, grapheme); // unreachable below: `generate` refuses a source that is no UTF-8 const n = std.unicode.utf8ByteSequenceLength(grapheme[0]) catch unreachable; const cp = std.unicode.utf8Decode(grapheme[0..n]) catch unreachable; @@ -61,7 +61,7 @@ const Row = struct { } }; -fn render(output: ?Result, source: []const u8, styles: []const u8) !usize { +fn render(tab: u16, output: ?Result, source: []const u8, styles: []const u8) !usize { if (source.len == 0) return 0; const end = source.len - @intFromBool(source[source.len - 1] == '\n'); var lines = std.mem.splitScalar(u8, source[0..end], '\n'); @@ -83,7 +83,7 @@ fn render(output: ?Result, source: []const u8, styles: []const u8) !usize { var counts: [5]u8 = @splat(0); for (&rows, 0..) |*row, y| { for (0..2) |x| { - if (row.dot(styles)) |color| { + if (row.dot(tab, styles)) |color| { mask |= @as(u8, 1) << bits[y][x]; counts[color] += 1; } @@ -122,18 +122,18 @@ fn render(output: ?Result, source: []const u8, styles: []const u8) !usize { return offset; } -pub fn generate(gpa: std.mem.Allocator, source: []const u8, styles: []const u8) !Result { +pub fn generate(tab: u16, gpa: std.mem.Allocator, source: []const u8, styles: []const u8) !Result { if (source.len > max_input_bytes) return error.MiniTooLarge; if (!std.unicode.utf8ValidateSlice(source)) return error.InvalidUtf8; if (styles.len != 0 and styles.len != source.len) return error.InvalidMiniColors; for (styles) |color| if (color > @backingInt(syntax.Syn.comment)) return error.InvalidMiniColors; - const len = try render(null, source, styles); + const len = try render(tab, null, source, styles); const content = try gpa.alloc(u8, len); errdefer gpa.free(content); const colors = try gpa.alloc(u8, len); errdefer gpa.free(colors); const result: Result = .{ .content = content, .colors = colors }; - const written = try render(result, source, styles); + const written = try render(tab, result, source, styles); std.debug.assert(written == len); return result; } @@ -151,7 +151,7 @@ pub fn open(p: *Pardes, id: usize, argument: []const u8) !void { defer p.gpa.free(input); const styles = try syntax.highlightFileRange(p.tree_sitter_gpa, source, input, 0, input.len); defer p.tree_sitter_gpa.free(styles); - const result = try generate(p.gpa, input, styles); + const result = try generate(p.settings.tab, p.gpa, input, styles); errdefer result.deinit(p.gpa); for (p.panes, 0..) |slot, i| { const pane = slot orelse continue; @@ -199,7 +199,7 @@ test "Mini maps every braille dot and partial line group" { for (0..2) |col| source[row * 3 + col] = if (mask & (@as(usize, 1) << bits[row][col]) != 0) 'x' else ' '; source[row * 3 + 2] = '\n'; } - const result = try generate(gpa, &source, ""); + const result = try generate(config.tab_width, gpa, &source, ""); defer result.deinit(gpa); var expected: [4]u8 = undefined; const len: usize = if (mask == 0) 0 else try std.unicode.utf8Encode(@as(u21, 0x2800) + @as(u21, @intCast(mask)), &expected); @@ -216,7 +216,7 @@ test "Mini maps every braille dot and partial line group" { .{ .source = "\n\n\n\nx", .expected = "\n⠁\n" }, .{ .source = "x\r\nx\r\n", .expected = "⠃\n" }, }) |case| { - const result = try generate(gpa, case.source, ""); + const result = try generate(config.tab_width, gpa, case.source, ""); defer result.deinit(gpa); try std.testing.expectEqualStrings(case.expected, result.content); } @@ -229,15 +229,15 @@ test "Mini uses display cells for tabs combining text and wide characters" { .{ .source = " x\n", .expected = " ⠁\n" }, .{ .source = "\u{a0}x\n", .expected = "⠈\n" }, }) |case| { - const result = try generate(gpa, case.source, ""); + const result = try generate(config.tab_width, gpa, case.source, ""); defer result.deinit(gpa); try std.testing.expectEqualStrings(case.expected, result.content); } - const tabs = try generate(gpa, "\tx\n", ""); + const tabs = try generate(config.tab_width, gpa, "\tx\n", ""); defer tabs.deinit(gpa); - const spaces = config.tab_now / 2; + const spaces = config.tab_width / 2; for (tabs.content[0..spaces]) |byte| try std.testing.expectEqual(@as(u8, ' '), byte); - try std.testing.expectEqualStrings(if (config.tab_now % 2 == 0) "⠁\n" else "⠈\n", tabs.content[spaces..]); + try std.testing.expectEqualStrings(if (config.tab_width % 2 == 0) "⠁\n" else "⠈\n", tabs.content[spaces..]); } test "Mini chooses highlighted dots over plain ink with stable color ties" { @@ -245,17 +245,17 @@ test "Mini chooses highlighted dots over plain ink with stable color ties" { const source = "xx\nxx\nxx\nxx\n"; var styles: [source.len]u8 = @splat(0); styles[0] = @backingInt(syntax.Syn.keyword); - const rare = try generate(gpa, source, &styles); + const rare = try generate(config.tab_width, gpa, source, &styles); defer rare.deinit(gpa); try std.testing.expectEqualStrings("⣿\n", rare.content); try std.testing.expectEqualSlices(u8, &.{ 1, 1, 1, 0 }, rare.colors); styles[0] = @backingInt(syntax.Syn.string); styles[1] = @backingInt(syntax.Syn.number); - const tied = try generate(gpa, source, &styles); + const tied = try generate(config.tab_width, gpa, source, &styles); defer tied.deinit(gpa); try std.testing.expectEqualSlices(u8, &.{ 2, 2, 2, 0 }, tied.colors); styles[3] = @backingInt(syntax.Syn.number); - const majority = try generate(gpa, source, &styles); + const majority = try generate(config.tab_width, gpa, source, &styles); defer majority.deinit(gpa); try std.testing.expectEqualSlices(u8, &.{ 3, 3, 3, 0 }, majority.colors); } @@ -263,19 +263,19 @@ test "Mini chooses highlighted dots over plain ink with stable color ties" { test "Mini generation bounds and allocation failures leave no partial result" { const Case = struct { fn run(gpa: std.mem.Allocator) !void { - const result = try generate(gpa, "alpha\nbeta\ngamma\ndelta\nepsilon\n", ""); + const result = try generate(config.tab_width, gpa, "alpha\nbeta\ngamma\ndelta\nepsilon\n", ""); defer result.deinit(gpa); } }; try std.testing.checkAllAllocationFailures(std.testing.allocator, Case.run, .{}); - try std.testing.expectError(error.InvalidMiniColors, generate(std.testing.allocator, "x", &.{5})); - try std.testing.expectError(error.InvalidMiniColors, generate(std.testing.allocator, "xx", &.{0})); + try std.testing.expectError(error.InvalidMiniColors, generate(config.tab_width, std.testing.allocator, "x", &.{5})); + try std.testing.expectError(error.InvalidMiniColors, generate(config.tab_width, std.testing.allocator, "xx", &.{0})); var allocator = std.testing.FailingAllocator.init(std.testing.allocator, .{ .fail_index = 0 }); const source = try std.testing.allocator.alloc(u8, max_input_bytes + 1); defer std.testing.allocator.free(source); - try std.testing.expectError(error.MiniTooLarge, generate(allocator.allocator(), source, "")); + try std.testing.expectError(error.MiniTooLarge, generate(config.tab_width, allocator.allocator(), source, "")); for (source[0..max_input_bytes], 0..) |*byte, i| byte.* = if (i % 2 == 0) 'x' else ' '; - try std.testing.expectError(error.MiniTooLarge, generate(allocator.allocator(), source[0..max_input_bytes], "")); + try std.testing.expectError(error.MiniTooLarge, generate(config.tab_width, allocator.allocator(), source[0..max_input_bytes], "")); try std.testing.expect(!allocator.has_induced_failure); } @@ -327,5 +327,5 @@ test "Mini publishes only complete snapshots and content replacement drops metad } test "Mini refuses a file that is no UTF-8, before its decoding could panic" { - try std.testing.expectError(error.InvalidUtf8, generate(std.testing.allocator, "ok \xff\xfe bad\n\xc3", "")); + try std.testing.expectError(error.InvalidUtf8, generate(config.tab_width, std.testing.allocator, "ok \xff\xfe bad\n\xc3", "")); } |
