diff --git a/src/main.zig b/src/main.zig index afc2c3f..9b2a50b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -406,6 +406,16 @@ pub fn free_config(allocator: std.mem.Allocator, bufs: [][]const u8) void { var config_mutex: std.Thread.Mutex = .{}; +pub fn exists_config(T: type) bool { + config_mutex.lock(); + defer config_mutex.unlock(); + const json_file_name = get_app_config_file_name(application_name, @typeName(T)) catch return false; + const text_file_name = json_file_name[0 .. json_file_name.len - ".json".len]; + var file = std.fs.openFileAbsolute(text_file_name, .{ .mode = .read_only }) catch return false; + defer file.close(); + return true; +} + pub fn read_config(T: type, allocator: std.mem.Allocator) struct { T, [][]const u8 } { config_mutex.lock(); defer config_mutex.unlock(); diff --git a/src/tui/status/tabs.zig b/src/tui/status/tabs.zig index 1a56aa0..537137d 100644 --- a/src/tui/status/tabs.zig +++ b/src/tui/status/tabs.zig @@ -80,8 +80,11 @@ const TabBar = struct { fn init(allocator: std.mem.Allocator, parent: Plane, event_handler: ?EventHandler) !Self { var w = try WidgetList.createH(allocator, parent, "tabs", .dynamic); w.ctx = w; - const tab_style, const tab_style_bufs = root.read_config(Style, allocator); - root.write_config(tab_style, allocator) catch {}; + const tab_style, const tab_style_bufs: [][]const u8 = if (root.exists_config(Style)) blk: { + const tab_style, const tab_style_bufs = root.read_config(Style, allocator); + root.write_config(tab_style, allocator) catch {}; + break :blk .{ tab_style, tab_style_bufs }; + } else .{ Style{}, &.{} }; return .{ .allocator = allocator, .plane = w.plane,