diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 14:20:01 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 14:32:15 -0300 |
| commit | f1b8c2acf131a38a85232c5c268b9b900c21d877 (patch) | |
| tree | ccb3f5f68d58ef2635dea8bdbac6fdd90bd6224b /core/Messages.zig | |
| parent | 89fb37907f34c0a55b85da44ea8f016b3e41081d (diff) | |
| download | pardes-f1b8c2acf131a38a85232c5c268b9b900c21d877.tar.gz pardes-f1b8c2acf131a38a85232c5c268b9b900c21d877.zip | |
Messages: a message too wide for the notice row gives way by its items, each cut showing `…` (UX D2, E5.4, F2): its cause first (a path from its left down to its name, `…Query.zig`; a command from its right down to its pane, `@p2…`), then each path its words and places name, from its left down to its name, and its words last, from the right, two blanks before the right part as before: noticeRow cut a message's whole left from the right, so a long cause path took the row and the words never showed (S2 08b at 26 px: `· /tmp/…/sources/of/th… 3 messages`, the message itself gone), a path in its words was cut on the right (08a: `saved /tmp/…/to/the/sources…`), and the place an error names was cut into (09a: `… exit 1 /tmp/c…`); causeWord's command cut (64 bytes) ends in `…` too (09a: `argument(s), fo exit 1`); the new giveWay walks an item's cells once from the end it cuts (no width sum per byte); a row that fits is built as before, byte for byte; TEST FIRST: Messages "a message too wide for the notice row gives way by its items ..." (08b, 08a and 09a's rows at 97 cells, and a command pane's cause word: fails on the base at Messages.zig:1735, 08b's left not `· …Query.zig the build in the other column finished`); a user hits it whenever a message and its cause or place are wider than the window's foot row; goldens (process-test, regenerated and every changed row read): the notice row of badutf, shellset, savepane, msg (two rows), lookloaded, lsp-rename-files, wrap, tagpath, tagalign (two rows) and wheeldrift now shows the message's words where the cause path took the row (`· …des-snap/msg/cwd/a.txt hand-written report` for `· /tmp/pardes-snap/msg/cwd/a.txt hand-writte…`, `✗ …cmd.txt Shell: shell "zznosuchshell" not found (a name on the…` for `✗ /tmp/pardes-snap/shellset/cwd/cmd.txt Shell: shell "zznosuchsh…`), a path in the words whole (savepane's `saved …/saved.txt`); wrap gains a frame, its `Wrap ×2` now shown where both frames read `✓ /tmp/pardes-snap/wrap…`; nothing else moved
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Messages.zig')
| -rw-r--r-- | core/Messages.zig | 133 |
1 files changed, 124 insertions, 9 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 90194e30..6233f7e5 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -314,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): @@ -733,6 +734,8 @@ 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| { @@ -742,7 +745,12 @@ pub fn noticeRow(p: *Pardes, width: usize, out: *[notice_row_cap]u8) Row { const words = s.words(); const cause = s.src.slice(); const named = if (std.mem.startsWith(u8, cause, "\u{2026}")) cause["\u{2026}".len..] else cause; - if (cause.len > 0 and std.mem.indexOf(u8, words, named) == null) w.print("{s} ", .{cause}) catch {}; + 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 {}; @@ -785,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; @@ -803,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 { @@ -1715,3 +1779,54 @@ test "a cause longer than its word's room keeps the path's end, `…` first, so 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}")); +} |
