summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-02 00:58:20 -0300
committerGabriel Schneider <[email protected]>2026-10-02 00:58:20 -0300
commit39d4a7c38b12f907d8ba6c08bb14600b503a13d7 (patch)
tree7ab29d0a3ebe12958019ef46d58e68506d91d615 /src
parent6637d8df988f8cff9d054c39d3781f4a1ede3b8e (diff)
downloadpardes-39d4a7c38b12f907d8ba6c08bb14600b503a13d7.tar.gz
pardes-39d4a7c38b12f907d8ba6c08bb14600b503a13d7.zip
Get of a file not there, or of a directory, says so before asking about unsaved edits; the init file saved in a pane logs a bad line as err - init file line N, as startup does, its commands still not run again
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/builtins.zig10
-rw-r--r--src/exec.zig4
-rw-r--r--src/ninep/ctl.zig14
3 files changed, 26 insertions, 2 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index c42d4978..77e1169d 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -1150,10 +1150,18 @@ pub const Get = struct {
return panes.Dir.show(c.p, c.id, c.id);
}
if (!panes.Output.fileTraits(f.output).saves) return c.p.reportFailure(c.id, "Get: only a file pane takes it");
- if (ctl.getRefused(c.p, c.pane, "Get")) |said| return c.p.reportFailure(c.id, said);
var failed: anyerror = error.Unexpected;
var home_buf: [4096]u8 = undefined;
const path = if (typed.len == 0) c.pane.file.?.path else std.fs.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(typed, &home_buf) }) catch return;
+ // A file that is not there, or a directory, is said before unsaved
+ // edits are asked about: there would be nothing to load over them.
+ if (comptime pardes.hosted) if (typed.len > 0) if (@import("fs.zig").localPath(path)) |local| {
+ var said: [320]u8 = undefined;
+ const kind = exec.kindOf(local);
+ if (kind == null or kind.? == .directory)
+ return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Get: {s}: {s}", .{ path[0..@min(path.len, 256)], if (kind == null) "no such file" else "is a directory" }) catch "Get: no such file");
+ };
+ if (ctl.getRefused(c.p, c.pane, "Get")) |said| return c.p.reportFailure(c.id, said);
const errno = if (typed.len == 0) ctl.get(c.p, c.pane, &failed) else ctl.getFile(c.p, c.pane, path, &failed);
if (errno != 0) {
var said: [320]u8 = undefined;
diff --git a/src/exec.zig b/src/exec.zig
index a5b6e506..2a6bd55c 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -1021,7 +1021,9 @@ fn applyInitText(p: *Pardes, text: []const u8, settings_only: bool) void {
// (`#ff0000`).
if (word.len == 0 or isComment(word)) continue;
const setting = config.Runtime.find(word[0 .. std.mem.indexOfAny(u8, word, " \t") orelse word.len]);
- if (settings_only and setting == null) continue;
+ // Saved in a pane, its settings run again and its commands do not:
+ // a word that is neither (a typo) is still said, as at startup.
+ if (settings_only and setting == null and std.meta.stringToEnum(Builtin, word[0 .. std.mem.indexOfAny(u8, word, " \t+") orelse word.len]) != null) continue;
// One init file serves the window and the terminal: a setting only
// the other has (Font, GripWidth in a terminal) is no failure here.
if (setting) |s| if (!s.enabled(builtins.capabilities)) continue;
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index dc5e8386..c9ce41e1 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -2173,6 +2173,20 @@ test "round 39's small refusals: one name an open, small scratches unasked, twin
try testing.expectEqualStrings("f\n", scratch.file.?.content);
}
+test "Get of a file not there says so without asking about unsaved edits; the init file saved says a bad line as startup does" {
+ const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .startup_config = "Theme dusk\n", .startup_config_path = "/tmp/pardes-init-test/init" });
+ defer p.deinit();
+ const pane = try p.setTestFile("x\n");
+ _ = wr(p, Node.of(pane.serial, .body), "unsaved\n");
+ try testing.expect(p.executeBuiltinLine(0, "Get /tmp/pardes-surely-no-such-file.txt"));
+ try testing.expect(th.logHas(p, "no such file"));
+ try testing.expect(!th.logHas(p, "again to discard"));
+ try testing.expect(pane.discard_warned == null);
+ pardes.exec.reapplyInitFile(p, "/tmp/pardes-init-test/init", "Theme acme\nnosuchword 1\nNewcol\n");
+ try testing.expect(th.logHas(p, "err - init file line 2: unknown word \"nosuchword 1\""));
+ try testing.expect(!th.logHas(p, "init file line 3"));
+}
+
test "a body write to a terminal is typed input, not a paste, even to a program that asked for bracketed paste" {
const p = try Pardes.init(testing.allocator, .{ .cols = 90, .rows = 30 });
defer p.deinit();