summaryrefslogtreecommitdiff
path: root/core/File.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 02:37:06 -0300
committerGabriel Schneider <[email protected]>2026-11-22 02:37:06 -0300
commit58180ae7574b5050331797f0ead1a1cec753b2ed (patch)
tree4a866bdfc968afe58f1f954f969b9c0ab00bc449 /core/File.zig
parent245dd088a5b502c72f94c85bf1cc5bd0ba7ebb56 (diff)
parent2015baa4ccd26a74b51e7b7cda0eb3533a325142 (diff)
downloadpardes-58180ae7574b5050331797f0ead1a1cec753b2ed.tar.gz
pardes-58180ae7574b5050331797f0ead1a1cec753b2ed.zip
integration: the tree to install: every client's terminals by the pty's bytes, and the source view's changes to the whole mock: pardes-flip (`uxzzxrtt`, on pardes-merge54: the one road by default, the old one behind PARDES_TERM_SCREEN until it is deleted; a client takes its road from the session's welcome: the wire at 29; the predicted echo kept on the one road; the user's ruling of 2026-11-22) and pardes-layers-5 (`qurmskql` on `yxupukvr` on `tllltqkq` on `qwvwsoww`, on pardes-layers-4: a terminal's output pays less for the layers with `Changes` off; ghost rows: a line taken away whole red across, each change's description after its last line; a changed line's words by the patch view's alignment; `]g` and `[g`; a description row keeps its author and age, a change's rows come before its own description); no conflict; core-test 911/1075 (164 skipped), shell-test 1117/1120; its gate: .scratch/sketch/reorg/merge55, the numbers in PARDES.md (2026-11-22)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/File.zig')
-rw-r--r--core/File.zig65
1 files changed, 57 insertions, 8 deletions
diff --git a/core/File.zig b/core/File.zig
index 8749417f..347f4809 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -19,6 +19,7 @@ const locations = @import("locations.zig");
const Colors = @import("colors.zig");
const Tables = @import("Tables.zig");
const Stream = @import("Stream.zig");
+const jj = @import("jj.zig");
const Pane = panes.Pane;
const Output = panes.Output;
const Mini = panes.mini;
@@ -399,7 +400,7 @@ pub fn renderedLineDisplayCol(tab: u16, pane: *const Pane, row: i32, line_text:
return prefix +| rawDisplayCol(tab, line_text[prefix..], byte_col - prefix);
}
-fn fitEnd(tab: u16, text: []const u8, start: usize, width: usize) usize {
+pub fn fitEnd(tab: u16, text: []const u8, start: usize, width: usize) usize {
var end = start;
var used: usize = 0;
while (used < width and end < text.len) {
@@ -757,7 +758,7 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
};
reportEdit(p, f, off, len, bytes);
// A pinned change's per-line values ride with the lines (jj.zig).
- if (p.changes.answers.items.len > 0) @import("jj.zig").edited(p, f, off, len, bytes);
+ if (p.changes.answers.items.len > 0) jj.edited(p, f, off, len, bytes);
if (f.mini) |*mini| mini.deinit(p.gpa);
f.mini = null;
if (f.line_starts.len > 0) shiftIndex(p.gpa, f, off, len, bytes);
@@ -1234,6 +1235,7 @@ fn pageEnd(tab: u16, pane: *Pane) usize {
if (pane.wrap_n == 0) return f.scroll + pane.rows;
const last = (if (pane.body_visible_rows > 0) @min(pane.wrap_n, pane.body_visible_rows) else pane.wrap_n) - 1;
const line: usize = @intCast(pane.wrap_line[last]);
+ if (pane.wrap_col[last] < 0) return @max(line, f.scroll + 1);
if (!pane.body_wrapped or line >= nlines(pane.gpa, f)) return line + 1;
const text = sourceLine(pane, @intCast(line));
const width = wrapWidth(pane, pane.view.wrap) -| pane.wrap_pad[last];
@@ -1658,7 +1660,7 @@ fn paintAhead(p: *Pardes, pane: *Pane, f: *State) void {
/// The path a text's language is known by: a file at a revision's
/// (jj.zig) without its `@rev`.
pub fn langPath(f: *const State) []const u8 {
- return if (@import("jj.zig").of(f)) |r| r.path else f.path;
+ return if (jj.of(f)) |r| r.path else f.path;
}
pub fn supportsContext(pane: *const Pane) bool {
@@ -1685,6 +1687,12 @@ fn prepareContextRows(pane: *Pane, file: *State) void {
pub fn wrapWidth(pane: *const Pane, wrap: bool) usize {
if (!wrap or pane.rows > pane.wrap_line.len) return 0;
+ return bodyWidth(pane);
+}
+
+/// The cells a body row has for text after the gutter (and a cell for a
+/// wrapped line's marker).
+pub fn bodyWidth(pane: *const Pane) usize {
return @max(1, @as(usize, pane.cols -| gutterWidth(pane)) -| 1);
}
@@ -1705,7 +1713,8 @@ pub fn visualRow(tab: u16, line: []const u8, col: usize, width: usize) VisualRow
pub fn bodyText(tab: u16, arena: std.mem.Allocator, pane: *Pane, f: *State) ![]const u8 {
geometry(tab, pane);
const out = try arena.alloc(u8, pane.geometry_len);
- const filled = fillBody(tab, out, pane, f, wrapWidth(pane, pane.view.wrap), false);
+ const width = wrapWidth(pane, pane.view.wrap);
+ const filled = if (hasGhosts(pane)) fillBody(true, tab, out, pane, f, width, false) else fillBody(false, tab, out, pane, f, width, false);
std.debug.assert(filled == out.len);
return out;
}
@@ -1749,7 +1758,13 @@ fn mapRows(tab: u16, pane: *Pane, f: *State) usize {
pane.body_wrapped = width > 0;
f.tables.ensure(tab, pane.gpa, f);
prepareContextRows(pane, f);
- return fillBody(tab, null, pane, f, width, true);
+ return if (hasGhosts(pane)) fillBody(true, tab, null, pane, f, width, true) else fillBody(false, tab, null, pane, f, width, true);
+}
+
+/// Whether this view of the pane shows ghost rows (jj.zig): its pinned
+/// changes shown, and some.
+fn hasGhosts(pane: *const Pane) bool {
+ return pane.layers.lanes > 0 and pane.ghosts.len > 0;
}
/// Everything the geometry is made of, hashed: the text (its revision and
@@ -1776,7 +1791,10 @@ fn geometryKey(pane: *const Pane, f: *const State) u64 {
/// Run the file-body row walk. With no destination it is the exact sizing
/// pass; with one it fills that allocation and records the wrapping map.
-fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize {
+/// `ghosted`: the view shows ghost rows (`Pane.ghosts`), each a row of its
+/// own before the line it stands at, no number, its text cut to the row; a
+/// body with none walks without them.
+fn fillBody(comptime ghosted: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize {
if (record_wrap) pane.wrap_n = 0;
const prefix_width = gutterWidth(pane);
// Where a number ends: a blank, then the lanes (laneCells), after it.
@@ -1788,12 +1806,42 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w
var body_line: usize = f.scroll;
var body_at: usize = 0;
var written: usize = 0;
+ // The first ghost row at or below the top line.
+ var ghost: usize = 0;
+ if (ghosted) while (ghost < pane.ghosts.len and pane.ghosts[ghost].at < f.scroll) {
+ ghost += 1;
+ };
for (0..if (pane.body_rows > 0) pane.body_rows else pane.rows) |i| {
if (i > 0) {
if (dst) |out| out[written] = '\n';
written += 1;
}
const context = i < pane.context_rows;
+ if (ghosted and !context and body_at == 0 and ghost < pane.ghosts.len and pane.ghosts[ghost].at == body_line) {
+ const g = pane.ghosts[ghost];
+ const said = pane.ghost_text[g.text..][0..g.len];
+ var fit: [jj.row_max]u8 = undefined;
+ // A description is one compact row whatever the scroll.
+ const shown = if (g.kind == .description)
+ jj.fitted(tab, said, bodyWidth(pane), &fit)
+ else if (width > 0)
+ said[0..fitEnd(tab, said, 0, width)]
+ else
+ said[modal.graphemeStart(said, @min(@as(usize, @intCast(@max(0, pane.hscroll))), said.len))..];
+ if (record_wrap) {
+ pane.wrap_line[i] = @intCast(body_line);
+ pane.wrap_col[i] = -1 - @as(i32, @intCast(ghost));
+ pane.wrap_pad[i] = 0;
+ pane.wrap_n = @intCast(i + 1);
+ }
+ if (dst) |out| {
+ @memset(out[written..][0..prefix_width], ' ');
+ @memcpy(out[written + prefix_width ..][0..shown.len], shown);
+ }
+ written += prefix_width + shown.len;
+ ghost += 1;
+ continue;
+ }
const row = if (context) @as(usize, @intCast(pane.wrap_line[i])) else body_line;
const at = if (context) 0 else body_at;
const text = if (row < total) sourceLine(pane, @intCast(row)) else "";
@@ -1811,7 +1859,7 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w
modal.graphemeStart(text, @min(@as(usize, @intCast(pane.hscroll)), text.len))
else
at;
- if ((width > 0 or pane.context_rows > 0) and record_wrap) {
+ if ((width > 0 or pane.context_rows > 0 or ghosted) and record_wrap) {
pane.wrap_line[i] = @intCast(row);
pane.wrap_col[i] = @intCast(cut);
pane.wrap_pad[i] = @intCast(pad);
@@ -1957,6 +2005,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
limit = line.len;
} else {
if (vr >= pane.wrap_n) break;
+ if (pane.wrap_col[vr] < 0) continue;
const lrow: usize = @intCast(@max(0, pane.wrap_line[vr]));
if (lrow >= total) break;
base = lineStart(p.gpa, f, lrow);
@@ -2104,7 +2153,7 @@ pub fn paintWordSelection(
var vr: i32 = 0;
while (vr + @as(i32, pane.tag_rows) < @as(i32, r.h)) : (vr += 1) {
const here = pane.wrapAt(p.settings.tab, vr);
- if (here.line != row) continue;
+ if (here.line != row or here.ghost) continue;
var hi = word_hi;
const next = pane.wrapAt(p.settings.tab, vr + 1);
if (next.line == row) hi = @min(hi, next.at);