diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 14:52:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 14:56:07 -0300 |
| commit | c6dc2a6148855e0f02e86103dd80f47525a985e4 (patch) | |
| tree | b8f5b4fc9da0aac4786fe3e7c04f3b979b304911 /core | |
| parent | f7f6b564c0f43aaa31233dcdf1ae7daf24799fe1 (diff) | |
| parent | 70fcd1b561f6f18e95101633a0f1bcd3f30a0247 (diff) | |
| download | pardes-c6dc2a6148855e0f02e86103dd80f47525a985e4.tar.gz pardes-c6dc2a6148855e0f02e86103dd80f47525a985e4.zip | |
walk UI M10: F1's three fixes (pmqrrmvm a picker previews its first row from the frame its rows come; zzxpztus C-r's history has the band's cursor; qxkzuoyq f7f6b564c0f4 a rolled level that wraps keeps its hints on its last row) and F2's four (nxorurnk a cause longer than its word keeps the path's end; qkynmxtw a message too wide for the notice row gives way by its items, ten goldens; qypmxlxx no `exit N` in a failed run's detail; mkwywzon 70fcd1b561f6 a pane's mark is its window button's glyph) merged onto M9 (svssokqn), resolved by meaning: no text conflict and no file in common (F1: core/Pick.zig, Prompt.zig, TagState.zig; F2: core/Messages.zig, colors.zig, panes.zig, dev/gui/gui.zig and the ten process-test goldens), and none reads what the other changed: F1's head hints and history rows are the tag's and the band's, F2's cuts the notice row's and the window's button, so the two stacks' tests hold each other's trees as they were written; core-test 1102/1273 (171 skipped: M9's 1097 + F1's three tests + F2's two), load 3.4 to 7
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
| -rw-r--r-- | core/Messages.zig | 174 | ||||
| -rw-r--r-- | core/colors.zig | 2 | ||||
| -rw-r--r-- | core/panes.zig | 23 |
3 files changed, 178 insertions, 21 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 72d5193d..6233f7e5 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -297,8 +297,16 @@ pub fn say(p: *Pardes, kind: Kind, id: usize, text: []const u8) *Said { /// A pane as a message names its cause: a file's path (a kind's too), else /// `@pN` and the command it runs. fn causeWord(pane: *const Pane, out: *Buf(96)) void { - if (pane.file) |f| return out.set(f.path); - if (pane.addon) |k| if (k.path.len > 0) return out.set(k.path); + const path = if (pane.file) |f| f.path else if (pane.addon) |k| k.path else ""; + if (path.len > 0) { + if (path.len <= out.bytes.len) return out.set(path); + // Longer than the room: its end, `…` first, so its name is whole + // (UX D2: a path is cut from the left). + var from = path.len - (out.bytes.len - "\u{2026}".len); + while (from < path.len and path[from] & 0xC0 == 0x80) from += 1; + _ = out.print("\u{2026}{s}", .{path[from..]}); + return; + } const line = pane.command orelse { _ = out.print(config.pane_addr ++ "{d}", .{pane.serial}); return; @@ -306,7 +314,8 @@ fn causeWord(pane: *const Pane, out: *Buf(96)) void { const first = line[0 .. std.mem.indexOfAny(u8, line, "\r\n") orelse line.len]; var cut = @min(first.len, 64); while (cut < first.len and cut > 0 and first[cut] & 0xC0 == 0x80) cut -= 1; - _ = out.print(config.pane_addr ++ "{d} {s}", .{ pane.serial, first[0..cut] }); + // A command cut shows it (UX F2: every cut ends in `…`). + _ = out.print(config.pane_addr ++ "{d} {s}{s}", .{ pane.serial, first[0..cut], if (cut < first.len) "\u{2026}" else "" }); } /// Make a message live, and return it (for its places and its detail): @@ -725,13 +734,23 @@ pub fn noticeRow(p: *Pardes, width: usize, out: *[notice_row_cap]u8) Row { var doc_buf: [notice_row_cap]u8 = undefined; const doc = if (said == null) pardes.Band.docLeft(p, &doc_buf) else null; const lead = if (said == null and doc == null) m.headline() else null; + // A message's cause, in bytes of `out`: the first item to give way. + var cause_at: [2]usize = .{ 0, 0 }; if (said != null) {} else if (doc) |line| { w.writeAll(line) catch {}; } else if (lead) |s| { w.print("{s} ", .{s.kind.glyph()}) catch {}; - // Its cause first, unless its words name it already. + // Its cause first, unless its words name it already (a cut one by + // what it kept). const words = s.words(); - if (s.src.len > 0 and std.mem.indexOf(u8, words, s.src.slice()) == null) w.print("{s} ", .{s.src.slice()}) catch {}; + const cause = s.src.slice(); + const named = if (std.mem.startsWith(u8, cause, "\u{2026}")) cause["\u{2026}".len..] else cause; + cause_at = .{ w.end, w.end }; + if (cause.len > 0 and std.mem.indexOf(u8, words, named) == null) { + w.writeAll(cause) catch {}; + cause_at[1] = w.end; + w.writeByte(' ') catch {}; + } w.writeAll(words) catch {}; if (s.n > 1) w.print(" \u{d7}{d}", .{s.n}) catch {}; for (s.places[0..s.places_len], 0..) |*place, i| w.print("{s} {s}:{d}:{d}", .{ if (i > 0) " \u{b7}" else "", place.path.slice(), place.line, place.col }) catch {}; @@ -774,14 +793,38 @@ pub fn noticeRow(p: *Pardes, width: usize, out: *[notice_row_cap]u8) Row { w.writeAll(name) catch {}; cut = w.end; } else { - cut = panes.File.rawAtDisplay(tab, out[0..left_end], room -| 1); - while (cut > 0 and panes.File.displayWidth(tab, out[0..cut]) > room -| 1) { - cut -= 1; - while (cut > 0 and out[cut] & 0xC0 == 0x80) cut -= 1; + // A message (UX D2, F2): its cause gives way first (a path down + // to its name, `…Query.zig`; a command down to its pane, + // `@p2…`), then each path its words and places name, down to + // its name; its words are cut last, from the right below. + if (lead != null) { + var over = panes.File.displayWidth(tab, out[0..left_end]) - room; + var kept: [notice_row_cap]u8 = undefined; + var k: std.Io.Writer = .fixed(&kept); + k.writeAll(out[0..cause_at[0]]) catch {}; + const cause = out[cause_at[0]..cause_at[1]]; + over -|= giveWay(tab, &k, cause, over, !std.mem.startsWith(u8, cause, config.pane_addr) and std.mem.indexOfScalar(u8, cause, '/') != null); + var items = std.mem.splitScalar(u8, out[cause_at[1]..left_end], ' '); + var first = true; + while (items.next()) |item| { + if (!first) k.writeByte(' ') catch {}; + first = false; + if (std.mem.indexOfScalar(u8, item, '/') != null) over -|= giveWay(tab, &k, item, over, true) else k.writeAll(item) catch {}; + } + cut = k.end; + @memcpy(out[0..cut], k.buffered()); + } + if (panes.File.displayWidth(tab, out[0..cut]) > room) { + const end = cut; + cut = panes.File.rawAtDisplay(tab, out[0..end], room -| 1); + while (cut > 0 and panes.File.displayWidth(tab, out[0..cut]) > room -| 1) { + cut -= 1; + while (cut > 0 and out[cut] & 0xC0 == 0x80) cut -= 1; + } + w.end = cut; + w.writeAll(if (room > 0) "…" else "") catch {}; + cut = w.end; } - w.end = cut; - w.writeAll(if (room > 0) "…" else "") catch {}; - cut = w.end; } } w.end = cut; @@ -792,6 +835,38 @@ pub fn noticeRow(p: *Pardes, width: usize, out: *[notice_row_cap]u8) Row { return .{ .left = cut, .right = right_at, .text = w.buffered(), .lead = lead, .quiet_left = said != null, .word = said orelse .{ 0, 0 } }; } +/// `item` written to `w` with `over` cells of it given back where it has +/// them, `…` in their place (UX D2): a path from its left, never into its +/// name (what follows its last `/`); anything else from its right, never +/// into its first word. The cells it gave. +fn giveWay(tab: u16, w: *std.Io.Writer, item: []const u8, over: usize, path: bool) usize { + var edge: usize = if (path) 0 else item.len; + var cells: usize = 0; + if (path) { + const name = if (std.mem.lastIndexOfScalar(u8, item, '/')) |slash| slash + 1 else 0; + while (edge < name and cells < over + 1) { + const next = @min(item.len, edge + (std.unicode.utf8ByteSequenceLength(item[edge]) catch 1)); + cells += panes.File.displayWidth(tab, item[edge..next]); + edge = next; + } + } else { + const first = std.mem.indexOfScalar(u8, item, ' ') orelse item.len; + while (edge > first and cells < over + 1) { + var prev = edge - 1; + while (prev > first and item[prev] & 0xC0 == 0x80) prev -= 1; + cells += panes.File.displayWidth(tab, item[prev..edge]); + edge = prev; + } + } + // The `…` takes a cell of what was given. + if (cells < 2) { + w.writeAll(item) catch {}; + return 0; + } + if (path) w.print("\u{2026}{s}", .{item[edge..]}) catch {} else w.print("{s}\u{2026}", .{item[0..edge]}) catch {}; + return cells - 1; +} + /// What notice band `i` says. The grid pass and the band layers both /// read it here, so a terminal and a pixel shell show the same line. pub fn noticeText(pane: *const Pane, i: usize) []const u8 { @@ -1680,3 +1755,78 @@ test "the notice row's left is cut with `…` two blanks before its right block row = noticeRow(p, 200, &buf); try std.testing.expect(std.mem.indexOf(u8, row.text, "…") == null); } + +test "a cause longer than its word's room keeps the path's end, `…` first, so the file's name is whole (S2 08b at 16 px: `…/core/Query.zi`, its last letter lost)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 24 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + const id = p.view().active; + const long = "/tmp/claude-1000/wS2g16/proj/a/rather/long/way/down/to/the/sources/of/this/project/core/Query.zig"; + p.gpa.free(pane.file.?.path); + pane.file.?.path = try p.gpa.dupe(u8, long); + p.messages.live_len = 0; + const s = say(p, .notice, id, "the build finished"); + try std.testing.expect(std.mem.startsWith(u8, s.src.slice(), "\u{2026}")); + try std.testing.expect(std.mem.endsWith(u8, long, s.src.slice()["\u{2026}".len..])); + // The notice row names the file whole, its words after it. + var buf: [notice_row_cap]u8 = undefined; + var row = noticeRow(p, 190, &buf); + try std.testing.expect(std.mem.endsWith(u8, row.text[0..row.left], "/core/Query.zig the build finished")); + // Words that name the path already leave the cause out, cut or not + // (S2 08a: `saved PATH`). + p.messages.live_len = 0; + _ = say(p, .notice, id, "saved " ++ long); + row = noticeRow(p, 190, &buf); + try std.testing.expectEqualStrings("\u{b7} saved " ++ long, row.text[0..row.left]); +} + +test "a message too wide for the notice row gives way by its items, each cut showing `…`: its cause first (a path down to its name, a command down to its pane), then the paths it names down to theirs, then its words from the right; its right part whole, two blanks before it (UX D2, F2; S2 08a, 08b, 09a at 26 px)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + const id = p.view().active; + const long = "/tmp/claude-1000/wS2g26/proj/a/rather/long/way/down/to/the/sources/of/this/project/core/Query.zig"; + p.gpa.free(pane.file.?.path); + pane.file.?.path = try p.gpa.dupe(u8, long); + p.messages.live_len = 0; + p.messages.len = 0; + const tab = p.settings.tab; + var buf: [notice_row_cap]u8 = undefined; + // 08b: the cause a long path, the words longer than the row. + _ = say(p, .notice, id, "the build in the other column finished with three warnings and one error, the error in a file this pane does not show"); + var row = noticeRow(p, 97, &buf); + var left = row.text[0..row.left]; + try std.testing.expect(std.mem.startsWith(u8, left, "\u{b7} \u{2026}Query.zig the build in the other column finished")); + try std.testing.expect(std.mem.endsWith(u8, left, "\u{2026}")); + try std.testing.expect(row.right - row.left >= 2); + try std.testing.expectEqual(@as(usize, 97), panes.File.displayWidth(tab, row.text)); + // 08a: the words name a path: it is cut from its left, its name whole. + p.messages.live_len = 0; + _ = say(p, .notice, id, "saved " ++ long); + row = noticeRow(p, 97, &buf); + left = row.text[0..row.left]; + try std.testing.expect(std.mem.startsWith(u8, left, "\u{b7} saved \u{2026}")); + try std.testing.expect(std.mem.endsWith(u8, left, "/core/Query.zig")); + try std.testing.expect(row.right - row.left >= 2); + // 09a: a command pane's cause gives way from its right, down to its + // `@pN`, before the place it names: the place stays whole. + p.messages.live_len = 0; + const err = keep(p, .@"error", 0, "@p2 sh -c 'printf \"Store.zig:20:5: error: expected 2 argument(s), found 3", "exit 1"); + err.places[0] = .{ .line = 20, .col = 5 }; + err.places[0].path.set("/tmp/claude-1000/wS2g26/proj/core/Store.zig"); + err.places_len = 1; + row = noticeRow(p, 97, &buf); + left = row.text[0..row.left]; + try std.testing.expect(std.mem.startsWith(u8, left, "\u{2717} @p2 sh -c")); + try std.testing.expect(std.mem.endsWith(u8, left, "\u{2026} exit 1 /tmp/claude-1000/wS2g26/proj/core/Store.zig:20:5")); + try std.testing.expect(std.mem.endsWith(u8, row.text, "SPC e walk")); + try std.testing.expect(row.right - row.left >= 2); + // A command's echo cut for its word ends in `…` too (S2 09a: `fo exit 1`). + pane.command = try p.gpa.dupe(u8, "sh -c 'printf \"Store.zig:20:5: error: expected 2 argument(s), found 3\\n\"; exit 1'"); + const file = pane.file; + pane.file = null; + defer pane.file = file; + var word: Buf(96) = .{}; + causeWord(pane, &word); + try std.testing.expect(std.mem.endsWith(u8, word.slice(), "\u{2026}")); +} diff --git a/core/colors.zig b/core/colors.zig index 4f58aed5..61af2e4a 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -733,7 +733,7 @@ fn toward(ink: [3]u8, ground: [3]u8, floor: f32) [3]u8 { /// `ink` pushed by fiftieths toward white or black, whichever reads better /// on all its grounds, until it reads at `floor` on every one; where no ink /// does (solarized's mid-grey tag), that end, the most any ink reaches. -fn pushAway(ink: [3]u8, grounds: []const [3]u8, floor: f32) [3]u8 { +pub fn pushAway(ink: [3]u8, grounds: []const [3]u8, floor: f32) [3]u8 { const white: [3]u8 = @splat(255); const black: [3]u8 = @splat(0); if (leastContrast(ink, grounds) >= floor) return ink; diff --git a/core/panes.zig b/core/panes.zig index 6fcb15b6..fe127acd 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -1071,6 +1071,14 @@ pub const Pane = struct { } var buf: [16]u8 = undefined; const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16 + // A failed run's last rows, read before its `exit N` goes under + // them: a report's places are at its end, and its detail is the + // tool's lines, not the run's status (UX F2). + const rows: ?[]const []const u8 = if (status == 0) null else if (pane.terminal) |state| read: { + const grid = Term.grid(state); + const first = grid.total -| 400; + break :read Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch null; + } else null; var said: pardes.Kind.Buf(32) = .{}; const lead = if (Term.grid(pane.terminal).cursor_x != 0) "\r\n" else ""; pane.feedOutput(p, said.print("{s}exit {s}\r\n", .{ lead, code })); @@ -1078,21 +1086,17 @@ pub const Pane = struct { p.needs_frame = true; // A failed run whose report names places (a compiler's // `path:line:col: error: ...`): an error of this pane, the places - // its words, the rows after its first its detail (SPEC §10.2). Its - // last rows only: a report's places are at its end. - if (status != 0) if (pane.terminal) |state| report: { - const grid = Term.grid(state); - const first = grid.total -| 400; - const rows = Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch break :report; + // its words, the rows after its first its detail (SPEC §10.2). + if (rows) |report_rows| report: { var found: pardes.Messages.Said = .{}; - if (pardes.Messages.readPlaces(&found, pane.cwdSlice(), rows) == 0) break :report; + if (pardes.Messages.readPlaces(&found, pane.cwdSlice(), report_rows) == 0) break :report; var words: pardes.Kind.Buf(32) = .{}; const kept = pardes.Messages.say(p, .@"error", id, words.print("exit {s}", .{code})); kept.places = found.places; kept.places_len = found.places_len; kept.detail = found.detail; kept.detail_len = found.detail_len; - }; + } } }; @@ -1981,6 +1985,9 @@ test "a command whose run fails naming places is an error of its pane, those pla try std.testing.expectEqual(@as(u8, 1), said.places_len); try std.testing.expectEqualStrings("/tmp/pardes-cmd/core/pick.zig", said.places[0].path.slice()); try std.testing.expectEqualStrings(" const best = rank(q, name, 3);", said.detail[0].slice()); + // The tool's lines alone: pardes's own `exit 1` under them is the run's + // status, in the command's tag and on the notice row (UX F2). + try std.testing.expectEqual(@as(u8, 1), said.detail_len); var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const s = try p.render(frame.allocator()); |
