summary refs log tree commit diff
path: root/src/Config.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Config.zig')
-rw-r--r--src/Config.zig34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Config.zig b/src/Config.zig
new file mode 100644
index 0000000..51fc885
--- /dev/null
+++ b/src/Config.zig
@@ -0,0 +1,34 @@
+// Configuration
+// SPDX-FileCopyrightText: 2025 Nguyễn Gia Phong
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+const Allocator = std.mem.Allocator;
+const cwd = std.fs.cwd;
+const maxInt = std.math.maxInt;
+const joinPath = std.fs.path.joinZ;
+const std = @import("std");
+
+const folders = @import("known-folders");
+const zsanett = @import("zsanett");
+
+const Config = @This();
+tab_width: u8 = 8,
+
+pub fn parse(allocator: Allocator, env: *zsanett.Table) !Config {
+    if (try folders.getPath(allocator, .local_configuration)) |local_conf| {
+        defer allocator.free(local_conf);
+        const path = try joinPath(allocator, &.{
+            local_conf,
+            "kay",
+            "config.janet"
+        });
+        defer allocator.free(path);
+        if (cwd().readFileAlloc(allocator, path, maxInt(u32))) |content| {
+            defer allocator.free(content);
+            return try zsanett.eval(Config, env, content, path.ptr);
+        } else |err| switch (err) {
+            error.FileNotFound => return .{},
+            else => return err,
+        }
+    } else return .{};
+}