diff --git a/build.zig b/build.zig
index 310cdfc..2c5dcbb 100644
--- a/build.zig
+++ b/build.zig
@@ -60,7 +60,7 @@ pub fn build(b: *Build) !void {
.target = b.standardTargetOptions(.{}),
.optimize = b.standardOptimizeOption(.{}),
});
- inline for (.{ "tree-sitter", "vaxis" }) |lib|
+ inline for (.{ "known-folders", "tree-sitter", "vaxis", "zsanett" }) |lib|
mod.addImport(lib, b.dependency(lib, .{}).module(lib));
try linkTreeSitterGrammars(b, mod);
diff --git a/build.zig.zon b/build.zig.zon
index 51bce35..a65c537 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -4,6 +4,10 @@
.fingerprint = 0xeefc6ead9221517a,
.minimum_zig_version = "0.14.1",
.dependencies = .{
+ .@"known-folders" = .{
+ .url = "git+https://github.com/ziglibs/known-folders.git#92defaee76b07487769ca352fd0ba95bc8b42a2f",
+ .hash = "known_folders-0.0.0-Fy-PJkfRAAAVdptXWXBspIIC7EkVgLgWozU5zIk5Zgcy",
+ },
.@"tree-sitter" = .{
.url = "git+https://github.com/tree-sitter/zig-tree-sitter#b4b72c903e69998fc88e27e154a5e3cc9166551b",
.hash = "tree_sitter-0.25.0-8heIf51vAQConvVIgvm-9mVIbqh7yabZYqPXfOpS3YoG",
@@ -12,6 +16,10 @@
.url = "git+https://github.com/rockorager/libvaxis#cc9154d5f4afa3fdfd289157f195ec67804ef437",
.hash = "vaxis-0.5.1-BWNV_MYNCQDO92x2PTpsfv6GwDHmjL98rf6iL3pbMLj4",
},
+ .zsanett = .{
+ .url = "git+https://trong.loang.net/~cnx/zsanett#f9aadd1c3e5407521af2f5d2af66e0d2936b362b",
+ .hash = "zsanett-0.0.0-1TMqaNnFAAAl2HUPcmy9fpePQQUi1j-2WxR1tgrFZS1M",
+ },
},
.paths = .{
"LICENSES",
diff --git a/manifest.scm b/manifest.scm
index 3e5deec..4ce920d 100644
--- a/manifest.scm
+++ b/manifest.scm
@@ -22,4 +22,4 @@
(map (lambda (language)
(string-append "tree-sitter-" (string-map _->- language)))
(read-lines "src/supported-languages"))))
- (specifications->manifest (cons "zig" tree-sitter-grammars)))
+ (specifications->manifest (cons* "zig" "janet" tree-sitter-grammars)))
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 .{};
+}
diff --git a/src/main.zig b/src/main.zig
index cf99cad..5e91719 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -17,7 +17,9 @@ const Unicode = vaxis.Unicode;
const Winsize = vaxis.Winsize;
const gwidth = vaxis.gwidth.gwidth;
const vaxis = @import("vaxis");
+const zsanett = @import("zsanett");
+const Config = @import("Config.zig");
const Token = @import("Token.zig");
const languages = @import("languages");
@@ -34,6 +36,11 @@ pub fn main() !void {
.ReleaseFast, .ReleaseSmall => smp_allocator,
};
+ zsanett.init();
+ defer zsanett.deinit();
+ const janet_env = zsanett.coreEnv(null);
+ const config = try Config.parse(allocator, janet_env);
+
var tty = try Tty.init();
defer tty.deinit();
var vx = try vaxis.init(allocator, .{});
@@ -77,10 +84,10 @@ pub fn main() !void {
continue;
}
const width: u8 = if (eql(u8, bytes, "\t"))
- 8 // TODO: make configurable
+ config.tab_width
else
@intCast(gwidth(bytes, vx.caps.unicode,
- &vx.unicode.width_data));
+ &vx.unicode.width_data));
defer col += width;
window.writeCell(col, row, .{
.char = .{ .grapheme = bytes, .width = width },
|