summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/colors.zig13
-rw-r--r--src/dump.zig10
-rw-r--r--src/ninep/ctl.zig6
3 files changed, 29 insertions, 0 deletions
diff --git a/src/colors.zig b/src/colors.zig
index a45184c8..2dcb906a 100644
--- a/src/colors.zig
+++ b/src/colors.zig
@@ -837,6 +837,19 @@ pub fn loadThemeFile(p: *Pardes, generation: u32, bytes: []const u8, animate: bo
return true;
}
+/// A Restore's: the theme `old` showed, its loaded theme file's included,
+/// for one that is to load a ThemeFile and keep this if it fails;
+/// `index` too when the dump names no Theme.
+pub fn carryTheme(p: *Pardes, old: *const Pardes, index: bool) !void {
+ if (index) p.settings.theme = old.settings.theme;
+ const t = old.custom_theme orelse return;
+ var copy = t;
+ copy.name = try p.gpa.dupe(u8, t.name);
+ if (p.custom_theme) |mine| std.zon.parse.free(p.gpa, mine);
+ p.custom_theme = copy;
+ _ = p.theme_file_loaded.set(old.theme_file_loaded.get());
+}
+
pub fn finishThemeInitialization(p: *Pardes) void {
p.chrome_animation.snap(ChromeTheme.fromTheme(p.theme()));
p.animate_theme_changes = true;
diff --git a/src/dump.zig b/src/dump.zig
index e76bb1a2..fa21eaa4 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -888,6 +888,16 @@ fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previo
p.locations_config = st.locations_config;
p.settings.tree_context_tag_style = st.tree_context_tag_style;
applySettings(p, st.settings);
+ // A dump naming a ThemeFile asks the host to load it again: until it
+ // has, and for good if it fails, the theme this session showed goes on
+ // (a failed ThemeFile changes nothing, a Restore's included), unless
+ // the dump names a Theme of its own.
+ if (previous) |old| if (p.theme_file_path.get().len > 0) {
+ const names_theme = for (st.settings) |line| {
+ if (std.mem.startsWith(u8, line, "Theme ")) break true;
+ } else false;
+ try colors.carryTheme(p, old, !names_theme);
+ };
for (st.mounts) |mount| {
var already_mounted = false;
for (p.fs.mounts.items) |existing| {
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index b7c529e1..a5a36464 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -2102,6 +2102,12 @@ test "a Restore asks again for the ThemeFile the dump names, as a /ctl write of
else => {},
} else return error.NoThemeFileAsked;
try testing.expectEqualStrings(good, pardes.colors.themeFileRequest(restored, asked.generation).?.path);
+ // The file broken since, the load fails: the restored session still
+ // shows the theme the old one did, and names the file it loaded.
+ try testing.expectEqualStrings("restored", restored.theme().name);
+ pardes.colors.failThemeFile(restored, asked.generation, error.ParseZon);
+ try testing.expectEqualStrings("restored", restored.theme().name);
+ try testing.expectEqualStrings(good, restored.theme_file_path.get());
}
test "a ThemeFile that fails to load changes nothing: the root ctl still names the one loaded, or none" {