diff options
author | Nguyễn Gia Phong <cnx@loang.net> | 2025-07-23 17:05:59 +0900 |
---|---|---|
committer | Nguyễn Gia Phong <cnx@loang.net> | 2025-07-23 17:06:58 +0900 |
commit | 366fa5128ae8398bb31ecfbbc5d9251dd785ba28 (patch) | |
tree | 2cd458133d76ad077d75e3aae5ad21a037bdfae7 /src | |
parent | a45f2cfa8c0425ddc6738deba8b5c09e8c964a07 (diff) | |
download | kay-main.tar.gz |
Diffstat (limited to 'src')
-rw-r--r-- | src/Config.zig | 34 | ||||
-rw-r--r-- | src/main.zig | 11 |
2 files changed, 43 insertions, 2 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 .{}; +} 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 }, |