summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Core.zig112
-rw-r--r--core/Handover.zig4
-rw-r--r--core/config.zig16
-rw-r--r--core/draw.zig40
-rw-r--r--core/dump.zig24
-rw-r--r--core/edit.zig24
-rw-r--r--core/keys.zig4
-rw-r--r--core/layout.zig75
-rw-r--r--core/mouse.zig52
-rw-r--r--core/ninep/cols.zig24
-rw-r--r--core/replica.zig4
-rw-r--r--core/root.zig37
-rw-r--r--core/tagline.zig232
13 files changed, 491 insertions, 157 deletions
diff --git a/core/Core.zig b/core/Core.zig
index a22822c2..ccdc8d6f 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -1001,24 +1001,11 @@ fn setLastDumpInner(p: *Pardes, path: []const u8) void {
ctlfs.events.notePath(p, "dump", path);
}
-/// The workspace tag's `Restore <path>` names `path` from now on: the
-/// default's does by itself, and one the tag was edited around (its own
-/// text) has the old path swapped, never left pointing at a dump that is
-/// not the last.
+/// The window row's `Restore <path>` names `path` from now on: a computed
+/// word (UX K'2, tagline.headerWords), never the user's text.
pub fn pointRestoreAt(p: *Pardes, path: []const u8) void {
const copy = p.gpa.dupe(u8, path) catch |err| return p.reportError(.at(p.view().active), "Restore", err);
- if (p.last_dump) |old| {
- if (p.global_tag.own) |own| swap: {
- const a = p.scratch.allocator();
- const was = std.fmt.allocPrint(a, "Restore {s}", .{old}) catch break :swap;
- if (std.mem.indexOf(u8, own, was) == null) break :swap;
- const now = std.fmt.allocPrint(a, "Restore {s}", .{path}) catch break :swap;
- const swapped = std.mem.replaceOwned(u8, p.gpa, own, was, now) catch break :swap;
- p.gpa.free(own);
- p.global_tag.own = swapped;
- }
- p.gpa.free(old);
- }
+ if (p.last_dump) |old| p.gpa.free(old);
p.last_dump = copy;
}
@@ -1977,7 +1964,9 @@ pub fn sync(p: *Pardes) void {
// A file opened or closed this step: the kept list follows.
p.saveRecent();
tagline.flattenHeaders(p);
- if (p.headerColumn() != null and layout.columnBarHeight(p) == 0) {
+ // A column's tag with no row to be in lets the keyboard go; a lone
+ // column's keeps it in the window row (UX K'2).
+ if (p.headerColumn() != null and layout.columnBarHeight(p) == 0 and !layout.columnInWindowRow(p)) {
tagline.exitHeader(p);
}
pardes.panes.reapPanes(p);
@@ -2549,25 +2538,30 @@ test "topbar hover highlights exactly the executable word" {
defer frame.deinit();
_ = try p.render(frame.allocator());
- p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 1, .row = 0 } });
- _ = frame.reset(.retain_capacity);
- const hovered = try p.render(frame.allocator());
- for (0.."Newcol".len) |col| {
- const cell = hovered.at(TAG_TEXT_INSET + @as(u16, @intCast(col)), 0);
- try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, cell.style.bg);
- try std.testing.expectEqual(Color{ .rgb = p.theme().sel_fg }, cell.style.fg);
- }
- try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(TAG_TEXT_INSET + 6, 0).style.bg);
+ // Each side of the window row (UX K'2): the lone column's `New`, then
+ // the window's `Find`.
+ const words = tagline.windowRow(p).words;
+ for ([_]struct { at: u16, len: u16 }{ .{ .at = TAG_TEXT_INSET, .len = "New".len }, .{ .at = words, .len = "Find".len } }) |word| {
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = word.at + 1, .row = 0 } });
+ _ = frame.reset(.retain_capacity);
+ const hovered = try p.render(frame.allocator());
+ for (0..word.len) |col| {
+ const cell = hovered.at(word.at + @as(u16, @intCast(col)), 0);
+ try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, cell.style.bg);
+ try std.testing.expectEqual(Color{ .rgb = p.theme().sel_fg }, cell.style.fg);
+ }
+ try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(word.at + word.len, 0).style.bg);
- p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 6, .row = 0 } });
- _ = frame.reset(.retain_capacity);
- const whitespace = try p.render(frame.allocator());
- try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(TAG_TEXT_INSET + 1, 0).style.bg);
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = word.at + word.len, .row = 0 } });
+ _ = frame.reset(.retain_capacity);
+ const whitespace = try p.render(frame.allocator());
+ try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(word.at + 1, 0).style.bg);
+ }
p.update(.pointer_leave);
_ = frame.reset(.retain_capacity);
const left = try p.render(frame.allocator());
- try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(TAG_TEXT_INSET + 1, 0).style.bg);
+ try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(words + 1, 0).style.bg);
}
test "pane-tag Exec prefers Term and argument builtins before shell fallback" {
@@ -3757,18 +3751,17 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" {
try std.testing.expect(look.expandedSel(p, pane, .{ .state = .dragging, .c0 = separator, .c1 = separator, .r0 = BOX_H, .r1 = BOX_H }) == null);
}
-test "the workspace tag's Restore word names the last dump, the tag edited around it or not, across a Restore too" {
+test "the window row's Restore word names the last dump, the user's text after it, across a Restore too (UX K'2)" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true });
defer p.deinit();
p.setLastDump("/tmp/a.zon");
- // The tag edited: its own text holds the Restore word as it was then.
- p.global_tag.own = try p.gpa.dupe(u8, try std.fmt.allocPrint(p.scratch.allocator(), "{s} Mine", .{tagline.headerDefault(p, .workspace)}));
+ p.global_tag.own = try p.gpa.dupe(u8, "Mine");
p.setLastDump("/tmp/b.zon");
- try std.testing.expect(std.mem.indexOf(u8, p.global_tag.own.?, "Restore /tmp/b.zon Mine") != null);
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Restore /tmp/b.zon Mine", tagline.topbar(p));
try dump.dumpState(p);
const restored = try dump.restore(p, p.dump_out.?, "/tmp/c.zon");
defer restored.deinit();
- try std.testing.expect(std.mem.indexOf(u8, restored.global_tag.own.?, "Restore /tmp/c.zon Mine") != null);
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Restore /tmp/c.zon Mine", tagline.topbar(restored));
try std.testing.expectEqualStrings("/tmp/c.zon", restored.last_dump.?);
}
@@ -3777,27 +3770,45 @@ test "editable workspace and column tags are typed into and persist" {
defer p.deinit();
_ = try p.setTestFile("untouched\n");
p.presented();
- try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y);
+ // One column: its tag in the window row, no column row (UX K'2).
+ try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y);
+ const words = tagline.windowRow(p).words;
// a sweep over a header is its selection, the caret where it ended
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = 0 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = TAG_TEXT_INSET + 6, .row = 0 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET + 6, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = words, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = words + 6, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = words + 6, .row = 0 } });
try std.testing.expect(p.global_tag.vsel.active and p.global_tag.vsel.col == 0 and p.global_tag.cur_col == 6);
- // A clicked header is in normal mode: `a` types after the sweep's
- // last character, the blank it ended on.
+ // A clicked header is in normal mode: `a` types after the sweep's last
+ // character, in the computed words: refused, they are no one's.
p.update(.{ .key = .{ .cp = 'a', .text = "a" } });
p.update(.{ .key = .{ .cp = 'H', .text = "Help " } });
- try std.testing.expect(std.mem.startsWith(u8, p.global_tag.own.?, "Newcol Help Joincol"));
+ try std.testing.expect(p.global_tag.own == null);
p.update(.{ .key = .{ .cp = Key.escape } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = TOPBAR_H } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET, .row = TOPBAR_H } });
+ // After them, the user's text.
+ const end: u16 = @intCast(words + "Find Grep Newcol Help Exit ".len);
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = end, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = end, .row = 0 } });
+ p.update(.{ .key = .{ .cp = 'i', .text = "i" } });
+ p.update(.{ .key = .{ .cp = 'H', .text = "Help " } });
+ try std.testing.expectEqualStrings("Help ", p.global_tag.own.?);
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Help ", tagline.topbar(p));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // The column's tag, at the window row's left: typed into, it has the
+ // user's text and the column row comes for it; emptied, it goes.
+ const own: u16 = TAG_TEXT_INSET + "New Term ".len;
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = own, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = own, .row = 0 } });
+ try std.testing.expectEqual(@as(?usize, 0), p.headerColumn());
p.update(.{ .key = .{ .cp = 'i', .text = "i" } });
p.update(.{ .key = .{ .cp = 'é', .text = "é" } });
- try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "éNew"));
+ try std.testing.expectEqualStrings("New Term é", tagline.columnTag(p, 0));
+ try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y);
p.update(.{ .key = .{ .cp = Key.backspace } });
- try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "New"));
+ try std.testing.expectEqualStrings("New Term ", tagline.columnTag(p, 0));
+ try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y);
+ try std.testing.expectEqual(@as(?usize, 0), p.headerColumn());
p.update(.{ .paste = "Grep " });
- try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "Grep New"));
+ try std.testing.expectEqualStrings("New Term Grep ", tagline.columnTag(p, 0));
try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content);
try dump.dumpState(p);
const restored = try dump.restore(p, p.dump_out.?, "test");
@@ -3809,7 +3820,7 @@ test "editable workspace and column tags are typed into and persist" {
try dump.dumpState(p);
const empty = try dump.restore(p, p.dump_out.?, "test");
defer empty.deinit();
- try std.testing.expectEqualStrings("", tagline.columnTag(empty, 0));
+ try std.testing.expectEqualStrings("New Term ", tagline.columnTag(empty, 0));
}
test "column tag first-cell execution keeps New local to the clicked column" {
@@ -3837,6 +3848,7 @@ test "a screen too short for the column row releases a column tag's focus withou
defer p.deinit();
const pane = try p.setTestFile("unchanged body\n");
p.view().col_tags[0].own = try p.gpa.dupe(u8, "New Help");
+ p.sync();
p.presented();
const shown = p.view().rects[0];
try std.testing.expectEqual(TOPBAR_H + COLBAR_H, shown.y);
@@ -3850,7 +3862,7 @@ test "a screen too short for the column row releases a column tag's focus withou
try std.testing.expect(p.view().header == null and p.headerColumn() == null);
p.update(.{ .resize = .{ .cols = 60, .rows = 12 } });
try std.testing.expectEqual(shown, p.view().rects[0]);
- try std.testing.expectEqualStrings("New Help", tagline.columnTag(p, 0));
+ try std.testing.expectEqualStrings("New Term New Help", tagline.columnTag(p, 0));
try std.testing.expectEqualStrings("unchanged body\n", pane.file.?.content);
}
diff --git a/core/Handover.zig b/core/Handover.zig
index 6f7340b2..f60ce72b 100644
--- a/core/Handover.zig
+++ b/core/Handover.zig
@@ -628,6 +628,10 @@ test "a column let go over another window goes beside the column the pointer is
const gpa = std.testing.allocator;
const from = try twoPanes(gpa);
defer from.deinit();
+ // A column's grip is in the column row, which a second column brings
+ // (UX K'2).
+ try std.testing.expect(from.executeBuiltinLine(0, "Newcol"));
+ from.sync();
const r = from.view().rects[0];
const c = layout.findPane(from, 0).?.col;
from.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = from.view().col_x[c], .row = from.topBarHeight() } });
diff --git a/core/config.zig b/core/config.zig
index d916b677..5df9b1b1 100644
--- a/core/config.zig
+++ b/core/config.zig
@@ -238,8 +238,20 @@ pub const child_term = "xterm-256color";
pub const child_colorterm = "truecolor";
pub const child_term_program = "pardes";
-// Fonts is the window's word alone (the font picker), so a terminal build's
-// row has no such builtin to name: the window's row and the terminal's.
+/// The window row's words (UX K'2): at its right end, `Restore <dump>`
+/// after them once a dump exists (tagline.headerWords). The rest of the
+/// words that left it run from `:`, their keys and typed (K'4).
+pub const window_words_str = "Find Grep Newcol Help Exit";
+/// A column's words: at the window row's left while there is one column,
+/// in its column tag with several, where Joincol and Delcol have a
+/// column to act on.
+pub const column_words_str = "New Term";
+pub const columns_words_str = "New Term Joincol Delcol";
+
+// The window's tag before UX K', its own text then: a dump's own text equal
+// to one is dropped (dump.dropOldTags), and /tagexec still takes their words
+// (ninep/cols.zig paneWord). Fonts is the window's word alone (the font
+// picker), so a terminal build's row has no such builtin to name.
pub const topbar_window_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Fonts Config History Debug Exit";
pub const topbar_terminal_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit";
pub const topbar_str = if (@import("builtins.zig").capabilities.font_picker) topbar_window_str else topbar_terminal_str;
diff --git a/core/draw.zig b/core/draw.zig
index 2553d5be..c156352f 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -152,6 +152,12 @@ pub fn place(p: *Pardes, s: *Surface) void {
}
}
const column_rows = layout.columnBarHeight(p);
+ // A lone column's tag at the window row's left (UX K'2): no grip, a
+ // column's edge has nothing to be dragged against.
+ if (layout.columnInWindowRow(p)) {
+ const inset = @min(TAG_TEXT_INSET, v.screen_w);
+ s.addRegion(.{ .kind = .column_tag, .owner = 0, .serial = v.cols[0].serial, .active = layout.findPane(p, v.active) != null, .rect = .{ .x = inset, .y = 0, .w = tagline.windowRow(p).column, .h = p.topBarHeight() } });
+ }
if (column_rows > 0) for (0..p.view().ncol) |c| {
if (v.col_w[c] == 0) continue;
const active = if (layout.findPane(p, v.active)) |found| found.col == c else false;
@@ -583,25 +589,31 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void {
if (s.region(.workspace_tag, Region.none)) |region| {
const top = if (v.header != null and p.headerColumn() == null) v.header_top else 0;
const layer = &s.tag_layers[MAX_PANES + MAX_COLS];
- var viewport = region.rect;
- s.chrome.tagline_rows = @intCast(viewport.y + viewport.h);
- const inset = @min(TAG_TEXT_INSET, viewport.w);
- s.fill(viewport.x, viewport.y, inset, viewport.h, .{ .bg = .{ .rgb = chrome.tagline_bg }, .fg = .{ .rgb = chrome.tagline_fg }, .font_role = .tagline });
- viewport.x += inset;
- viewport.w -= inset;
- try renderHeaderLayer(p, layer, .workspace, 0, viewport, tagline.topbar(p), top, chrome.tagline_bg, chrome.tagline_fg);
+ s.chrome.tagline_rows = @intCast(region.rect.y + region.rect.h);
+ // The window row (UX K'2), on the tagline's ground end to end: a
+ // lone column's tag at its left (its region), in the row's inks;
+ // the window's at its right end (tagline.windowRow).
+ s.fill(region.rect.x, region.rect.y, region.rect.w, region.rect.h, .{ .bg = .{ .rgb = chrome.tagline_bg }, .fg = .{ .rgb = chrome.tagline_fg }, .font_role = .tagline });
+ if (s.region(.column_tag, 0)) |column| if (column.rect.y < region.rect.y + region.rect.h) {
+ const column_top = if (v.header != null and p.headerColumn() == 0) v.header_top else 0;
+ const column_layer = &s.tag_layers[MAX_PANES];
+ try renderHeaderLayer(p, column_layer, .column, 0, column.rect, tagline.columnTag(p, 0), column_top, chrome.tagline_bg, chrome.tagline_fg);
+ joinHeaderRows(s, column_layer, chrome.tagline_fg);
+ };
+ const words = tagline.windowRow(p).words;
+ const viewport: Rect = .{ .x = words, .y = region.rect.y, .w = region.rect.w -| words, .h = region.rect.h };
+ const text = tagline.topbar(p);
+ try renderHeaderLayer(p, layer, .workspace, 0, viewport, text, top, chrome.tagline_bg, chrome.tagline_fg);
// A server's progress (a message of no pane) at its first row's
// right end, where the row has room for it.
- if (layer.rows > 0 and top == 0) for (p.messages.live[0..p.messages.live_len]) |*said| {
- if (said.kind != .progress or said.pane != 0) continue;
+ if (layer.rows > 0 and top == 0) if (tagline.sessionProgress(p)) |said| {
var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined;
- const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break;
- const width = panes.File.displayWidth(p.settings.tab, text);
- const used = panes.File.displayWidth(p.settings.tab, modal.lineSlice(tagline.topbar(p), 0));
+ const shown = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch "";
+ const width = panes.File.displayWidth(p.settings.tab, shown);
+ const used = panes.File.displayWidth(p.settings.tab, modal.lineSlice(text, 0));
const room = layout.tagCapacity(p, viewport.w);
var row: Surface = .{ .cols = layer.cols, .rows = 1, .cells = layer.cells[0..layer.cols], .tab = p.settings.tab };
- if (used + 2 + width < room) _ = row.print(@intCast(room - 1 - width), 0, @intCast(width), text, .{ .fg = .{ .rgb = Messages.ink(chrome, .progress) }, .bg = .{ .rgb = chrome.tagline_bg }, .font_role = .tagline });
- break;
+ if (used + 2 + width < room) _ = row.print(@intCast(room - 1 - width), 0, @intCast(width), shown, .{ .fg = .{ .rgb = Messages.ink(chrome, .progress) }, .bg = .{ .rgb = chrome.tagline_bg }, .font_role = .tagline });
};
joinHeaderRows(s, layer, chrome.tagline_fg);
}
diff --git a/core/dump.zig b/core/dump.zig
index 2806e445..ad436ac5 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -667,13 +667,29 @@ fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previ
/// is dropped, its words computed now (K'1); any other is the user's text,
/// kept as it is. Here, where a Restore, a start from a dump and an
/// Upgrade load (a replica's join loads its authority's, dropped there).
+/// The window's and the columns' tags the same (UX K'2): the window row of
+/// either build, with its `Restore <path>` or without, and the column tag
+/// it had.
fn dropOldTags(p: *Pardes) void {
for (p.panes) |slot| if (slot) |pane| if (pane.tag.own) |own| {
- if (!std.mem.eql(u8, own, pardes.tagline.kindTail(pane))) continue;
- p.gpa.free(own);
- pane.tag.own = null;
- pane.tag.cur_pinned = false;
+ if (std.mem.eql(u8, own, pardes.tagline.kindTail(pane))) dropOwn(p, &pane.tag);
};
+ const window: []const u8 = p.global_tag.own orelse "";
+ for ([_][]const u8{ pardes.config.topbar_window_str, pardes.config.topbar_terminal_str }) |old| {
+ if (!std.mem.startsWith(u8, window, old)) continue;
+ if (window.len != old.len and !std.mem.startsWith(u8, window[old.len..], " Restore ")) continue;
+ dropOwn(p, &p.global_tag);
+ break;
+ }
+ for (&p.views) |*slot| if (slot.*) |*v| for (v.col_tags[0..v.ncol]) |*t| {
+ if (t.own) |own| if (std.mem.eql(u8, own, pardes.tagline.column_tag_default)) dropOwn(p, t);
+ };
+}
+
+fn dropOwn(p: *Pardes, t: *pardes.panes.Text) void {
+ p.gpa.free(t.own.?);
+ t.own = null;
+ t.cur_pinned = false;
}
/// A loaded core given to this host (with `revivePane` for each of its
diff --git a/core/edit.zig b/core/edit.zig
index fa442fca..12cd7706 100644
--- a/core/edit.zig
+++ b/core/edit.zig
@@ -540,7 +540,8 @@ pub fn flatSurface(e: Editor, t: *Text) Error![]const u8 {
// the tag as it is shown: the keyboard reaches its prefix too
.tag => return if (t.pane()) |pane| try tagline.tagText(e.p, e.scratch, pane) else "",
.input => return t.own orelse "",
- .column, .workspace => return t.own orelse if (comptime Editor.lib) "" else tagline.headerDefault(e.p, t.what),
+ // a header as it is shown: its computed words, then its own text
+ .column, .workspace => return if (comptime Editor.lib) t.own orelse "" else try tagline.headerText(e.p, t),
}
const pane = t.pane() orelse return "";
if (pane.file) |f| return f.content;
@@ -576,14 +577,13 @@ pub fn paneWrapWidth(e: Editor, t: *Text) usize {
/// Route shared edit operations to the characters `t` edits: its own, or
/// for a body its file's content or its terminal's overlay.
fn editText(e: Editor, t: *Text, lo: i32, hi: i32, col: i32) Error!?panes.EditText {
- // A tag or header nobody has changed shows its default; the first edit
- // makes that default its own text.
+ // A tag or a header is edited as it is shown, its computed words and
+ // all; what an edit leaves after them is its own text (setEditTextSpan).
if (t.what == .tag) {
const pane = t.pane() orelse return null;
return .{ .text = try tagline.tagText(e.p, e.scratch, pane), .row0 = 0 };
}
- if (t.what != .body and t.what != .input and t.own == null)
- t.own = try e.gpa.dupe(u8, try flatSurface(e, t));
+ if (comptime !Editor.lib) if (t.what == .column or t.what == .workspace) return .{ .text = try tagline.headerText(e.p, t), .row0 = 0 };
if (t.what != .body or comptime Editor.lib) return .{ .text = t.own orelse &.{}, .row0 = 0 };
const pane = t.pane() orelse return null;
if (pane.file) |f| return .{ .text = f.content, .row0 = 0 };
@@ -703,6 +703,20 @@ fn setEditTextSpan(e: Editor, t: *Text, new: []u8, known_end: ?modal.Cursor, spa
t.own = tail;
return;
}
+ if (comptime !Editor.lib) if (t.what == .column or t.what == .workspace) {
+ // A header's computed words (UX K'2) are no one's to edit, as a
+ // tag's prefix is not.
+ defer retireEditText(e, new);
+ const words = tagline.headerWords(e.p, t.what);
+ if (!std.mem.startsWith(u8, new, words) or new.len == words.len or new[words.len] != ' ') {
+ t.refused = true;
+ return;
+ }
+ const tail = try e.gpa.dupe(u8, new[words.len + 1 ..]);
+ if (t.own) |old| e.gpa.free(old);
+ t.own = tail;
+ return;
+ };
if (t.what != .body) {
if (t.own) |old| e.gpa.free(old);
t.own = new;
diff --git a/core/keys.zig b/core/keys.zig
index e9be2461..5baed695 100644
--- a/core/keys.zig
+++ b/core/keys.zig
@@ -1064,12 +1064,12 @@ test "s in a header selects in the header's own text" {
p.update(.{ .key = .{ .cp = 's' } });
try std.testing.expect(pane.prompt == .search and pane.prompt_for == .workspace);
// the prompt takes the keys while the header keeps the keyboard
- p.update(.{ .key = .{ .cp = 'c', .text = "col" } });
+ p.update(.{ .key = .{ .cp = 'i', .text = "i" } });
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expect(p.view().header != null and pane.prompt == .none);
var ranges: [Text.max_selections]modal.Selection = undefined;
const text = try edit.flatSurface(p.editor(), &p.global_tag);
const got = p.global_tag.ranges(text, 0, &ranges);
- try std.testing.expectEqual(@as(usize, 2), got.n); // Newcol, Joincol
+ try std.testing.expectEqual(@as(usize, 2), got.n); // Find, Exit
try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
}
diff --git a/core/layout.zig b/core/layout.zig
index be2d213c..b72d6ec5 100644
--- a/core/layout.zig
+++ b/core/layout.zig
@@ -1678,12 +1678,24 @@ pub fn noticeRowHeight(p: *const Pardes) u16 {
return 1;
}
-/// The column tags' height: one row, as acme's (cols.c:244, colresize,
-/// gives a column tag one font height); a newline in one is a space
-/// (tagline.flattenHeaders).
+/// The column tags' row: one, as acme's (cols.c:244, colresize, gives a
+/// column tag one font height), a newline in one a space
+/// (tagline.flattenHeaders); only while there are columns (UX K'2): two
+/// or more, a column tag holding the user's text, or no window row for a
+/// lone column's words (a native shell's). None on a screen too short.
pub fn columnBarHeight(p: *const Pardes) u16 {
- if (p.view().screen_h < 3) return 0;
- return COLBAR_H;
+ const v = p.view();
+ if (v.screen_h < 3) return 0;
+ if (v.ncol > 1 or p.topBarHeight() == 0) return COLBAR_H;
+ for (v.col_tags[0..v.ncol]) |t| if (t.own) |own| if (own.len > 0) return COLBAR_H;
+ return 0;
+}
+
+/// A lone column's tag is at the window row's left (UX K'2): no column
+/// row, and a window row for it.
+pub fn columnInWindowRow(p: *const Pardes) bool {
+ const v = p.view();
+ return v.ncol == 1 and v.screen_h >= 3 and p.topBarHeight() > 0 and columnBarHeight(p) == 0;
}
/// Whether new column `c` (Newcol's) may stay. A narrower
@@ -1692,9 +1704,13 @@ pub fn columnBarHeight(p: *const Pardes) u16 {
/// minimum `before`, `before_min`, not one dragged short) takes rows back
/// from the panes with rows to spare, its column shared out again only
/// where that is not enough. False, `c` dropped unannounced, where nothing
-/// holds every minimum, as a size too small is refused.
+/// holds every minimum, as a size too small is refused, and every pane's
+/// rows as they were: the trial's shares are taken back with it (the
+/// column row a second column brings, UX K'2, takes a row from every pane).
pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_min: *const [MAX_PANES]u16) bool {
const v = p.view();
+ var weights: [MAX_PANES]f32 = undefined;
+ for (p.panes, &weights) |slot, *w| w.* = if (slot) |pane| pane.vweight else 0;
restoreMinimaFrom(p, before, before_min);
for (0..p.view().ncol) |k| {
compute(p);
@@ -1704,6 +1720,9 @@ pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_m
if (!pane.collapsed and v.rects[id].h < minRows(p, id) and before[id].h >= before_min[id]) break true;
} else false;
if (squeezed and !shareColumn(p, k)) {
+ for (p.panes, weights) |slot, w| if (slot) |pane| {
+ pane.vweight = w;
+ };
dropColumnUnannounced(p, c);
return false;
}
@@ -2590,3 +2609,47 @@ test "free space first (UX J1): a command's output and a Term take an untouched
try std.testing.expectEqual(before + 3, f.count());
try std.testing.expect(p.panes[scratch] != null);
}
+
+test "the column row comes with a second column and goes with it, the panes giving it and taking it back; a column tag with the user's text keeps it (UX K'2)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ // One column: no column row, its words in the window row, its pane
+ // under the window row.
+ try std.testing.expectEqual(@as(u16, 0), columnBarHeight(p));
+ try std.testing.expect(columnInWindowRow(p));
+ const alone = p.view().rects[0];
+ try std.testing.expectEqual(TOPBAR_H, alone.y);
+ // A second column: the row, under the window row, every column's panes
+ // starting under it.
+ try std.testing.expect(p.executeBuiltinLine(0, "Newcol"));
+ p.sync();
+ try std.testing.expectEqual(@as(usize, 2), p.view().ncol);
+ try std.testing.expectEqual(COLBAR_H, columnBarHeight(p));
+ try std.testing.expect(!columnInWindowRow(p));
+ try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y);
+ newScratchIn(p, 0, 1);
+ p.sync();
+ const second = p.view().cols[1].panes[0];
+ try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[second].y);
+ // Delcol back to one: the row goes, the pane has it again.
+ p.exec_column = 1;
+ try std.testing.expect(p.executeBuiltinLine(second, "Delcol"));
+ p.exec_column = null;
+ p.sync();
+ try std.testing.expectEqual(@as(usize, 1), p.view().ncol);
+ try std.testing.expectEqual(@as(u16, 0), columnBarHeight(p));
+ try std.testing.expectEqualDeep(alone, p.view().rects[0]);
+ // The user's text in the column's tag: the row stays for it, alone.
+ p.view().col_tags[0].own = try p.gpa.dupe(u8, "Mine");
+ p.sync();
+ try std.testing.expectEqual(COLBAR_H, columnBarHeight(p));
+ try std.testing.expect(!columnInWindowRow(p));
+ try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y);
+ // Emptied, it goes again.
+ p.gpa.free(p.view().col_tags[0].own.?);
+ p.view().col_tags[0].own = try p.gpa.dupe(u8, "");
+ p.sync();
+ try std.testing.expectEqual(@as(u16, 0), columnBarHeight(p));
+ try std.testing.expectEqualDeep(alone, p.view().rects[0]);
+}
diff --git a/core/mouse.zig b/core/mouse.zig
index b62cec7e..568470c7 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -365,11 +365,14 @@ fn emulateButton(p: *Pardes, m: *Mouse) void {
fn headerPoint(p: *Pardes, column: ?usize, mcol: u16, mrow: u16, clamp: bool) ?struct { t: *panes.Text, text: []const u8, line: u16, at: usize } {
const v = p.view();
const t = if (column) |c| &v.col_tags[c] else &p.global_tag;
- const x = if (column) |c| v.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET;
+ // A lone column's tag is at the window row's left, the window's at
+ // its right end (UX K'2).
+ const in_row = column == null or layout.columnInWindowRow(p);
+ const x = if (column) |c| (if (in_row) TAG_TEXT_INSET else v.col_x[c] + TAG_TEXT_INSET) else tagline.windowRow(p).words;
const focused = v.header != null and p.headerColumn() == column;
const text = edit.flatSurface(p.editor(), t) catch return null;
- const base = if (column != null) p.topBarHeight() else 0;
- const rows = if (column != null) layout.columnBarHeight(p) else p.topBarHeight();
+ const base = if (in_row) 0 else p.topBarHeight();
+ const rows = if (in_row) p.topBarHeight() else layout.columnBarHeight(p);
const row: u16 = if (clamp) @min(mrow -| base, rows -| 1) else mrow -| base;
const top: usize = if (focused) v.header_top else 0;
const lines = modal.lineCount(text);
@@ -680,7 +683,12 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
var column: ?usize = null;
var x: u16 = TAG_TEXT_INSET;
if (mcol < x) return;
- if (mrow >= p.topBarHeight()) {
+ if (mrow < p.topBarHeight()) {
+ // The window row: a lone column's tag at its left, the
+ // window's at its right; the blank between them is no one's.
+ const sides = tagline.windowRow(p);
+ if (mcol < TAG_TEXT_INSET + sides.column) column = 0 else if (mcol < sides.words) return;
+ } else {
for (0..p.view().ncol) |c| if (mcol >= v.col_x[c] and mcol < v.col_x[c] + v.col_w[c]) {
column = c;
x = v.col_x[c] + TAG_TEXT_INSET;
@@ -1991,3 +1999,39 @@ test "a body press, drag and release are the same state whichever frame this pro
}
try expectSame(a, b, "after the press");
}
+
+fn clickAt(p: *Pardes, button: pardes.Mouse.Button, col: u16, row: u16) void {
+ p.update(.{ .mouse = .{ .button = button, .kind = .press, .col = col, .row = row } });
+ p.update(.{ .mouse = .{ .button = button, .kind = .release, .col = col, .row = row } });
+}
+
+test "one column's words at the window row's left and the window's at its right each run their own; the blank between is no one's (UX K'2)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ const row = tagline.windowRow(p);
+ // `New Term ` and its caret's cell from the inset; the window's words
+ // end on the blank before the last cell.
+ try std.testing.expectEqual(@as(u16, "New Term ".len + 1), row.column);
+ try std.testing.expectEqual(@as(u16, 100 - "Find Grep Newcol Help Exit ".len - 1), row.words);
+ // B2 on `New`: a pane in the column.
+ clickAt(p, .middle, TAG_TEXT_INSET + 1, 0);
+ try std.testing.expectEqual(@as(usize, 2), p.view().cols[0].n);
+ // B2 and B1 on the blank between: nothing, and no tag takes the keyboard.
+ const between = row.words - 2;
+ try std.testing.expect(between > TAG_TEXT_INSET + row.column);
+ clickAt(p, .middle, between, 0);
+ clickAt(p, .left, between, 0);
+ try std.testing.expectEqual(@as(usize, 2), p.view().cols[0].n);
+ try std.testing.expectEqual(@as(usize, 1), p.view().ncol);
+ try std.testing.expect(p.view().header == null);
+ // B1 on `Term`: the column's tag has the keyboard, there in the window
+ // row, its caret on the clicked cell.
+ clickAt(p, .left, TAG_TEXT_INSET + "New ".len + 1, 0);
+ p.sync();
+ try std.testing.expectEqual(@as(?usize, 0), p.headerColumn());
+ try std.testing.expectEqual(@as(i32, "New ".len + 1), p.view().col_tags[0].cur_col);
+ // B2 on `Newcol`, at the right: a second column.
+ clickAt(p, .middle, row.words + @as(u16, "Find Grep ".len) + 2, 0);
+ try std.testing.expectEqual(@as(usize, 2), p.view().ncol);
+}
diff --git a/core/ninep/cols.zig b/core/ninep/cols.zig
index 88d8ef88..c84017a7 100644
--- a/core/ninep/cols.zig
+++ b/core/ninep/cols.zig
@@ -79,7 +79,7 @@ pub fn write(p: *Pardes, req: Req, serial: ?u32) Reply {
if (pending) p.fs.header_trunc_pending = null;
return tree.failText(req.tag, E.INVAL, why);
}
- const had = if (pending) 0 else headerText(p, serial).?.len;
+ const had = if (pending) 0 else if (t.own) |own| own.len else 0;
// A rewrite drops its one trailing newline: `echo <4096 bytes> > tag`
// is 4096 bytes of tag, and fits.
const rewrite = pending or p.fs.header_rewrite == rewriteKey(serial);
@@ -89,7 +89,8 @@ pub fn write(p: *Pardes, req: Req, serial: ?u32) Reply {
return tree.failText(req.tag, E.NOSPC, pardes.ctlfs.pane.e_tag_over);
}
applyTruncation(p, serial);
- const was = headerText(p, serial).?;
+ // Its own text grows, after the computed words (UX K'1).
+ const was: []const u8 = t.own orelse "";
var data = req.data;
const rewriting = p.fs.header_rewrite == rewriteKey(serial);
// A newline held from the write before goes in once more text follows.
@@ -106,8 +107,8 @@ pub fn write(p: *Pardes, req: Req, serial: ?u32) Reply {
return .{ .tag = req.tag, .written = @intCast(req.data.len) };
}
-/// Truncating clears it, as a pane tag's `cleartag`: its default words go
-/// too, and `u` in it brings them back.
+/// Truncating clears it, as a pane tag's `cleartag`: its own text goes,
+/// its computed words stay, and `u` in it brings the text back.
pub fn truncate(p: *Pardes, serial: ?u32) tree.Status {
if (header(p, serial) == null) return .err;
// Done with the write after it, which may yet be refused.
@@ -128,8 +129,9 @@ fn clear(p: *Pardes, serial: ?u32) tree.Status {
const empty = p.gpa.alloc(u8, 0) catch unreachable; // no byte: the allocator is not asked
if (t.own) |own| p.gpa.free(own);
t.own = empty;
+ // what is left is the computed words; the cursor goes after them
t.cur_row = 0;
- t.cur_col = 0;
+ t.cur_col = @intCast(tagline.headerWords(p, t.what).len + 1);
p.fs.header_rewrite = rewriteKey(serial);
p.fs.header_held = false;
return .ok;
@@ -548,19 +550,21 @@ test "a column's tag and the workspace's read, replace and append as a pane tag
try testing.expectEqual(E.NOENT, th.look_up(p, col_dir, "777").errno());
const tag = Node.ofCol(serial, .tag);
try testing.expectEqual(tree.Status.ok, th.look_up(p, Node.ofCol(serial, .dir), "tag").reply.status);
- try testing.expectEqualStrings("New Term Find Grep Joincol Delcol", th.rd(p, tag, 0, 4096).bytes);
- // `echo Make > tag`: cleared, then the newline ending the write dropped.
+ // Its computed words (UX K'2), a blank, and its own text: none yet.
+ try testing.expectEqualStrings("New Term ", th.rd(p, tag, 0, 4096).bytes);
+ // `echo Make > tag`: its own text cleared, then the newline ending the
+ // write dropped; the computed words stay.
_ = th.call(p, .{ .tag = 1, .op = .setattr, .node = tag, .truncate = true });
_ = th.wr(p, tag, "Make\n");
- try testing.expectEqualStrings("Make", th.rd(p, tag, 0, 4096).bytes);
+ try testing.expectEqualStrings("New Term Make", th.rd(p, tag, 0, 4096).bytes);
_ = th.call(p, .{ .tag = 2, .op = .release, .node = tag });
// `>>` appends; a newline in a one-line tag is a space.
_ = th.wr(p, tag, " Lint\nNow");
- try testing.expectEqualStrings("Make Lint Now", th.rd(p, tag, 0, 4096).bytes);
+ try testing.expectEqualStrings("New Term Make Lint Now", th.rd(p, tag, 0, 4096).bytes);
const top = @backingInt(tree.TopFile.tag);
_ = th.call(p, .{ .tag = 3, .op = .setattr, .node = top, .truncate = true });
_ = th.wr(p, top, "Newcol Exit\n");
- try testing.expectEqualStrings("Newcol Exit", tagline.topbar(p));
+ try testing.expectEqualStrings("Find Grep Newcol Help Exit Newcol Exit", tagline.topbar(p));
}
test "a focus write makes its pane's column the active one: layout says so and pane/new goes there" {
diff --git a/core/replica.zig b/core/replica.zig
index 97cbaeee..ccc29661 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -8001,7 +8001,9 @@ test "a far client's drag in a kind's pane it grabbed, the pane since too short
}
for ([_]pardes.Event{
.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row } },
- .{ .resize = .{ .cols = 80, .rows = 5 } },
+ // Two rows for the two panes under the window row (a lone column has
+ // no column row, UX K'2): one each.
+ .{ .resize = .{ .cols = 80, .rows = 4 } },
.{ .mouse = .{ .button = .left, .kind = .drag, .col = col, .row = 30 } },
.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = 30 } },
}) |ev| {
diff --git a/core/root.zig b/core/root.zig
index 11cb5058..525e796a 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -166,7 +166,13 @@ pub const TAG_TEXT_INSET: u16 = config.GUTTER;
pub fn taglineOriginCol(p: *const Pardes, col: u16, row: u16) f32 {
const v = p.view();
- if (row < p.topBarHeight()) return 0;
+ // The window row's two tags (UX K'2): a lone column's from the inset,
+ // the window's from its words.
+ if (row < p.topBarHeight()) {
+ const sides = tagline.windowRow(p);
+ if (col >= sides.words) return @floatFromInt(sides.words);
+ return if (sides.column > 0 and col >= TAG_TEXT_INSET) @floatFromInt(TAG_TEXT_INSET) else 0;
+ }
if (row < p.topBarHeight() + layout.columnBarHeight(p)) {
for (v.col_x[0..p.view().ncol], v.col_w[0..p.view().ncol]) |x, w|
if (col >= x and col - x < w) return @floatFromInt(x);
@@ -183,7 +189,17 @@ pub fn taglineOriginCol(p: *const Pardes, col: u16, row: u16) f32 {
pub fn gridColAt(p: ?*const Pardes, x: f32, row: u16, body_w: f32, tagline_w: f32) u16 {
const body = @max(body_w, 1);
const tag = @max(tagline_w, 1);
- if (row < (if (p) |core| core.topBarHeight() else TOPBAR_H)) return colFromSpan(x, tag);
+ if (row < (if (p) |core| core.topBarHeight() else TOPBAR_H)) {
+ // Its inset and the blank between its two tags on the body's grid,
+ // each tag's glyphs from its origin (taglineOriginCol).
+ const core = p orelse return colFromSpan(x, tag);
+ const cell = colFromSpan(x, body);
+ const origin: u16 = @intFromFloat(taglineOriginCol(core, cell, row));
+ if (origin == 0) return cell;
+ const sides = tagline.windowRow(core);
+ const end = if (origin < sides.words) TAG_TEXT_INSET + sides.column else core.view().screen_w;
+ return @min(origin + colFromSpan(x - @as(f32, @floatFromInt(origin)) * body, tag), end -| 1);
+ }
if (p) |core| if (row < core.topBarHeight() + layout.columnBarHeight(core)) {
for (core.view().col_x[0..core.view().ncol], core.view().col_w[0..core.view().ncol]) |origin, width| {
if (width == 0) continue;
@@ -279,7 +295,7 @@ fn shortcuts(comptime b: Builtin) []const u8 {
for (config.exec_key) |k| s = s ++ ", " ++ chordName(k);
s = s ++ ", " ++ @tagName(config.exec_button) ++ "-click";
}
- var it = std.mem.tokenizeScalar(u8, config.topbar_str, ' ');
+ var it = std.mem.tokenizeScalar(u8, config.window_words_str, ' ');
while (it.next()) |w| if (std.mem.eql(u8, w, @tagName(b))) {
s = s ++ ", topbar";
};
@@ -333,7 +349,7 @@ pub const builtin_rows: [std.enums.values(Builtin).len]Row = blk: {
comptime {
@setEvalBranchQuota(20000); // one branch per string byte, behind the decl walk that folds Builtin
- var it = std.mem.tokenizeScalar(u8, config.topbar_str, ' ');
+ var it = std.mem.tokenizeScalar(u8, config.topbar_str ++ " " ++ config.window_words_str ++ " " ++ config.columns_words_str, ' ');
words: while (it.next()) |w| {
for (@typeInfo(Builtin).@"enum".field_names) |name|
if (std.mem.eql(u8, name, w)) continue :words;
@@ -368,9 +384,11 @@ test "a compact tagline anchors at its own pane, and both shells step from the s
try std.testing.expectEqual(@as(f32, @floatFromInt(left.x)), taglineOriginCol(p, left.x + 3, left.y));
try std.testing.expectEqual(@as(f32, @floatFromInt(right.x)), taglineOriginCol(p, right.x + 3, right.y));
- // The topbar's origin is column zero always — it is not a pane rect, which
- // is why row zero is right even in a window with no core to ask.
+ // The window row (UX K'2): its blank's origin is column zero, as a window
+ // with no core to ask has it; the window's words start at their own.
+ const words = tagline.windowRow(p).words;
try std.testing.expectEqual(@as(f32, 0), taglineOriginCol(p, 40, 0));
+ try std.testing.expectEqual(@as(f32, @floatFromInt(words)), taglineOriginCol(p, words + 3, 0));
const body_row = left.y + 2;
try std.testing.expectEqual(@as(f32, 7), taglineOriginCol(p, 7, body_row));
@@ -399,9 +417,10 @@ test "a compact tagline anchors at its own pane, and both shells step from the s
try std.testing.expectEqual(col, gridColAt(p, glyph_x + tag_w / 2, left.y, body_w, tag_w));
}
- // The topbar's pointer grid is compact from column zero, with no pane to
- // anchor to — the one tag row that is right with or without a core.
- try std.testing.expectEqual(@as(u16, 3), gridColAt(p, 3.5 * tag_w, 0, body_w, tag_w));
+ // The window row's blank is on the body's grid, its words compact from
+ // where they start; with no core to ask, compact from column zero.
+ try std.testing.expectEqual(@as(u16, 3), gridColAt(p, 3.5 * body_w, 0, body_w, tag_w));
+ try std.testing.expectEqual(words + 3, gridColAt(p, @as(f32, @floatFromInt(words)) * body_w + 3.5 * tag_w, 0, body_w, tag_w));
try std.testing.expectEqual(@as(u16, 3), gridColAt(null, 3.5 * tag_w, 0, body_w, tag_w));
// A body row is untouched: still the body grid, still divided by the body
diff --git a/core/tagline.zig b/core/tagline.zig
index 3a306f04..b05a3d4a 100644
--- a/core/tagline.zig
+++ b/core/tagline.zig
@@ -12,6 +12,7 @@ const config = @import("config.zig");
const Layer = @import("Layer.zig");
const layout = @import("layout.zig");
const TagState = @import("TagState.zig");
+const Messages = @import("Messages.zig");
const Pane = panes.Pane;
const Text = panes.Text;
const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET;
@@ -113,34 +114,85 @@ pub fn dirty(pane: *const panes.Pane) bool {
const f = pane.file orelse return false;
return panes.Output.fileTraits(f.output).saves and (f.revision != f.saved_revision or f.disk_gone);
}
-/// What a column's tag says until someone edits it.
+/// What a column's tag said before UX K', its own text then: a dump's own
+/// text equal to it is dropped (dump.dropOldTags), and a column's exec
+/// still takes its words (ninep/cols.zig paneWord).
pub const column_tag_default = "New Term Find Grep Joincol Delcol";
-/// What a header says until someone edits it: for the workspace the
-/// fixed builtins, plus `Restore <path>` once a dump exists.
-pub fn headerDefault(p: *Pardes, what: Text.What) []const u8 {
- if (what == .column) return column_tag_default;
- const row = topbarDefault(p);
- const d = p.last_dump orelse return row;
- return std.fmt.allocPrint(p.scratch.allocator(), "{s} Restore {s}", .{ row, d }) catch row;
+/// A header's computed words (UX K'2), read-only, made again from the
+/// session's state as a pane tag's are: the window's, then `Restore
+/// <path>` once a dump exists; a column's, with Joincol and Delcol where
+/// there is a second column for them.
+pub fn headerWords(p: *Pardes, what: Text.What) []const u8 {
+ if (what == .column) return if (p.view().ncol > 1) config.columns_words_str else config.column_words_str;
+ const d = p.last_dump orelse return config.window_words_str;
+ return std.fmt.allocPrint(p.scratch.allocator(), "{s} Restore {s}", .{ config.window_words_str, d }) catch config.window_words_str;
}
-/// The workspace row's words for this view: the window's row, with Fonts,
-/// in a window's view alone; a terminal's view (a terminal's build, or a
-/// terminal's replica of a window's session) has the row without it.
-fn topbarDefault(p: *Pardes) []const u8 {
- if (comptime @import("builtins.zig").capabilities.font_picker) if (@import("builtins.zig").registry.here(p, .Fonts)) return config.topbar_window_str;
- return config.topbar_terminal_str;
+/// A header as it is shown, read and edited: its computed words, a blank,
+/// then the user's text (UX K'1), everything typed into it, as a pane
+/// tag's own text follows its prefix.
+pub fn headerText(p: *Pardes, t: *const Text) ![]u8 {
+ const own: []const u8 = t.own orelse "";
+ return std.mem.concat(p.scratch.allocator(), u8, &.{ headerWords(p, t.what), " ", own });
}
-/// the topbar line -- render and click dispatch must agree on this exact
-/// string
+/// The window's tag -- render and click dispatch must agree on this exact
+/// string.
pub fn topbar(p: *Pardes) []const u8 {
- return p.global_tag.own orelse headerDefault(p, .workspace);
+ return headerText(p, &p.global_tag) catch config.window_words_str;
}
-pub fn columnTag(p: *const Pardes, c: usize) []const u8 {
- return p.view().col_tags[c].own orelse column_tag_default;
+pub fn columnTag(p: *Pardes, c: usize) []const u8 {
+ return headerText(p, &p.view().col_tags[c]) catch config.column_words_str;
+}
+
+/// A header's width in glyphs as headerText makes it, made of nothing.
+fn headerWidth(p: *const Pardes, t: *const Text) usize {
+ const tab = p.settings.tab;
+ const own = if (t.own) |text| panes.File.displayWidth(tab, text) else 0;
+ const column: []const u8 = if (p.view().ncol > 1) config.columns_words_str else config.column_words_str;
+ if (t.what == .column) return column.len + 1 + own;
+ const restore = if (p.last_dump) |d| " Restore ".len + panes.File.displayWidth(tab, d) else 0;
+ return config.window_words_str.len + restore + 1 + own;
+}
+
+/// The window row's two sides (UX K'2), in cells from the window's left:
+/// column 0's tag from the inset, `column` cells (its text and its caret's
+/// cell; none but while layout.columnInWindowRow), and the window's tag
+/// from `words` to the right edge, its last cell the caret's, a server's
+/// progress after its text while one runs (draw.zig). Draw, the mouse,
+/// workspaceBlank and a pixel shell's grid read it.
+pub const WindowRow = struct { column: u16, words: u16 };
+pub fn windowRow(p: *const Pardes) WindowRow {
+ const v = p.view();
+ const inset = @min(TAG_TEXT_INSET, v.screen_w);
+ const column = if (layout.columnInWindowRow(p)) @min(cellsFor(p, headerWidth(p, &v.col_tags[0]) + 1), v.screen_w - inset) else 0;
+ var glyphs = headerWidth(p, &p.global_tag) + 1;
+ if (sessionProgress(p)) |said| glyphs += 2 + progressWidth(p, said);
+ return .{ .column = column, .words = @max(v.screen_w -| cellsFor(p, glyphs), inset + column) };
+}
+
+/// A server's progress that is no pane's, the session's: shown at the
+/// window tag's end while it runs.
+pub fn sessionProgress(p: *const Pardes) ?*const Messages.Said {
+ for (p.messages.live[0..p.messages.live_len]) |*said| if (said.kind == .progress and said.pane == 0) return said;
+ return null;
+}
+
+/// The width of a server's progress as the window's tag shows it: its
+/// glyph, a blank and its words.
+pub fn progressWidth(p: *const Pardes, said: *const Messages.Said) usize {
+ return panes.File.displayWidth(p.settings.tab, Messages.Kind.progress.glyph()) + 1 + panes.File.displayWidth(p.settings.tab, said.words());
+}
+
+/// The grid cells `glyphs` tagline glyphs take: layout.tagCapacity's
+/// inverse.
+fn cellsFor(p: *const Pardes, glyphs: usize) u16 {
+ const m = p.view().row_metrics;
+ const body: usize = @max(1, m.body_w);
+ const tag: usize = @max(1, m.tagline_w);
+ return @intCast(@min(std.math.maxInt(u16), (glyphs * tag + body - 1) / body));
}
/// The header with the keyboard, when one has it.
@@ -160,11 +212,14 @@ pub fn revealHeader(p: *Pardes) void {
};
const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(v.active), "tag", err);
const cur: usize = @intCast(@max(0, t.cur_row));
- const rows: usize = if (p.headerColumn() != null) layout.columnBarHeight(p) else p.topBarHeight();
+ // Column 0's tag in the window row (UX K'2) has that row and its side.
+ const in_row = p.headerColumn() != null and layout.columnInWindowRow(p);
+ const rows: usize = if (p.headerColumn() != null and !in_row) layout.columnBarHeight(p) else p.topBarHeight();
if (cur < v.header_top) v.header_top = cur;
if (rows > 0 and cur >= v.header_top + rows) v.header_top = cur + 1 - rows;
const line = modal.lineSlice(text, cur);
- const width = layout.tagCapacity(p, if (p.headerColumn()) |c| v.col_w[c] -| TAG_TEXT_INSET else v.screen_w -| TAG_TEXT_INSET);
+ const sides = windowRow(p);
+ const width = layout.tagCapacity(p, if (p.headerColumn()) |c| (if (in_row) sides.column else v.col_w[c] -| TAG_TEXT_INSET) else v.screen_w -| sides.words);
const col = panes.File.rawDisplayCol(p.settings.tab, line, @min(@as(usize, @intCast(@max(0, t.cur_col))), line.len));
if (col < v.header_scroll) v.header_scroll = col;
if (col >= v.header_scroll + width) v.header_scroll = col -| (width -| 1);
@@ -699,13 +754,18 @@ pub fn exitHeader(p: *Pardes) void {
}
/// Give the keyboard to a column's tag, or the workspace's for null, in
-/// normal mode, its cursor where that header last had it.
+/// normal mode, its cursor where that header last had it; the first time
+/// on the user's text, after the computed words (UX K'1), as enterTag.
pub fn enterHeader(p: *Pardes, column: ?usize) void {
exitHeader(p);
if (p.panes[p.view().active]) |pane| pane.focus = .body;
p.view().header = if (column) |c| .{ .column = c } else .workspace;
if (column) |c| p.setActiveColumn(c);
const t = focusedHeader(p) orelse return exitHeader(p);
+ if (!t.cur_pinned) {
+ t.cur_row = 0;
+ t.cur_col = @intCast(headerWords(p, t.what).len + 1);
+ }
takeKeyboard(t, edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(p.view().active), "tag", err));
}
@@ -724,19 +784,23 @@ pub fn headerSelection(t: *const Text, text: []const u8, row: usize) ?struct { l
return .{ .lo = @max(lo, start) - start, .hi = @min(hi, end) - start };
}
-/// Whether the workspace tag is blank at cell (col, row): its inset left of
-/// the text, or past the text's end with two cells kept free for the caret
-/// (a B1 there still types at the end of the tag). A pixel shell lets the
-/// window be dragged by such a cell, as a browser by the space beside its
-/// tabs: blank is no text, so no button of acme's is taken from any. A
-/// column's tag and a pane's are not: their blank is where B1 types.
+/// Whether the window row is blank at cell (col, row): its inset, the
+/// cells between its two sides (UX K'2), or past the window's text with
+/// two cells kept free for the caret (a B1 there still types at the end of
+/// the tag). A pixel shell lets the window be dragged by such a cell, as a
+/// browser by the space beside its tabs: blank is no text, so no button of
+/// acme's is taken from any. A column's tag and a pane's are not: their
+/// blank is where B1 types.
pub fn workspaceBlank(p: *Pardes, col: u16, row: u16, tag_hit: ?pardes.TagHit) bool {
const v = p.view();
if (row >= p.topBarHeight() or col >= v.screen_w) return false;
if (col < TAG_TEXT_INSET) return true;
- const text = edit.flatSurface(p.editor(), &p.global_tag) catch return false;
+ const sides = windowRow(p);
+ if (col < TAG_TEXT_INSET + sides.column) return false;
+ if (col < sides.words) return true;
+ const text = topbar(p);
const scroll: usize = if (v.header != null and p.headerColumn() == null) v.header_scroll else 0;
- const at = @as(usize, Layer.columnAt(p, .workspace, 0, tag_hit, false, 0) orelse (col - TAG_TEXT_INSET)) + scroll;
+ const at = @as(usize, Layer.columnAt(p, .workspace, 0, tag_hit, false, 0) orelse (col - sides.words)) + scroll;
return at >= panes.File.displayWidth(p.settings.tab, modal.lineSlice(text, 0)) + 2;
}
@@ -744,15 +808,17 @@ pub fn workspaceBlank(p: *Pardes, col: u16, row: u16, tag_hit: ?pardes.TagHit) b
/// pasted or restored from a dump into one becomes a space, the caret and
/// the selection kept on the same characters.
pub fn flattenHeaders(p: *Pardes) void {
- for (p.view().col_tags[0..p.view().ncol]) |*t| flatten(t);
- flatten(&p.global_tag);
+ for (p.view().col_tags[0..p.view().ncol]) |*t| flatten(p, t);
+ flatten(p, &p.global_tag);
}
-fn flatten(t: *Text) void {
+fn flatten(p: *Pardes, t: *Text) void {
const own = t.own orelse return;
if (std.mem.indexOfScalar(u8, own, '\n') == null) return;
- const cur = modal.offsetAt(own, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) });
- const anchor = modal.offsetAt(own, .{ .row = @intCast(@max(0, t.vsel.row)), .col = @intCast(@max(0, t.vsel.col)) });
+ // The caret and the anchor are in the text as shown, words and all.
+ const shown = headerText(p, t) catch return;
+ const cur = modal.offsetAt(shown, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) });
+ const anchor = modal.offsetAt(shown, .{ .row = @intCast(@max(0, t.vsel.row)), .col = @intCast(@max(0, t.vsel.col)) });
std.mem.replaceScalar(u8, own, '\n', ' ');
t.cur_row = 0;
t.cur_col = @intCast(cur);
@@ -774,25 +840,22 @@ pub fn wordBoundsAtCol(str: []const u8, col: usize) ?WordBounds {
return .{ .lo = lo, .hi = hi };
}
-test "the workspace tag is blank left of its text and past its end, and nowhere else" {
+test "the window row is blank at its inset and between its two sides, and nowhere else (UX K'2)" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 12, .tty_only = true });
defer p.deinit();
- p.global_tag.own = try p.gpa.dupe(u8, "Newcol Exit");
p.sync();
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
_ = try p.render(arena.allocator());
- const end = TAG_TEXT_INSET + "Newcol Exit".len;
- try std.testing.expect(workspaceBlank(p, 0, 0, null));
- try std.testing.expect(workspaceBlank(p, TAG_TEXT_INSET - 1, 0, null));
- // Every cell of the text, the gap between its words too, is not.
- for (TAG_TEXT_INSET..end) |c| try std.testing.expect(!workspaceBlank(p, @intCast(c), 0, null));
- // The two cells after it are the caret's, then blank to the edge.
- try std.testing.expect(!workspaceBlank(p, end, 0, null));
- try std.testing.expect(!workspaceBlank(p, end + 1, 0, null));
- try std.testing.expect(workspaceBlank(p, end + 2, 0, null));
- try std.testing.expect(workspaceBlank(p, 79, 0, null));
- // Below the workspace tag: a column's tag, a pane: never.
+ const sides = windowRow(p);
+ try std.testing.expect(sides.column > 0 and TAG_TEXT_INSET + sides.column < sides.words);
+ for (0..TAG_TEXT_INSET) |c| try std.testing.expect(workspaceBlank(p, @intCast(c), 0, null));
+ // The column's words and their caret's cell are not; the cells between
+ // the two sides are; the window's words and their caret's cell are not.
+ for (TAG_TEXT_INSET..TAG_TEXT_INSET + sides.column) |c| try std.testing.expect(!workspaceBlank(p, @intCast(c), 0, null));
+ for (TAG_TEXT_INSET + sides.column..sides.words) |c| try std.testing.expect(workspaceBlank(p, @intCast(c), 0, null));
+ for (sides.words..80) |c| try std.testing.expect(!workspaceBlank(p, @intCast(c), 0, null));
+ // Below the window row: a column's tag, a pane: never.
for (1..12) |r| try std.testing.expect(!workspaceBlank(p, 79, @intCast(r), null));
// Hidden, there is none.
p.settings.workspace_tag = false;
@@ -807,10 +870,11 @@ test "a column or workspace tag is one line: a newline in it is a space" {
p.view().col_tags[0].cur_col = 2;
p.global_tag.own = try p.gpa.dupe(u8, "Newcol\nExit");
p.sync();
- try std.testing.expectEqualStrings("New Snarf", columnTag(p, 0));
+ try std.testing.expectEqualStrings("New Term New Snarf", columnTag(p, 0));
try std.testing.expectEqualStrings("Newcol Exit", p.global_tag.own.?);
+ // The caret on the same character, `a` of Snarf.
try std.testing.expectEqual(@as(i32, 0), p.view().col_tags[0].cur_row);
- try std.testing.expectEqual(@as(i32, 6), p.view().col_tags[0].cur_col);
+ try std.testing.expectEqual(@as(i32, "New Term New Sn".len), p.view().col_tags[0].cur_col);
try std.testing.expectEqual(pardes.COLBAR_H, layout.columnBarHeight(p));
try std.testing.expectEqual(pardes.TOPBAR_H, p.topBarHeight());
}
@@ -940,3 +1004,71 @@ test "a dump of a build before UX K' restores a tag's old default own text as no
defer kept.deinit();
try std.testing.expectEqualStrings(" Save Term Collapse Follow Del Mine", kept.panes[0].?.tag.own.?);
}
+
+test "a header reads its computed words, then the user's text: typed there, kept through a change of its words (UX K'1, K'2)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30, .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit ", topbar(p));
+ try std.testing.expectEqualStrings("New Term ", columnTag(p, 0));
+ // The window's tag given the keyboard starts on the user's text.
+ enterHeader(p, null);
+ typeKeys(p, "iMine");
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expectEqualStrings("Mine", p.global_tag.own.?);
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Mine", topbar(p));
+ // A Backspace on the blank before it is refused: the words are no one's.
+ p.global_tag.cur_col = "Find Grep Newcol Help Exit ".len;
+ typeKeys(p, "i");
+ p.update(.{ .key = .{ .cp = pardes.Key.backspace } });
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Mine", topbar(p));
+ // A dump: its Restore comes into the words, the user's text after it.
+ p.setLastDump("/tmp/a.zon");
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Restore /tmp/a.zon Mine", topbar(p));
+ // A second column: Joincol and Delcol come into every column's words.
+ exitHeader(p);
+ try std.testing.expect(p.executeBuiltinLine(0, "Newcol"));
+ p.sync();
+ try std.testing.expectEqualStrings("New Term Joincol Delcol ", columnTag(p, 0));
+ try std.testing.expectEqualStrings("New Term Joincol Delcol ", columnTag(p, 1));
+ // Newcol gave the keyboard to the new column's tag, on its user's text.
+ try std.testing.expectEqual(@as(?usize, 1), p.headerColumn());
+ typeKeys(p, "iTwo");
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expectEqualStrings("New Term Joincol Delcol Two", columnTag(p, 1));
+ try std.testing.expectEqualStrings("Two", p.view().col_tags[1].own.?);
+}
+
+test "a dump of a build before UX K' restores a header's old default own text as none, any other as the user's (UX K'1)" {
+ const dump = @import("dump.zig");
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30, .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ // What the window's and a column's tags said before, with a Restore.
+ p.global_tag.own = try p.gpa.dupe(u8, config.topbar_terminal_str ++ " Restore /tmp/old.zon");
+ p.view().col_tags[0].own = try p.gpa.dupe(u8, column_tag_default);
+ try dump.dumpState(p);
+ const dropped = try dump.restore(p, p.dump_out.?, "old");
+ defer dropped.deinit();
+ try std.testing.expect(dropped.global_tag.own == null);
+ try std.testing.expect(dropped.view().col_tags[0].own == null);
+ try std.testing.expectEqualStrings("New Term ", columnTag(dropped, 0));
+ // The window's row with Fonts, and no Restore, is dropped too.
+ p.gpa.free(p.global_tag.own.?);
+ p.global_tag.own = try p.gpa.dupe(u8, config.topbar_window_str);
+ try dump.dumpState(p);
+ const window = try dump.restore(p, p.dump_out.?, "window");
+ defer window.deinit();
+ try std.testing.expect(window.global_tag.own == null);
+ // Edited around: kept whole, after the computed words.
+ p.gpa.free(p.global_tag.own.?);
+ p.global_tag.own = try p.gpa.dupe(u8, config.topbar_terminal_str ++ " Mine");
+ p.gpa.free(p.view().col_tags[0].own.?);
+ p.view().col_tags[0].own = try p.gpa.dupe(u8, "New Mine");
+ try dump.dumpState(p);
+ const kept = try dump.restore(p, p.dump_out.?, "custom");
+ defer kept.deinit();
+ try std.testing.expectEqualStrings(config.topbar_terminal_str ++ " Mine", kept.global_tag.own.?);
+ try std.testing.expectEqualStrings("New Term New Mine", columnTag(kept, 0));
+}