diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-01 10:31:23 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 10:36:28 -0300 |
| commit | 4db57bf5bd788a292fcf2cfbea3b6d8b281510f0 (patch) | |
| tree | cf0905c14c180e17c33e1e1289dfbc70b71ad84e | |
| parent | d3f60c930db06b540bb196b6323a88045e746bbf (diff) | |
| download | pardes-4db57bf5bd788a292fcf2cfbea3b6d8b281510f0.tar.gz pardes-4db57bf5bd788a292fcf2cfbea3b6d8b281510f0.zip | |
Saving the init file in a pane (Config) applies its settings at once; its commands are not run a second time
A setting changed in the init file took effect only at the next start.
The host's Save now hands a written init file's text back to the core,
which applies its setting lines again (each idempotent), with the same
notice and err for one that fails; a command line in it (`Newcol`)
belongs to the start and is left alone.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| -rw-r--r-- | src/exec.zig | 15 | ||||
| -rw-r--r-- | src/host_io.zig | 2 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 11 |
3 files changed, 27 insertions, 1 deletions
diff --git a/src/exec.zig b/src/exec.zig index 8a24969d..722ad3de 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -980,9 +980,21 @@ pub fn executeBuiltinLine(p: *Pardes, id: usize, txt: []const u8) bool { } pub fn applyStartupConfig(p: *Pardes) void { + applyInitText(p, p.opts.startup_config orelse return, false); +} + +/// The init file saved in a pane: its settings applied again. Only its +/// setting lines: a command in it (`Newcol`) is the session's start, and +/// would not be right twice. +pub fn reapplyInitFile(p: *Pardes, path: []const u8, text: []const u8) void { + const init_path = p.opts.startup_config_path orelse return; + if (!std.mem.eql(u8, init_path, path)) return; + applyInitText(p, text, true); +} + +fn applyInitText(p: *Pardes, text: []const u8, settings_only: bool) void { p.announce = false; defer p.announce = true; - const text = p.opts.startup_config orelse return; // A UTF-8 BOM an editor left at its start is no part of its first word. const body = if (std.mem.startsWith(u8, text, "\xEF\xBB\xBF")) text[3..] else text; var lines = std.mem.splitScalar(u8, body, '\n'); @@ -993,6 +1005,7 @@ pub fn applyStartupConfig(p: *Pardes) void { // `#` starts a comment only at a line's start: a value may hold one // (`#ff0000`). if (word.len == 0 or isComment(word)) continue; + if (settings_only and config.Runtime.find(word[0 .. std.mem.indexOfAny(u8, word, " \t") orelse word.len]) == null) continue; const failures = p.fs.failures; const known = executeBuiltinLine(p, p.active, line); if (known and p.fs.failures == failures) continue; diff --git a/src/host_io.zig b/src/host_io.zig index a488f0f8..8ff55d74 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -2818,6 +2818,8 @@ pub fn writeFile(core: *pardes.Pardes, watches: *file_watch.Table, pane: u8, pat }; var mbuf: [256]u8 = undefined; core.setMessage(pane, pardes.Messages.Message.stamp(&mbuf, "saved", path)); + // The init file, saved here (Config): its settings take effect now. + pardes.exec.reapplyInitFile(core, path, bytes); } /// A Dump's write, into the DumpDir. diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 2fa0cd7e..cd8bc6c9 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -4477,3 +4477,14 @@ test "the init file reads past a BOM, and every line it fails is a notice and an try testing.expect(!th.logHas(p, "line 4")); try testing.expect(th.logHas(p, "err - init file line 5: ")); } + +test "the init file saved in a pane applies its settings again, and runs none of its commands twice" { + 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 cols = p.ncol; + pardes.exec.reapplyInitFile(p, "/tmp/pardes-init-test/elsewhere", "Theme acme\n"); + try testing.expectEqualStrings("dusk", p.theme().name); + pardes.exec.reapplyInitFile(p, "/tmp/pardes-init-test/init", "Theme acme\nNewcol\n"); + try testing.expectEqualStrings("acme", p.theme().name); + try testing.expectEqual(cols, p.ncol); +} |
