地圖 (Jido) is a lightweight Unix TUI file explorer designed for speed and simplicity.
1const std = @import("std");
2const builtin = @import("builtin");
3const vaxis = @import("vaxis");
4const environment = @import("./environment.zig");
5
6const Config = struct {
7 show_hidden: bool = true,
8 sort_dirs: bool = true,
9 show_images: bool = true,
10 preview_file: bool = true,
11 styles: Styles,
12
13 pub fn parse(self: *Config, alloc: std.mem.Allocator) !void {
14 var config_path: []u8 = undefined;
15 defer alloc.free(config_path);
16
17 var config_home: std.fs.Dir = undefined;
18 defer config_home.close();
19 if (try environment.get_xdg_config_home_dir()) |path| {
20 config_home = path;
21 config_path = try std.fs.path.join(alloc, &.{ "zfe", "config.json" });
22 } else {
23 if (try environment.get_home_dir()) |path| {
24 config_home = path;
25 config_path = try std.fs.path.join(alloc, &.{ ".config", "zfe", "config.json" });
26 } else {
27 return error.MissingConfigHomeEnvironmentVariable;
28 }
29 }
30
31 if (!environment.file_exists(config_home, config_path)) {
32 return error.ConfigNotFound;
33 }
34
35 const config_file = try config_home.openFile(config_path, .{});
36 defer config_file.close();
37
38 const config_str = try config_file.readToEndAlloc(alloc, 1024 * 1024 * 1024);
39 defer alloc.free(config_str);
40
41 const c = try std.json.parseFromSlice(Config, alloc, config_str, .{});
42 defer c.deinit();
43
44 self.* = c.value;
45 }
46};
47
48const Styles = struct {
49 selected_list_item: vaxis.Style = vaxis.Style{
50 .bg = .{ .rgb = .{ 45, 45, 45 } },
51 .bold = true,
52 },
53 list_item: vaxis.Style = vaxis.Style{},
54 file_name: vaxis.Style = vaxis.Style{},
55 file_information: vaxis.Style = vaxis.Style{
56 .fg = .{ .rgb = .{ 0, 0, 0 } },
57 .bg = .{ .rgb = .{ 255, 255, 255 } },
58 },
59 error_bar: vaxis.Style = vaxis.Style{
60 .bg = .{ .rgb = .{ 216, 74, 74 } },
61 },
62};
63
64pub var config: Config = Config{ .styles = Styles{} };