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/body_layer.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/body_layer.zig')
| -rw-r--r-- | core/body_layer.zig | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/core/body_layer.zig b/core/body_layer.zig index 101bbe9c..73c9dd48 100644 --- a/core/body_layer.zig +++ b/core/body_layer.zig @@ -29,7 +29,7 @@ const Layer = @import("Layer.zig"); // ---- drawing a pane body into the surface ---- fn paintTerminalSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: []const Pane.PointerRow, bg: [3]u8, fg: ?[3]u8) void { - const body = bodyText(p.scratch.allocator(), pane) catch return; + const body = bodyText(p.settings.tab, p.scratch.allocator(), pane) catch return; const raw = pane.body.mode == .tty; const tx = r.x + config.GUTTER; const width = r.w -| config.GUTTER; @@ -38,7 +38,7 @@ fn paintTerminalSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: [ var visible: i32 = 0; while (lines.next()) |line| : (visible += 1) { if (visible >= r.h -| pane.tag_rows) break; - const source_row = if (raw) @as(i32, @intCast(panes.Term.grid(pane.terminal).offset)) + visible else pane.wrapAt(visible).line; + const source_row = if (raw) @as(i32, @intCast(panes.Term.grid(pane.terminal).offset)) + visible else pane.wrapAt(p.settings.tab, visible).line; for (rows) |row| { const target = if (row.raw_terminal) (if (raw) row.row else pane.surfRow(row.row)) @@ -51,15 +51,15 @@ fn paintTerminalSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: [ lo -|= row.prompt_bytes; hi -|= row.prompt_bytes; } else if (!row.raw_terminal and raw) { - const prefix = panes.Term.promptPrefix(pane.terminal, source_row, line); + const prefix = panes.Term.promptPrefix(p.settings.tab, pane.terminal, source_row, line); lo += prefix; hi += prefix; } lo = modal.graphemeStart(line, @min(lo, line.len)); hi = @min(hi, line.len); if (lo >= hi) continue; - const col = panes.File.rawDisplayCol(line, lo); - const end = @min(width, if (row.to_edge and hi == line.len) width else panes.File.rawDisplayCol(line, hi)); + const col = panes.File.rawDisplayCol(p.settings.tab, line, lo); + const end = @min(width, if (row.to_edge and hi == line.len) width else panes.File.rawDisplayCol(p.settings.tab, line, hi)); if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(visible)), @intCast(end - col), bg, fg); } } @@ -68,13 +68,13 @@ fn paintTerminalSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: [ /// Whether `col` lies past the last column its visible row shows: the last /// visible row of a line owns every column after its start (wrapRow), so a /// head millions of bytes along a long line is on that row, off the view. -fn pastView(pane: *Pane, body: []const u8, line: i32, row: i32, at: i32, col: i32, tw: u16) bool { +fn pastView(tab: u16, pane: *Pane, body: []const u8, line: i32, row: i32, at: i32, col: i32, tw: u16) bool { const text = if (pane.file != null) panes.File.sourceLine(pane, line) else modal.lineSlice(body, @intCast(@max(0, row))); const from: usize = @intCast(@max(0, at)); const to: usize = @intCast(@max(0, col)); if (from >= text.len) return to >= from +| tw; // A file row's last shown byte counts its table pads (File.rowPads). - const shown: usize = if (pane.file != null) @intCast(panes.File.byteAtRowDisplay(pane, line, at, tw)) else from + panes.File.byteAtDisplay(text[from..], tw); + const shown: usize = if (pane.file != null) @intCast(panes.File.byteAtRowDisplay(tab, pane, line, at, tw)) else from + panes.File.byteAtDisplay(tab, text[from..], tw); return to >= shown and to < text.len; } @@ -87,10 +87,10 @@ fn paintSourceSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: []c const prefix: i32 = if (pane.file != null) panes.File.gutterWidth(pane) else 0; var visible: i32 = 0; while (visible < @as(i32, r.h -| pane.tag_rows)) : (visible += 1) { - const source = pane.wrapAt(visible); + const source = pane.wrapAt(p.settings.tab, visible); const line = edit.pointerSourceLine(pane, terminal_lines, source.line); const start = @min(line.len, @as(usize, @intCast(@max(0, source.at)))); - const next = pane.wrapAt(visible + 1); + const next = pane.wrapAt(p.settings.tab, visible + 1); const end = if (next.line == source.line) @min(line.len, @as(usize, @intCast(@max(0, next.at)))) else line.len; for (rows) |row| { if (row.row != source.line) continue; @@ -99,13 +99,13 @@ fn paintSourceSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: []c if (lo >= hi) continue; // A file row through its pads (File.rowPads), as it is drawn. const col = prefix + source.pad + if (pane.file != null) - panes.File.displayOffset(pane, source.line, @intCast(start), @intCast(lo)) + panes.File.displayOffset(p.settings.tab, pane, source.line, @intCast(start), @intCast(lo)) else - @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], lo - start))); + @as(i32, @intCast(panes.File.rawDisplayCol(p.settings.tab, line[start..], lo - start))); const last = @min(width, if (row.to_edge and hi == end) @as(i32, width) else prefix + source.pad + if (pane.file != null) - panes.File.displayOffset(pane, source.line, @intCast(start), @intCast(hi)) + panes.File.displayOffset(p.settings.tab, pane, source.line, @intCast(start), @intCast(hi)) else - @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], hi - start)))); + @as(i32, @intCast(panes.File.rawDisplayCol(p.settings.tab, line[start..], hi - start)))); if (col < last) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(visible)), @intCast(last - col), bg, fg); } } @@ -172,7 +172,7 @@ pub fn joinBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, if (pane.file == null) return renderBody(p, s, arena, pane, r, id, active, rail); // The pane's geometry as it is (File.geometry): made by the step that // moved it if one read it, else here, and the same either way. - panes.File.geometry(pane); + panes.File.geometry(p.settings.tab, pane); // Which rows are context rows is decided by the text the body shows: a // layer taller than the grid's rows when there are any. if (pane.collapsed or r.h <= pane.tag_rows or pane.body_rows == 0) @@ -185,7 +185,7 @@ pub fn joinBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count); const temporary_cells = try arena.alloc(Cell, @as(usize, r.w) * (logical_rows + pane.tag_rows)); @memset(temporary_cells, .{}); - var temporary: Surface = .{ .cols = r.w, .rows = @intCast(logical_rows + pane.tag_rows), .cells = temporary_cells }; + var temporary: Surface = .{ .cols = r.w, .rows = @intCast(logical_rows + pane.tag_rows), .cells = temporary_cells, .tab = p.settings.tab }; const synthetic: Rect = .{ .x = 0, .y = 0, .w = r.w, .h = @intCast(logical_rows + pane.tag_rows) }; try renderBody(p, &temporary, arena, pane, synthetic, id, active, null); for (0..logical_rows) |row| { @@ -307,7 +307,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane }; const tz_body = tracy.zone(@src(), "bodyText"); const probe_text = pardes.FrameStats.nowNs(); - const body = try bodyText(arena, pane); + const body = try bodyText(p.settings.tab, arena, pane); p.frames.zone(.body_text, probe_text); tz_body.end(); // A select sweep begun on the tag and dragged into the body marks the @@ -401,7 +401,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane colors.mix(th.sel_bg, page_rgb); var vr: i32 = 0; while (vr + @as(i32, pane.tag_rows) < @as(i32, body_bottom)) : (vr += 1) { - const w = pane.wrapAt(vr); + const w = pane.wrapAt(p.settings.tab, vr); if (w.line < bnd.lo_row or w.line > bnd.hi_row) continue; const visible_line = modal.lineSlice(body, @intCast(vr)); // Only the visible columns are measured: a selection that @@ -415,24 +415,24 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane const shown_to = if (row_at >= row_text.len) row_text.len else if (pane.file != null) - @as(usize, @intCast(panes.File.byteAtRowDisplay(pane, w.line, w.at, tw))) + @as(usize, @intCast(panes.File.byteAtRowDisplay(p.settings.tab, pane, w.line, w.at, tw))) else - row_at + panes.File.byteAtDisplay(row_text[row_at..], tw); + row_at + panes.File.byteAtDisplay(p.settings.tab, row_text[row_at..], tw); const past_view = if (shown_to >= row_text.len) std.math.maxInt(usize) else shown_to; // A row that ends before the selection starts has none of it. if (w.line == bnd.lo_row and @as(usize, @intCast(@max(0, bnd.lo_col))) >= past_view) continue; const cstart: i32 = if (w.line == bnd.lo_row and bnd.lo_col > w.at) (if (pane.file != null) - panes.File.displayOffset(pane, w.line, w.at, bnd.lo_col) + panes.File.displayOffset(p.settings.tab, pane, w.line, w.at, bnd.lo_col) else - panes.File.lineDisplayOffset(visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.lo_col)))) + vpfx + w.pad + panes.File.lineDisplayOffset(p.settings.tab, visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.lo_col)))) + vpfx + w.pad else vpfx + w.pad; const cend: i32 = if (w.line == bnd.hi_row and @as(usize, @intCast(@max(0, bnd.hi_col))) < past_view) (if (pane.file != null) - panes.File.displayEndOffset(pane, w.line, w.at, bnd.hi_col) + panes.File.displayEndOffset(p.settings.tab, pane, w.line, w.at, bnd.hi_col) else - panes.File.lineDisplayEndOffset(visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.hi_col)))) + vpfx + w.pad + panes.File.lineDisplayEndOffset(p.settings.tab, visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.hi_col)))) + vpfx + w.pad else @as(i32, tw) - 1; const col: i32 = @max(cstart, vpfx); @@ -441,16 +441,16 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane } if (primary and !preview and !hover_only) continue; // the hardware cursor IS the primary's if (hover_only) continue; // quiet preview preserves the source ink - const cw = pane.wrapRow(sr.row, sr.col); + const cw = pane.wrapRow(p.settings.tab, sr.row, sr.col); // A head off the view is measured not at all: its row is not // drawn, and its column may be millions of bytes along. if (cw.row < 0 or cw.row + @as(i32, pane.tag_rows) >= @as(i32, body_bottom)) continue; - if (pastView(pane, body, sr.row, cw.row, cw.at, sr.col, tw)) continue; + if (pastView(p.settings.tab, pane, body, sr.row, cw.row, cw.at, sr.col, tw)) continue; const crow = cw.row + @as(i32, pane.tag_rows); const ccol = (if (pane.file != null) - panes.File.displayOffset(pane, sr.row, cw.at, sr.col) + panes.File.displayOffset(p.settings.tab, pane, sr.row, cw.at, sr.col) else - panes.File.lineDisplayOffset( + panes.File.lineDisplayOffset(p.settings.tab, modal.lineSlice(body, @intCast(@max(0, cw.row))), @intCast(@max(0, cw.at)), @intCast(@max(0, sr.col)), @@ -475,11 +475,11 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane for ([_]u8{ letters[i / letters.len], letters[i % letters.len] }) |letter| { const pos = modal.positionAt(flat, at); const row: i32 = @intCast(pos.row); - const wp = pane.wrapRow(row, @intCast(pos.col)); + const wp = pane.wrapRow(p.settings.tab, row, @intCast(pos.col)); const cx = if (pane.file != null) - @as(i32, panes.File.gutterWidth(pane)) + wp.pad + panes.File.displayOffset(pane, row, wp.at, @intCast(pos.col)) + @as(i32, panes.File.gutterWidth(pane)) + wp.pad + panes.File.displayOffset(p.settings.tab, pane, row, wp.at, @intCast(pos.col)) else - panes.File.lineDisplayOffset(modal.lineSlice(flat, pos.row), @intCast(@max(0, wp.at)), pos.col); + panes.File.lineDisplayOffset(p.settings.tab, modal.lineSlice(flat, pos.row), @intCast(@max(0, wp.at)), pos.col); if (wp.row >= 0 and wp.row < body_h and cx >= 0 and cx < tw) s.set(tx + @as(u16, @intCast(cx)), body_y + @as(u16, @intCast(wp.row)), &.{letter}, style); at = modal.nextGrapheme(flat, at); @@ -494,17 +494,17 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane const grid = panes.Term.grid(pane.terminal); const crow = if (pane.body.cur_pinned) pane.body.cur_row else pane.surfRow(@as(i32, grid.cursor_y) + @as(i32, @intCast(grid.offset))); const ccol = if (pane.body.cur_pinned) pane.body.cur_col else @as(i32, grid.cursor_x); - const cwp = pane.wrapRow(crow, ccol); + const cwp = pane.wrapRow(p.settings.tab, crow, ccol); const prow = cwp.row + @as(i32, pane.tag_rows); // Off the view, the cursor is not measured (its column may be // millions of bytes along a line whose start is shown). - if (cwp.row >= 0 and prow < body_bottom and !pastView(pane, body, crow, cwp.row, cwp.at, ccol, tw)) { + if (cwp.row >= 0 and prow < body_bottom and !pastView(p.settings.tab, pane, body, crow, cwp.row, cwp.at, ccol, tw)) { // Files store source-byte columns; the Surface stores display // cells, so account for every expanded tab before the cursor. const cx = if (pane.file != null) - @as(i32, panes.File.gutterWidth(pane)) + cwp.pad + panes.File.displayOffset(pane, crow, cwp.at, ccol) + @as(i32, panes.File.gutterWidth(pane)) + cwp.pad + panes.File.displayOffset(p.settings.tab, pane, crow, cwp.at, ccol) else if (pane.body.cur_pinned) - panes.File.lineDisplayOffset( + panes.File.lineDisplayOffset(p.settings.tab, modal.lineSlice(body, @intCast(@max(0, cwp.row))), @intCast(@max(0, cwp.at)), @intCast(@max(0, ccol)), @@ -540,13 +540,13 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane }; } -pub fn bodyText(arena: std.mem.Allocator, pane: *Pane) ![]const u8 { +pub fn bodyText(tab: u16, arena: std.mem.Allocator, pane: *Pane) ![]const u8 { if (pane.addon != null) { const buf = try arena.alloc(u8, pane.rows -| 1); @memset(buf, '\n'); return buf; } - if (pane.file) |*f| return panes.File.bodyText(arena, pane, f); + if (pane.file) |*f| return panes.File.bodyText(tab, arena, pane, f); // A terminal's: the rows its view shows (outside raw mode its prompts // cut off), the edit copy's lines over the rows the copy covers. const vp: []const []const u8 = if (pane.terminal) |state| try panes.Term.viewport(state, arena, pane.body.mode != .tty) else &.{}; |
