summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.zig')
-rw-r--r--src/builtins.zig82
1 files changed, 41 insertions, 41 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index a22872df..643fe5bb 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -41,13 +41,13 @@ pub const capabilities: config.Runtime.Capabilities = if (desktop) window_capabi
/// (`Pardes.frontend`, which its client says, Event.frontend).
pub fn viewCapabilities(p: *const Pardes) config.Runtime.Capabilities {
if (comptime !desktop) return frontend;
- return if (p.frontend.windowed) window_capabilities else terminal_capabilities;
+ return if (p.view().frontend.windowed) window_capabilities else terminal_capabilities;
}
/// The live view's frontend, by name (the Settings report's platform).
pub fn viewPlatform(p: *const Pardes) []const u8 {
if (comptime !desktop) return @tagName(pardes.platform);
- return if (p.frontend.windowed) "gui" else "tui";
+ return if (p.view().frontend.windowed) "gui" else "tui";
}
/// Where a builtin acts: at the pane it runs from, or on the editor as a
@@ -179,7 +179,7 @@ pub const registry = struct {
/// cannot show) in a window's view alone. The rest of a build's words are
/// every view's.
pub fn here(p: *const Pardes, b: Builtin()) bool {
- return hereFor(b, viewCapabilities(p), !desktop or p.frontend.windowed);
+ return hereFor(b, viewCapabilities(p), !desktop or p.view().frontend.windowed);
}
/// `here` for a frontend of these capabilities, windowed or not.
@@ -298,11 +298,11 @@ test "Exit asks once about unsaved text, and quits when asked again" {
const pane = try p.setTestFile("saved\n");
pane.file.?.saved_revision = pane.file.?.revision -% 1; // modified
pane.file.?.saved_hash = 0; // edited: what it had is not what it has
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(!p.quit);
try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nExit again to discard\n"));
// Told once, and nothing edited since: the second Exit quits.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(p.quit);
}
@@ -313,15 +313,15 @@ test "Exit over a ctl write or a click names every pane it asks about, a second
const first = try p.setTestFile("saved\n");
first.file.?.saved_revision = first.file.?.revision -% 1;
first.file.?.saved_hash = 0; // edited: what it had is not what it has
- p.newScratchBelow(p.active);
- const second = p.panes[p.active].?;
+ p.newScratchBelow(p.view().active);
+ const second = p.panes[p.view().active].?;
panes.File.setContent(p, &second.file.?, try std.testing.allocator.dupe(u8, &@as([120]u8, @splat('x'))));
try std.testing.expect(second.file.?.revision != second.file.?.saved_revision);
// A ctl write, or a click through exec (ctl.captured).
if (clicked) p.fs.capturing = true else p.fs.no_prompt = true;
defer p.fs.capturing = false;
defer p.fs.no_prompt = false;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(!p.quit);
// Two: counted, never a list cut short; `unsaved` records name them.
try std.testing.expectEqualStrings("2 unsaved panes: Modified (Exit again to discard)", p.fs.failure[0..p.fs.failure_len]);
@@ -340,7 +340,7 @@ test "Exit over a ctl write or a click names every pane it asks about, a second
// Edited since: only that one is named again (acme's rule).
p.fs.failure_len = 0;
panes.File.setContent(p, &second.file.?, try std.testing.allocator.dupe(u8, &@as([120]u8, @splat('y'))));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(!p.quit);
const again = p.fs.failure[0..p.fs.failure_len];
try std.testing.expect(std.mem.indexOf(u8, again, first.file.?.path) == null);
@@ -353,7 +353,7 @@ test "Exit over a ctl write or a click names every pane it asks about, a second
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), first.file.?.path) == null);
try std.testing.expect(std.mem.startsWith(u8, again, second.file.?.path));
p.fs.failure_len = 0;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(p.quit);
}
}
@@ -385,10 +385,10 @@ test "Restore asks about unsaved text as Exit does, and restores when asked agai
pane.file.?.saved_hash = 0; // edited: what it had is not what it has
var line_buf: [4200]u8 = undefined;
const line = try testDump(&line_buf);
- try std.testing.expect(p.executeBuiltinLine(p.active, line));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, line));
try std.testing.expect(p.restore_req == null);
try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nRestore again to discard\n"));
- try std.testing.expect(p.executeBuiltinLine(p.active, line));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, line));
try std.testing.expectEqualStrings(line["Restore ".len..], p.restore_req.?);
}
@@ -400,7 +400,7 @@ test "a Restore of a dump that cannot be read says so, before the unsaved-text w
pane.file.?.saved_hash = 0; // edited: what it had is not what it has
p.fs.no_prompt = true;
defer p.fs.no_prompt = false;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Restore /nope/missing.zon"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Restore /nope/missing.zon"));
try std.testing.expect(p.restore_req == null);
try std.testing.expectEqualStrings("Restore: /nope/missing.zon: no such file", p.fs.failure[0..p.fs.failure_len]);
// No warning spent: the Exit after it still asks.
@@ -414,13 +414,13 @@ test "a Restore's warning is not an Exit's: each word is warned on its own" {
pane.file.?.saved_revision = pane.file.?.revision -% 1; // modified
pane.file.?.saved_hash = 0; // edited: what it had is not what it has
var line_buf: [4200]u8 = undefined;
- try std.testing.expect(p.executeBuiltinLine(p.active, try testDump(&line_buf)));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, try testDump(&line_buf)));
try std.testing.expect(p.restore_req == null);
// The Restore warned; an Exit after it has not been, and asks.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(!p.quit);
try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nExit again to discard\n"));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(p.quit);
}
@@ -428,7 +428,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- const term = p.active;
+ const term = p.view().active;
try std.testing.expect(p.panes[term].?.isTerminal());
const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07";
p.update(.{ .output = .{ .pane = @intCast(term), .bytes = prompt } });
@@ -445,7 +445,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc
}
fn count(pp: *Pardes, line: []const u8) usize {
asked = 0;
- _ = pp.executeBuiltinLine(pp.active, line);
+ _ = pp.executeBuiltinLine(pp.view().active, line);
return asked;
}
};
@@ -1282,7 +1282,7 @@ pub const Del = struct {
{
c.pane.prompt = .del_side;
c.pane.question_due_ns = exec.clockNow(c.p) + config.del_question_delay_ns;
- c.p.active = c.id;
+ c.p.view().active = c.id;
var rec: [32]u8 = undefined;
pardes.ctlfs.events.notePath(c.p, "ask", std.fmt.bufPrint(&rec, "{d} del k j", .{c.pane.serial}) catch "");
// The question says Del already.
@@ -1515,8 +1515,8 @@ pub const Joincol = struct {
pub const scope: Scope = .session;
pub fn run(c: Ctx) void {
// The keyboard's column joins the one to its right; the last has none.
- const col = layout.keyboardColumn(c.p, c.p.active) orelse return;
- if (col + 1 >= c.p.ncol) return c.p.reportFailure(c.id, "Joincol: no column to the right");
+ const col = layout.keyboardColumn(c.p, c.p.view().active) orelse return;
+ if (col + 1 >= c.p.view().ncol) return c.p.reportFailure(c.id, "Joincol: no column to the right");
// As Newcol is refused: a column that could not give each pane its
// tag and 2 rows would leave a layout `size` refuses as it is.
if (!layout.joinFits(c.p, col)) return c.p.reportFailure(c.id, "Joincol: no space: the joined column cannot give each pane its tag and 2 rows");
@@ -1565,7 +1565,7 @@ pub const Config = struct {
panes.newScratchFor(c.p, c.id, .scratch);
if (c.p.panes[free] == null) return;
@import("ninep/pane.zig").nameBuffer(c.p, free, path, false) catch |err| return c.p.reportError(c.id, "Config", err);
- c.p.active = free;
+ c.p.view().active = free;
}
};
@@ -1723,7 +1723,7 @@ pub const Panes = struct {
/// Move the keyboard to the pane, or column tag, to the left.
pub const Left = struct {
pub fn run(c: Ctx) void {
- if (c.p.header != null) {
+ if (c.p.view().header != null) {
if (c.p.headerColumn()) |column| if (column > 0) tagline.enterHeader(c.p, column - 1);
return;
}
@@ -1734,16 +1734,16 @@ pub const Left = struct {
/// Move the keyboard to the pane below, off a tag onto the pane under it.
pub const Down = struct {
pub fn run(c: Ctx) void {
- if (c.p.header != null) {
+ if (c.p.view().header != null) {
const column = layout.findPane(c.p, c.id);
if (c.p.headerColumn() == null and layout.columnBarHeight(c.p) > 0)
return tagline.enterHeader(c.p, if (column) |at| at.col else 0);
// Onto the top pane of the column the header stands over.
const col = c.p.headerColumn() orelse if (column) |at| at.col else return;
// An empty column's tag has nothing below it.
- if (col < c.p.ncol and c.p.cols[col].n == 0) return;
+ if (col < c.p.view().ncol and c.p.view().cols[col].n == 0) return;
tagline.exitHeader(c.p);
- if (col < c.p.ncol) c.p.active = c.p.cols[col].panes[0];
+ if (col < c.p.view().ncol) c.p.view().active = c.p.view().cols[col].panes[0];
return;
}
_ = layout.focusDir(c.p, c.id, .down);
@@ -1753,7 +1753,7 @@ pub const Down = struct {
/// Move the keyboard to the pane above, and from a column's top pane to its tag.
pub const Up = struct {
pub fn run(c: Ctx) void {
- if (c.p.header != null) {
+ if (c.p.view().header != null) {
if (c.p.headerColumn() != null and c.p.topBarHeight() > 0) tagline.enterHeader(c.p, null);
return;
}
@@ -1767,8 +1767,8 @@ pub const Up = struct {
/// Move the keyboard to the pane, or column tag, to the right.
pub const Right = struct {
pub fn run(c: Ctx) void {
- if (c.p.header != null) {
- if (c.p.headerColumn()) |column| if (column + 1 < c.p.ncol) tagline.enterHeader(c.p, column + 1);
+ if (c.p.view().header != null) {
+ if (c.p.headerColumn()) |column| if (column + 1 < c.p.view().ncol) tagline.enterHeader(c.p, column + 1);
return;
}
_ = layout.focusDir(c.p, c.id, .right);
@@ -1780,7 +1780,7 @@ pub const Right = struct {
pub const Window = struct {
pub fn run(c: Ctx) void {
tagline.exitHeader(c.p);
- c.p.window_pick = if (c.p.panes[c.id] != null) c.id else c.p.active;
+ c.p.view().window_pick = if (c.p.panes[c.id] != null) c.id else c.p.view().active;
}
};
@@ -1821,10 +1821,10 @@ pub const LookPrev = struct {
/// Go back to the last place jumped from in another pane.
pub const Last = struct {
pub fn run(c: Ctx) void {
- var i = c.p.jumps.n;
+ var i = c.p.view().jumps.n;
while (i > 0) {
i -= 1;
- const j = c.p.jumps.list[i];
+ const j = c.p.view().jumps.list[i];
if (j.serial == 0) continue; // a closed file's: Back reopens it, Last goes to a pane
// Restore the cursor without recentering the pane's retained view.
if (j.pane != c.id) return look.focusPaneLine(c.p, j.pane, .{ .line = j.line, .col = j.col }, .keep);
@@ -2006,25 +2006,25 @@ test "Exit and Restore name a modified +New scratch as well as files" {
const file = try p.setTestFile("saved\n");
file.file.?.saved_revision = file.file.?.revision -% 1; // modified
file.file.?.saved_hash = 0; // edited: what it had is not what it has
- p.newScratchBelow(p.active);
- const scratch = &p.panes[p.active].?.file.?;
+ p.newScratchBelow(p.view().active);
+ const scratch = &p.panes[p.view().active].?.file.?;
scratch.content = try p.gpa.realloc(scratch.content, 120);
@memset(scratch.content, 'n'); // past acme's 100 bytes, where it whines
scratch.revision +%= 1; // typed into, never saved
scratch.saved_hash = 0; // edited: what it had is not what it has
p.fs.no_prompt = true;
defer p.fs.no_prompt = false;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Exit"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Exit"));
try std.testing.expect(!p.quit);
// Each pane's message row names it; the write's refusal counts them.
try std.testing.expectEqualStrings("2 unsaved panes: Modified (Exit again to discard)", p.fs.failure[0..p.fs.failure_len]);
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), "test.txt: Modified") != null);
- const scratch_pane = p.panes[p.active].?;
+ const scratch_pane = p.panes[p.view().active].?;
var named: [64]u8 = undefined;
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), try std.fmt.bufPrint(&named, "{s} (pane {d})", .{ config.scratch_buffer, scratch_pane.serial })) != null);
// Delcol, Restore and Exit name it the same way.
p.fs.failure_len = 0;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Delcol"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Delcol"));
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), "Delcol again to discard") == null);
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), named[0 .. config.scratch_buffer.len + 7]) != null);
}
@@ -2036,22 +2036,22 @@ test "Del and Delcol refuse a pane with unsaved text once, as acme's do, and clo
pane.file.?.saved_revision = pane.file.?.revision -% 1; // modified
pane.file.?.saved_hash = 0; // edited: what it had is not what it has
const serial = pane.serial;
- try std.testing.expect(p.executeBuiltinLine(p.active, "Delcol"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Delcol"));
try std.testing.expect(p.paneBySerial(serial) != null);
// A refused Delcol changes nothing: no +Unsaved (its records say it).
try std.testing.expect(std.mem.indexOf(u8, unsavedList(p), "Delcol") == null);
// Each word is warned on its own: Del asks too, then closes.
- try std.testing.expect(p.executeBuiltinLine(p.active, "Del"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Del"));
try std.testing.expect(p.paneBySerial(serial) != null);
try std.testing.expect(std.mem.endsWith(u8, unsavedList(p), ": Modified\n\nDel again to discard\n"));
- try std.testing.expect(p.executeBuiltinLine(p.active, "Del"));
+ try std.testing.expect(p.executeBuiltinLine(p.view().active, "Del"));
try std.testing.expect(p.paneBySerial(serial) == null);
}
test "a pane renamed but never edited has no text to lose: Del closes it at once" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
- p.newScratchBelow(p.active);
+ p.newScratchBelow(p.view().active);
const pane = try p.setTestFile("loaded\n");
pane.file.?.saved_revision = pane.file.?.revision -% 1; // dirty by the rename alone
const serial = pane.serial;