summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/File.zig2
-rw-r--r--core/Trail.zig166
-rw-r--r--core/builtins.zig11
-rw-r--r--core/colors.zig5
-rw-r--r--core/config.zig12
-rw-r--r--core/draw.zig16
-rw-r--r--core/panes.zig4
-rw-r--r--core/root.zig2
-rw-r--r--core/tagline.zig9
-rw-r--r--core/themes/acme.zig2
10 files changed, 222 insertions, 7 deletions
diff --git a/core/File.zig b/core/File.zig
index 07dfa52d..2affde32 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -1312,6 +1312,8 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
}
f.revision +%= 1;
f.splice = .{ .revision = f.revision, .head = span.head, .tail = span.tail, .old_len = old_len };
+ // Edited, a reading pane is held (pick-ui SPEC §6.5).
+ if (how == .edit) pardes.Trail.edited(p, f);
if (!told) {
// The file's text is as it was: as clean as it was, its
// declarations still its own.
diff --git a/core/Trail.zig b/core/Trail.zig
new file mode 100644
index 00000000..fc163751
--- /dev/null
+++ b/core/Trail.zig
@@ -0,0 +1,166 @@
+//! A pane's walk (pick-ui SPEC §6): the places a reading pane stepped
+//! through, written as words in its tag before its path, and whether it
+//! is held. A held pane (edited, kept, or not a file) never walks: a jump
+//! from it steps its one reader, a reading pane below it whose trail
+//! starts with it (`‹@p3`). A reading pane steps in place.
+//!
+//! The steps are one array, oldest first: `cur` is where the pane is (its
+//! place as it was at its last step: the caret is the truth between
+//! steps), the steps before it the back steps, the ones after it the
+//! forward steps a step back left, drawn dimmed after the path.
+const std = @import("std");
+const pardes = @import("root.zig");
+const Kind = @import("Kind.zig");
+const config = @import("config.zig");
+const layout = @import("layout.zig");
+const panes = @import("panes.zig");
+const look = @import("look.zig");
+const Pardes = pardes.Pardes;
+const Pane = panes.Pane;
+const Spot = look.Spot;
+
+const Trail = @This();
+
+/// The steps a trail keeps; past it the oldest go, the owner kept first.
+pub const max_steps = 16;
+/// The bytes of a step's path or word. A jump to a longer path is no step:
+/// it opens a pane as `Jumps new-pane` does (look.zig open).
+pub const max_text = 256;
+/// The newest back steps written whole; older ones fold to `·` (§6.3).
+pub const shown_steps = 3;
+
+/// `cur` held to the steps there are (walk.zig `.place`).
+pub const replica = .{ .len = .{.{ "steps", "n" }}, .place = .{.{ "cur", "lastCur" }} };
+
+steps: [max_steps]Step = undefined,
+n: u8 = 0,
+cur: u8 = 0,
+/// Kept, or edited since it was shown: it no longer walks (§6.5).
+held: bool = false,
+
+pub fn lastCur(t: *const Trail) usize {
+ return t.n -| 1;
+}
+
+/// One step of a walk, as its word says it (§2 "trail word").
+pub const Step = union(enum) {
+ /// A place the pane was at: `rank.zig:14`.
+ place: Place,
+ /// The held pane this is the reader of, by its serial: `‹@p3`, always
+ /// the first step.
+ owner: u32,
+ /// A list the pane came through (`Find pick 3/6 •2`, §5.6): its word
+ /// and the pickers' index for it. Made by the pickers (not yet).
+ list: Word,
+ /// A search made in the pane (`/dirty/ 3/7`, §7.3). Made by the
+ /// prompts (not yet).
+ search: Word,
+ /// A chain of selection prompts as an Edit line (§7.5). Made by the
+ /// prompts (not yet).
+ recipe: Word,
+};
+pub const Place = struct { path: Kind.Buf(max_text) = .{}, line: u32 = 0, col: u32 = 0 };
+pub const Word = struct { text: Kind.Buf(max_text) = .{}, index: u32 = 0 };
+
+/// A file the walk can show: a text on its path, not an output, a
+/// listing, a pager, a query or a kind (§2: what is not a file is held).
+pub fn isFile(pane: *const Pane) bool {
+ const f = pane.file orelse return false;
+ return f.output == null and f.listing == null and !f.pager and f.mini == null and pane.query == null and pane.addon == null;
+}
+
+/// A pane that walks: a file not held, in a session whose jumps walk.
+pub fn reading(p: *const Pardes, pane: *const Pane) bool {
+ return p.settings.jumps == .walk and isFile(pane) and !pane.trail.held;
+}
+
+/// Pane `id` held (§6.5): Keep, or an edit. It no longer walks, so the
+/// walk leaves its trail (places, lists, its owner, forward steps); words
+/// about its own text (a search, a recipe) stay. The next jump from its
+/// old owner makes a new reader.
+pub fn keep(pane: *Pane) void {
+ const t = &pane.trail;
+ if (t.held) return;
+ t.held = true;
+ var w: u8 = 0;
+ for (t.steps[0..t.cur]) |s| if (s == .search or s == .recipe) {
+ t.steps[w] = s;
+ w += 1;
+ };
+ t.n = w;
+ t.cur = w;
+}
+
+/// An edit of file `f`: the panes showing it are held from now on (§6.5).
+pub fn edited(p: *Pardes, f: *const panes.File.State) void {
+ for (p.panes) |slot| {
+ const pane = slot orelse continue;
+ if (pane.trail.held) continue;
+ const shown = if (pane.file) |*pf| pf else continue;
+ if (shown == f or (f.twin != 0 and shown.twin == f.twin)) keep(pane);
+ }
+}
+
+
+fn typeKeys(p: *Pardes, keys: []const u8) void {
+ for (keys) |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+}
+
+fn tagOf(p: *Pardes, pane: *Pane) ![]const u8 {
+ return pardes.tagline.tagText(p, p.scratch.allocator(), pane);
+}
+
+/// The ground of the cell under the first cell of pane `id`'s tag text.
+fn tagGroundOf(p: *Pardes, arena: *std.heap.ArenaAllocator, id: usize) !pardes.Color {
+ p.sync();
+ _ = arena.reset(.retain_capacity);
+ const s = try p.render(arena.allocator());
+ const r = p.view().rects[id];
+ return s.at(r.x + pardes.TAG_TEXT_INSET, p.tagTop(p.panes[id].?, r)).style.bg;
+}
+
+test "a file's pane is reading, its tag in the reading tint with Keep after its path; typed into, it is held, and Jumps new-pane reads none" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ p.settings.jumps = .walk;
+ const pane = try p.setTestFile("alpha\nbeta\n");
+ try std.testing.expect(reading(p, pane));
+ try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), "/test.txt Keep "));
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().tag_reading_bg }, try tagGroundOf(p, &arena, 0));
+ // Under Jumps new-pane nothing reads: the tag as it always was.
+ p.settings.jumps = .@"new-pane";
+ try std.testing.expect(!reading(p, pane));
+ try std.testing.expectEqualStrings("/test.txt Save Term Collapse Follow Del", try tagOf(p, pane));
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().tag_active_bg }, try tagGroundOf(p, &arena, 0));
+ p.settings.jumps = .walk;
+ // Typed into: held from now on, though Undo takes the text back.
+ typeKeys(p, "ix");
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ typeKeys(p, "u");
+ try std.testing.expectEqualStrings("alpha\nbeta\n", pane.file.?.content);
+ try std.testing.expect(!reading(p, pane));
+ try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), "Keep") == null);
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().tag_active_bg }, try tagGroundOf(p, &arena, 0));
+}
+
+test "Keep holds a reading pane; a scratch and a listing are never reading" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ const pane = try p.setTestFile("alpha\n");
+ pardes.exec.runBuiltin(p, .Keep, 0, "Keep", null);
+ try std.testing.expect(!reading(p, pane));
+ try std.testing.expect(pane.trail.held);
+ pardes.exec.runBuiltin(p, .New, 0, "New", null);
+ const scratch = p.panes[p.view().active].?;
+ try std.testing.expect(scratch != pane and scratch.file != null and !reading(p, scratch));
+ var dir = std.testing.tmpDir(.{});
+ defer dir.cleanup();
+ var buf: [4096]u8 = undefined;
+ const len = try dir.dir.realPath(std.testing.io, &buf);
+ pardes.look.lookAt(p, 0, buf[0..len]);
+ const listing = p.panes[p.view().active].?;
+ try std.testing.expect(listing.file.?.listing != null and !reading(p, listing));
+}
diff --git a/core/builtins.zig b/core/builtins.zig
index a236b0d6..12ab9da5 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -1998,6 +1998,17 @@ pub const Forward = struct {
}
};
+/// Keep this pane: a reading pane, which a jump steps, is held from now on.
+///
+/// Its walk leaves its tag (its places, its owner): the next jump from its
+/// owner makes a new reader. Editing a reading pane keeps it too.
+pub const Keep = struct {
+ pub fn run(c: Ctx) void {
+ if (!pardes.Trail.reading(c.p, c.pane)) return c.p.setMessage(.at(c.id), "Keep: this pane is held already");
+ pardes.Trail.keep(c.pane);
+ }
+};
+
/// Select the next thing a Look would open: a place in a list, a word that
/// names a file.
///
diff --git a/core/colors.zig b/core/colors.zig
index 5579ed05..84595a30 100644
--- a/core/colors.zig
+++ b/core/colors.zig
@@ -287,6 +287,9 @@ pub const Theme = struct {
lineno_active: ?[3]u8 = null,
/// A tag's selection, where it differs from the body's (acme's #9eeeee).
tag_sel_bg: ?[3]u8 = null,
+ /// The tag of a reading pane, one a jump steps (Trail.zig): unset, the
+ /// page tinted toward the search's ground, so it reads as the body's.
+ tag_reading_bg: ?[3]u8 = null,
/// Each pointer button's sweep, select, exec and look (Mouse.Button
/// order), and the ink over it. Unset, tints of `sel_bg` in `sel_fg`.
sweep_bg: ?[3][3]u8 = null,
@@ -543,6 +546,7 @@ pub const ChromeTheme = struct {
empty_col: [3]u8,
search_bg: [3]u8,
search_fg: [3]u8,
+ tag_reading_bg: [3]u8,
diagnostic_error: [3]u8,
diagnostic_warning: [3]u8,
diagnostic_info: [3]u8,
@@ -579,6 +583,7 @@ pub const ChromeTheme = struct {
.empty_col = th.empty_col orelse separatorOf(th),
.search_bg = th.search_bg orelse th.sel_bg,
.search_fg = th.search_fg orelse th.sel_fg,
+ .tag_reading_bg = th.tag_reading_bg orelse mixOklab(th.bg orelse th.tag_bg, th.search_bg orelse th.sel_bg, 0.4),
.diagnostic_error = th.diagnostic_error orelse (th.fg orelse th.tag_fg),
.diagnostic_warning = th.diagnostic_warning orelse (th.fg orelse th.tag_fg),
.diagnostic_info = th.diagnostic_info orelse (th.fg orelse th.tag_fg),
diff --git a/core/config.zig b/core/config.zig
index e9225c53..d5895b99 100644
--- a/core/config.zig
+++ b/core/config.zig
@@ -144,6 +144,7 @@ pub const leader_path = paths: {
.Unfollow = null,
.Back = "jo",
.Forward = "ji",
+ .Keep = "jk",
.Last = "jj",
.Jumplist = "jl",
.History = "fh",
@@ -157,6 +158,7 @@ pub const leader_path = paths: {
table.set(.TaglineSize, null);
}
table.set(.MessageLinger, null);
+ table.set(.Jumps, null);
table.set(.DumpDir, null);
if (builtins.capabilities.window_opacity) table.set(.WindowOpacity, null);
if (builtins.capabilities.pixels) table.set(.CursorBlink, null);
@@ -668,9 +670,16 @@ pub const Settings = struct {
tab: u16 = tab_width,
callstack_depth: u8 = @import("lsp/lsp.zig").callstack_default_depth,
+ /// A jump (a Look at a place, a definition, an error's place) steps
+ /// the pane it is made from, or its reader, as a walk (Trail.zig); or
+ /// opens a pane for each file, as before the walk, until the walk's
+ /// pickers and prompts are in (pick-ui SPEC §14.3).
+ jumps: Jumps = .@"new-pane",
+
/// A setting that is one of a few words, each an enum field of Settings.
- pub const Choice = enum { pet };
+ pub const Choice = enum { pet, jumps };
pub const Pet = enum { off, cat, frog };
+ pub const Jumps = enum { walk, @"new-pane" };
pub const tagline_percent_min: u8 = 1;
pub const tagline_percent_max: u8 = 100;
@@ -798,6 +807,7 @@ pub const Settings = struct {
.{ .word = "GripWidth", .action = .grip_width, .doc = "The grip and scrollbar width, as a percent of the theme's rail." },
.{ .word = "InactiveDim", .action = .inactive_dim, .doc = "Fade the unfocused panes' text by a percentage, 0 through 100, 0 off." },
.{ .word = "Pet", .action = .{ .choice = .pet }, .doc = "The window's companion in the workspace tag's blank space: off, cat or frog." },
+ .{ .word = "Jumps", .action = .{ .choice = .jumps }, .doc = "A jump steps its pane or that pane's reader (walk), or opens a pane for each file (new-pane)." },
.{ .word = "MessageLinger", .action = .message_linger, .doc = "How long, in milliseconds, a message stays after what dismisses it." },
.{ .word = "DumpDir", .action = .dump_dir, .doc = "The directory of the state file, where Dump writes and Recent is kept. A relative Restore name is looked for there too; bare, the default." },
.{ .word = "Theme", .action = .theme, .doc = "Switch to the theme named: `Theme atelier`. Themes lists them, NextColor steps through them." },
diff --git a/core/draw.zig b/core/draw.zig
index ff76aa75..f00a7583 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -454,7 +454,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
// its ring. A pixel shell draws the ring (gui.zig gripDecor); a grid,
// which cannot, marks dirty in the grip's second cell with a bold `*`
// on the dirty colour, a cue that survives any palette.
- const band = if (active) chrome.tag_active_bg else chrome.tag_bg;
+ const band = tagGround(p, pane, active);
const dirty = tagline.dirty(pane);
const box_bg = gripBg(p, active);
const box_style: CellStyle = .{
@@ -776,7 +776,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
layer.cols = columns;
layer.rows = rows;
layer.context_rows = 0;
- layer.bg = if (v.window_pick == id) p.theme().sel_bg else if (active) chrome.tag_active_bg else chrome.tag_bg;
+ layer.bg = if (v.window_pick == id) p.theme().sel_bg else tagGround(p, pane, active);
layer.cursor = if (v.header != null) null else if (temporary.cursor) |cursor|
.{ .x = cursor.x - TAG_TEXT_INSET, .y = cursor.y, .bar = cursor.bar }
else
@@ -793,6 +793,14 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
}
}
+/// A pane's tag's ground: a reading pane's tint (its focus is its grip's),
+/// else the focused tag's or the tag's.
+fn tagGround(p: *Pardes, pane: *const Pane, active: bool) [3]u8 {
+ const chrome = p.chromeTheme();
+ if (pardes.Trail.reading(p, pane)) return chrome.tag_reading_bg;
+ return if (active) chrome.tag_active_bg else chrome.tag_bg;
+}
+
fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void {
const th = p.theme();
const chrome = p.chromeTheme();
@@ -802,7 +810,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const rows = pane.tag_rows;
const page_rgb = th.bg orelse th.tag_bg;
// Focus is visible along the tag without changing its live text grid.
- const tag_bg = if (active) chrome.tag_active_bg else chrome.tag_bg;
+ const tag_bg = tagGround(p, pane, active);
const tag_fg = if (active) chrome.tag_active_fg else chrome.tag_fg;
const tag_style: CellStyle = .{ .fg = .{ .rgb = tag_fg }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline };
// Padding belongs to the same font row but keeps its default ink: a
@@ -1046,7 +1054,7 @@ test "a tag of three rows has its grip on the first, and band under it that stil
const top = p.tagTop(pane, r);
try std.testing.expect(pane.tag_rows >= 3);
const chrome = p.chromeTheme();
- const band = chrome.tag_active_bg;
+ const band = tagGround(p, pane, true);
for (0..config.GUTTER) |dx| {
const x = r.x + @as(u16, @intCast(dx));
try std.testing.expectEqual(Color{ .rgb = chrome.box }, s.at(x, top).style.bg);
diff --git a/core/panes.zig b/core/panes.zig
index 8939bd05..c11fdc94 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -15,6 +15,7 @@ const dump = @import("dump.zig");
const memory = @import("memory.zig");
const ctlfs = @import("ninep/tree.zig");
const Pipe = @import("Pipe.zig");
+const Trail = @import("Trail.zig");
const Key = pardes.Key;
const Cell = pardes.Cell;
const BOX_H = pardes.BOX_H;
@@ -269,6 +270,9 @@ pub const Pane = struct {
/// the current one selected (Places.zig).
places: Places = .{},
look_at: ?LookSpot = null,
+ /// Its walk: the places it stepped through, its owner when it is a
+ /// reader, whether it is held (Trail.zig, pick-ui SPEC §6).
+ trail: Trail = .{},
/// `gw`'s words, labelled in order while it waits for a label to be
/// typed (gpa-owned); `jump_first` is the label's first letter once typed.
jump: std.ArrayList(modal.Selection) = .empty,
diff --git a/core/root.zig b/core/root.zig
index 63b77964..696b08e1 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -114,6 +114,7 @@ pub const font_picker = platform == .gui or platform == .macos;
pub var turn: Turn = .{};
pub const Turn = @import("Turn.zig");
pub const Jump = @import("Jump.zig");
+pub const Trail = @import("Trail.zig");
const Loc = Jump.Loc;
pub const can_attach = platform == .tui or platform == .gui;
@@ -403,6 +404,7 @@ test {
_ = @import("Plumb.zig");
_ = @import("lsp/Ask.zig");
_ = @import("Jump.zig");
+ _ = @import("Trail.zig");
_ = @import("keys.zig");
_ = @import("Effect.zig");
_ = @import("tape.zig");
diff --git a/core/tagline.zig b/core/tagline.zig
index 02d1b277..1cab2166 100644
--- a/core/tagline.zig
+++ b/core/tagline.zig
@@ -153,8 +153,13 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co
// 3/27` (Query.zig): its owner is right above it.
if (pane.query) |q| if (pane.file) |f| if (pane.prompt != .name) return panes.Query.tagPrefix(q, arena, f.path);
// Unsaved text shows on the grip, as acme's modbutton does, not as a
- // mark in the text: the prefix is the name alone.
- if (pane.file) |f| return if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
+ // mark in the text: the prefix is the name alone, and Keep after it
+ // while a jump would step it (Trail.zig).
+ if (pane.file) |f| {
+ const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
+ if (!pardes.Trail.reading(p, pane)) return name;
+ return std.mem.concat(arena, u8, &.{ name, " Keep" });
+ }
// A terminal showing kitty graphics says how it draws them, as an image
// pane does, and so does one drawing them as glyph art by choice.
if (pane.terminal != null) {
diff --git a/core/themes/acme.zig b/core/themes/acme.zig
index 4e4e9a43..34d99805 100644
--- a/core/themes/acme.zig
+++ b/core/themes/acme.zig
@@ -49,6 +49,8 @@ pub const theme = .{
.box_dirty = .{ 0x00, 0x00, 0x99 },
.rail_px = 12,
.tag_sel_bg = .{ 0x9e, 0xee, 0xee },
+ // A reading pane's tag: the page's yellow, a shade down (pick-ui's).
+ .tag_reading_bg = .{ 0xf3, 0xf0, 0xcc },
.sweep_bg = .{ .{ 0xee, 0xee, 0x9e }, .{ 0xaa, 0x00, 0x00 }, .{ 0x00, 0x66, 0x00 } },
.sweep_fg = .{ .{ 0x00, 0x00, 0x00 }, .{ 0xff, 0xff, 0xff }, .{ 0xff, 0xff, 0xff } },
.column_box = .{ 0x88, 0x88, 0xcc },