summaryrefslogtreecommitdiff
path: root/src/Output.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 02:31:20 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitf749eb712d990a9b03f1db372d5311e77bd32edd (patch)
treeee4d9966f1eb293054b7ed865c9d4d6eb49e432b /src/Output.zig
parent8f6621f9f70db86d56266a59b56dfb92b324b0d9 (diff)
parentb3d32656413734952bc918c2d4cfd12fede6c214 (diff)
downloadpardes-f749eb712d990a9b03f1db372d5311e77bd32edd.tar.gz
pardes-f749eb712d990a9b03f1db372d5311e77bd32edd.zip
integration: the terminal behind src/Term.zig, with the diff viewer and the plumber's first phase
A merge of term-phase0 and pardes-next. File.zig's recolorSyntax keeps the theme's grounds and names Term.Filter and Term.Span; the changelog keeps both sides' entries, the palette sentence in the place of the entry the terminal work cut down. core-test 985/985 on tui; the diff, pager and tree process cases pass, goldens unchanged. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/Output.zig')
-rw-r--r--src/Output.zig97
1 files changed, 19 insertions, 78 deletions
diff --git a/src/Output.zig b/src/Output.zig
index 0c6fdfc2..2e49ceb3 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -14,8 +14,6 @@ const lsp = @import("lsp/lsp.zig");
const look = @import("look.zig");
const locations = @import("locations.zig");
const layout = @import("layout.zig");
-const hunks = @import("hunks.zig");
-const diff = @import("diff.zig");
const Pane = panes.Pane;
const File = panes.File;
@@ -414,17 +412,19 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []
result_rows = formatted.rows;
anchor = formatted.anchor;
}
- _ = try fillRows(p, id, dir, from, arg, result_content, result_rows, anchor);
+ _ = try fillRows(p, id, dir, from, null, arg, result_content, result_rows, anchor);
}
/// Rows already laid out (`content`, `rows` its metadata, both taken
/// when it succeeds, the caller's still when it fails) into the pane they
-/// belong in: the one a run of `from` with `arg` in `dir` showed last,
+/// belong in: the one named `name` (null: its origin's own name, as `open`
+/// gives it) that a run of `from` with `arg` in `dir` showed last,
/// refilled, else a new one placed by pane `id`. Its id.
-pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u8, result_content: []u8, result_rows: []locations.Row, anchor: ?usize) !usize {
+pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, name: ?[]const u8, arg: []const u8, result_content: []u8, result_rows: []locations.Row, anchor: ?usize) !usize {
const pane = p.panes[id] orelse return error.MissingPane;
if (arg.len > max_arg) return error.ArgumentTooLong;
const by_arg = std.meta.activeTag(from) != .query;
+ const own = name orelse if (from == .kind) arg else traits(from).name;
for (p.panes, 0..) |slot, i| {
const rp = slot orelse continue;
const rf = if (rp.file) |*f| f else continue;
@@ -440,8 +440,7 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con
if (!shared and !std.meta.eql(o.from, from)) continue;
if (!shared and by_arg and !std.mem.eql(u8, o.arg(), arg)) continue;
if (!std.mem.eql(u8, std.Io.Dir.path.dirname(rf.path) orelse "", dir)) continue;
- if (std.meta.eql(from, Origin{ .cmd = .Diff }) and
- !std.mem.eql(u8, diff.commitHash(rf.content) orelse "", diff.commitHash(result_content) orelse "")) continue;
+ if (!std.mem.eql(u8, std.Io.Dir.path.basename(rf.path), std.Io.Dir.path.basename(own))) continue;
o.from = from;
p.fs.refilled = rp.serial;
try setArg(o, arg);
@@ -451,16 +450,10 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con
File.setContent(p, rf, result_content);
resetBody(p, rp);
}
- if (locations.equalRows(rf.location_rows, result_rows)) {
+ File.setRows(p, rf, result_rows) catch |err| {
locations.freeRows(p.gpa, result_rows);
- } else {
- locations.freeRows(p.gpa, rf.location_rows);
- rf.location_rows = result_rows;
- if (rf.highlights.len > 0) p.tree_sitter_gpa.free(rf.highlights);
- rf.highlights = &.{};
- rf.highlight_start = 0;
- rf.syntax_dirty = true;
- }
+ p.reportError(id, "rows", err);
+ };
p.view().active = id;
if (traits(from).steps) {
pane.search_pane = i;
@@ -470,8 +463,17 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con
return i;
}
const free = p.freeSlot() orelse return error.NoPaneSlots;
+ const path = if (name) |named| try std.fmt.allocPrint(p.gpa, "{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), named }) else null;
+ errdefer if (path) |owned| p.gpa.free(owned);
const np = try open(p, free, dir, from, arg, result_content);
- np.file.?.location_rows = result_rows;
+ if (path) |owned| {
+ p.gpa.free(np.file.?.path);
+ np.file.?.path = owned;
+ }
+ File.setRows(p, &np.file.?, result_rows) catch |err| {
+ locations.freeRows(p.gpa, result_rows);
+ p.reportError(id, "rows", err);
+ };
layout.placeNew(p, id, id, free, .doc);
p.view().active = id;
if (traits(from).steps) {
@@ -482,67 +484,6 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con
return free;
}
-/// Diff: `content`, the diff at `path` (a file, a +Pager), stacked as a
-/// diff viewer shows it (hunks.zig), in a +Diff where its files are found
-/// (hunks.sourceRoot), placed by pane `id`, refilled when it is there. Its
-/// arg names the diff (its base name, or its whole path when the +Diff
-/// stands elsewhere), for Diff to go back to it. The +Diff's id;
-/// NoHunks when there is none in it.
-pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !usize {
- const dir = std.Io.Dir.path.dirname(path) orelse p.sessionDir();
- const root = hunks.sourceRoot(p, dir, content);
- const result = try hunks.format(p, root, content);
- errdefer {
- p.gpa.free(result.content);
- locations.freeRows(p.gpa, result.rows);
- }
- var has_hunk = false;
- for (result.rows) |row| has_hunk = has_hunk or row.kind == .match;
- if (!has_hunk) return error.NoHunks;
- const arg = if (std.mem.eql(u8, root, dir) or path.len > max_arg) std.Io.Dir.path.basename(path) else path;
- const title = if (diff.commitHash(content)) |hash|
- try std.fmt.allocPrint(p.gpa, "{s}/{s}-{s}", .{ std.mem.trimEnd(u8, root, "/"), config.diff_buffer, hash[0..@min(hash.len, 12)] })
- else
- null;
- errdefer if (title) |name| p.gpa.free(name);
- const hid = try fillRows(p, id, root, .{ .cmd = .Diff }, arg, result.content, result.rows, null);
- if (title) |name| {
- const f = &p.panes[hid].?.file.?;
- p.gpa.free(f.path);
- f.path = name;
- }
- return hid;
-}
-
-/// Diff on a +Diff: the diff it stacks, as text. A pane holding it
-/// already (the newest: a +Pager folded under its +Diff unfolds) is
-/// shown; else the file is opened as text.
-pub fn showDiffText(p: *Pardes, id: usize, source: []const u8) void {
- var newest: ?usize = null;
- for (p.panes, 0..) |slot, i| {
- const f = (slot orelse continue).file orelse continue;
- if (!std.mem.eql(u8, f.path, source)) continue;
- if (newest == null or p.panes[newest.?].?.serial < slot.?.serial) newest = i;
- }
- if (newest) |i| {
- if (p.panes[i].?.collapsed) layout.toggleCollapse(p, i);
- p.view().active = i;
- return;
- }
- p.look_text = true;
- defer p.look_text = false;
- look.lookAt(p, id, source);
-}
-
-/// The diff a +Diff stacks (openDiff's arg): its path.
-pub fn diffSource(p: *Pardes, f: *const File.State) ?[]const u8 {
- const o = f.output orelse return null;
- if (!std.meta.eql(o.from, Origin{ .cmd = .Diff })) return null;
- const arg = o.arg();
- if (arg.len > 0 and arg[0] == '/') return arg;
- return std.Io.Dir.path.join(p.scratch.allocator(), &.{ std.Io.Dir.path.dirname(f.path) orelse "", arg }) catch null;
-}
-
pub fn openJumps(p: *Pardes, id: usize) !void {
var out: std.Io.Writer.Allocating = .init(p.gpa);
errdefer out.deinit();