summaryrefslogtreecommitdiff
path: root/core/Messages.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Messages.zig')
-rw-r--r--core/Messages.zig62
1 files changed, 56 insertions, 6 deletions
diff --git a/core/Messages.zig b/core/Messages.zig
index 2cb196f6..725f5a99 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -737,15 +737,35 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row {
var keys: [64]u8 = undefined;
if (pardes.TagState.pending(p, p.view(), &keys)) |typed| r.print("{s}{s}", .{ if (r.end > 0) " " else "", typed }) catch {};
const tail = r.buffered();
- // The left cut to make room for the right, a blank between them.
+ // The left cut with `…` to make room for the right, two blanks between
+ // them at least (UX D2): the pane's path from the left, so its name
+ // and line stay (`…core/Store.zig:12`), anything else from the right.
const tail_w = panes.File.displayWidth(tab, tail);
- const room = width -| (tail_w + 1);
+ const room = width -| (if (tail_w > 0) tail_w + 2 else 0);
var cut = left_end;
if (panes.File.displayWidth(tab, out[0..cut]) > room) {
- cut = panes.File.rawAtDisplay(tab, out[0..left_end], room);
- while (cut > 0 and panes.File.displayWidth(tab, out[0..cut]) > room) {
- cut -= 1;
- while (cut > 0 and out[cut] & 0xC0 == 0x80) cut -= 1;
+ if (said == null and lead == null) {
+ var from: usize = 0;
+ while (from < left_end and panes.File.displayWidth(tab, out[from..left_end]) > room -| 1) {
+ from += 1;
+ while (from < left_end and out[from] & 0xC0 == 0x80) from += 1;
+ }
+ var kept: [notice_row_cap]u8 = undefined;
+ const name = kept[0 .. left_end - from];
+ @memcpy(name, out[from..left_end]);
+ w.end = 0;
+ w.writeAll(if (room > 0) "…" else "") catch {};
+ 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;
+ }
+ w.end = cut;
+ w.writeAll(if (room > 0) "…" else "") catch {};
+ cut = w.end;
}
}
w.end = cut;
@@ -1560,3 +1580,33 @@ test "Esc at rest takes a search's tints first, then the warnings and errors, an
try std.testing.expectEqual(@as(u8, 0), p.messages.live_len);
try std.testing.expectEqual(id, p.view().active);
}
+
+test "the notice row's left is cut with `…` two blanks before its right block at least: the pane's path from the left, its name and line kept; a message from the right" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\n");
+ const id = p.view().active;
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try p.gpa.dupe(u8, "/home/someone/projects/a/long/way/down/core/Store.zig");
+ p.messages.live_len = 0;
+ p.messages.len = 0;
+ _ = say(p, .notice, id, "saved");
+ p.messages.live_len = 0;
+ var buf: [notice_row_cap]u8 = undefined;
+ const tab = p.settings.tab;
+ // The path and `1 message · SPC h m`: 40 cells.
+ var row = noticeRow(p, 40, &buf);
+ try std.testing.expect(std.mem.startsWith(u8, row.text, "…") and std.mem.endsWith(u8, row.text[0..row.left], "/Store.zig:1"));
+ try std.testing.expect(std.mem.endsWith(u8, row.text, "1 message \u{b7} SPC h m"));
+ try std.testing.expect(row.right - row.left >= 2);
+ try std.testing.expectEqual(@as(usize, 40), panes.File.displayWidth(tab, row.text));
+ // A live message: cut from the right, `…` at its end.
+ _ = say(p, .@"error", id, "the build failed because something somewhere went badly wrong");
+ row = noticeRow(p, 40, &buf);
+ try std.testing.expect(std.mem.startsWith(u8, row.text, "\u{2717} ") and std.mem.endsWith(u8, row.text[0..row.left], "…"));
+ try std.testing.expect(row.right - row.left >= 2);
+ try std.testing.expect(panes.File.displayWidth(tab, row.text) <= 40);
+ // Room for it all: nothing cut, no `…`.
+ row = noticeRow(p, 200, &buf);
+ try std.testing.expect(std.mem.indexOf(u8, row.text, "…") == null);
+}