summaryrefslogtreecommitdiff
path: root/core/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/builtins.zig')
-rw-r--r--core/builtins.zig68
1 files changed, 63 insertions, 5 deletions
diff --git a/core/builtins.zig b/core/builtins.zig
index 12ab9da5..32af63f7 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -797,6 +797,9 @@ pub const Themes = struct {
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.themes_buffer, .steps = true, .commands = true };
pub fn run(c: Ctx) void {
+ // From the keyboard, where the walk is on: a picker in the tag, the
+ // window wearing its row (Pick.zig, SPEC §5.1).
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .themes, "", "", "");
panes.Output.openThemes(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "themes", err);
}
};
@@ -1248,7 +1251,7 @@ pub const Del = struct {
var rec: [32]u8 = undefined;
pardes.ctlfs.events.notePath(c.p, "ask", std.fmt.bufPrint(&rec, "{d} del k j", .{c.pane.serial}) catch unreachable); // a u32 fits 32
// The question says Del already.
- if (c.pane.msg_announcement) c.pane.msg_len = 0;
+ _ = c.p.messages.retire(&.{.echo});
return;
}
c.p.removePane(c.id, to) catch |err| return c.p.reportError(.at(c.id), "close", err);
@@ -1622,6 +1625,19 @@ pub const Help = struct {
}
};
+/// Show what a key sequence runs: the next keys typed are replayed in the tag.
+///
+/// The tag shows `Keys` and the keys as they are typed; a sequence that
+/// reaches a leaf unrolls its level under the tag with the leaf on the
+/// cursor and its documentation beside it, and Enter runs it. Every root
+/// answers: SPC, g, m, z, Z, [, ], window mode's C-w. A sequence nothing
+/// is bound to is shown struck, `runs nothing`. Esc leaves it.
+pub const Keys = struct {
+ pub fn run(c: Ctx) void {
+ pardes.TagState.openDescribe(c.p, c.id);
+ }
+};
+
/// Open the startup file, `init` in the configuration directory, in a pane.
///
/// Its pane when it is open, else the file; not there yet, a pane of that
@@ -1709,12 +1725,32 @@ pub const LocationsConfig = struct {
}
};
-/// Show the messages said so far in a +Messages.
+/// Act on the message the notice row leads with.
+///
+/// An error that names places lands them as a list in the pane's walk, n
+/// and N walking them (where jumps do not walk, a +Search the Look walk
+/// steps through); a question takes the keyboard in its pane's tag (its
+/// answer's key answers it, Esc leaves it waiting); anything else opens the
+/// history.
+pub const Message = struct {
+ pub const quiet = true;
+ pub const scope: Scope = .session;
+ pub fn run(c: Ctx) void {
+ pardes.Messages.act(c.p, c.id);
+ }
+};
+
+/// Show the messages said so far, the newest first, an error's places
+/// under it.
+///
+/// Where jumps walk, a list in the pane's tag: Enter Looks a row (a
+/// message's cause, a place), C-q keeps it as a +Messages; else the
+/// +Messages.
pub const Messages = struct {
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.messages_buffer };
pub fn run(c: Ctx) void {
- panes.Output.openMessages(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "messages", err);
+ pardes.Messages.history(c.p, c.id);
}
};
@@ -1801,6 +1837,7 @@ pub const Grep = struct {
/// stays, its count 0; the write hears `not found`.
fn search(c: Ctx, source: panes.Query.Source, miss: []const u8) void {
const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, if (source == .find) .find else .grep, "", pat, "");
const reused = panes.Query.ofOwner(c.p, c.pane.serial) != null;
panes.Query.open(c.p, c.id, source, pat, pat.len == 0);
if (pat.len == 0 or !c.p.fs.serving) return;
@@ -1823,6 +1860,11 @@ pub const Search = struct {
pub fn run(c: Ctx) void {
const line = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
const asked = panes.Query.parse(line) orelse panes.Query.parse(std.mem.concat(c.p.scratch.allocator(), u8, &.{ "/", line }) catch return).?;
+ // `SPC b b`, `SPC s s`, `SPC /` and the like: a picker in the tag.
+ if (pardes.Pick.asked(c.p)) switch (asked.source) {
+ inline .find, .grep, .recent, .panes, .symbols, .all => |s| return pardes.Pick.open(c.p, c.id, @field(pardes.Pick.Source, @tagName(s)), "", asked.pat, ""),
+ else => {},
+ };
panes.Query.open(c.p, c.id, asked.source, asked.pat, true);
}
};
@@ -1844,6 +1886,7 @@ pub const Panes = struct {
pub const takes_arg = true;
pub const quiet = true;
pub fn run(c: Ctx) void {
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .panes, "", std.mem.trim(u8, c.arg orelse "", " \t\r\n"), "");
panes.Query.open(c.p, c.id, .panes, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true);
}
};
@@ -1998,6 +2041,16 @@ pub const Forward = struct {
}
};
+/// Reopen the last picker as it was: its rows, marks, cursor and query.
+///
+/// In the tag of the pane its Enter lands in from this one: this pane if it
+/// reads, else its reader. `SPC '`.
+pub const Resume = struct {
+ pub fn run(c: Ctx) void {
+ pardes.Pick.resumeFrom(c.p, c.id);
+ }
+};
+
/// 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
@@ -2062,6 +2115,7 @@ pub const Recent = struct {
// The query pane under the pane the keyboard is in, line 1
// `Recent `, typed into; what follows the word narrows the files.
if (c.p.panes[c.id] == null) return c.p.reportFailure(c.id, "Recent: open a pane to search from");
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .recent, "", std.mem.trim(u8, c.arg orelse "", " \t\r\n"), "");
panes.Query.open(c.p, c.id, .recent, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true);
}
};
@@ -2091,6 +2145,7 @@ pub const Jumplist = struct {
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.jumps_buffer, .steps = true, .locations = true };
pub fn run(c: Ctx) void {
+ if (pardes.Pick.asked(c.p)) return pardes.Pick.open(c.p, c.id, .jumplist, "", "", "");
panes.Output.openJumps(c.p, c.id) catch |err| c.p.reportError(.at(c.id), "jumplist", err);
}
};
@@ -2240,6 +2295,9 @@ pub const Rename = struct {
pub fn run(c: Ctx) void {
const a = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
if (a.len > 0) return c.p.lspRequest(c.id, .rename, a);
+ // From the keyboard, where the walk is on: typed in the pane's own
+ // tag, its edits drawn in its body as they are typed (SPEC §3.5).
+ if (pardes.Pick.asked(c.p) and c.pane.file != null) return @import("lsp/Ask.zig").openRename(c.p, c.id);
panes.startPrompt(c.p, c.pane, &c.pane.body, .{ .search = config.rename_marker });
}
};
@@ -2374,7 +2432,7 @@ test "Exit over a ctl write or a click names every pane it asks about, a second
try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), "\nExit again to discard\n"));
var noticed = false;
for (p.panes) |slot| if (slot) |pane| {
- noticed = noticed or std.mem.eql(u8, pane.msg[0..pane.msg_len], "2 unsaved panes \u{2014} Exit again to discard");
+ noticed = noticed or std.mem.eql(u8, p.messages.saidBy(pane), "2 unsaved panes \u{2014} Exit again to discard");
};
try std.testing.expect(noticed);
// Edited since: only that one is named again (acme's rule).
@@ -2474,7 +2532,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc
p.host = .{ .vtable = &killed.vtable };
// Nothing running: nothing to stop, and never the shell; said.
try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill"));
- try std.testing.expectEqualStrings("Kill: nothing running", p.panes[term].?.msg[0..p.panes[term].?.msg_len]);
+ try std.testing.expectEqualStrings("Kill: nothing running", p.messages.saidBy(p.panes[term].?));
_ = exec.execute(p, term, "make -j8");
while (p.nextEffect()) |_| {}
// Typed but not started yet (no C mark): not running.