地圖 (Jido) is a lightweight Unix TUI file explorer designed for speed and simplicity.

feat: Duplicate keybind notification now includes additional information

+12 -9
+2 -2
src/app.zig
··· 135 135 } 136 136 137 137 if ((key.codepoint == 'r' and key.mods.ctrl)) { 138 - if (config.parse(self.alloc)) { 138 + if (config.parse(self.alloc, self)) { 139 139 try self.notification.writeInfo(.ConfigReloaded); 140 140 } else |err| switch (err) { 141 141 error.SyntaxError => { ··· 145 145 try self.notification.writeErr(.InvalidKeybind); 146 146 }, 147 147 error.DuplicateKeybind => { 148 - try self.notification.writeErr(.DuplicateKeybinds); 148 + // Error logged in function 149 149 }, 150 150 else => { 151 151 try self.notification.writeErr(.ConfigUnknownError);
+8 -3
src/config.zig
··· 4 4 const vaxis = @import("vaxis"); 5 5 const FileLogger = @import("file_logger.zig"); 6 6 const Notification = @import("./notification.zig"); 7 + const App = @import("./app.zig"); 7 8 8 9 const CONFIG_NAME = "config.json"; 9 10 const TRASH_DIR_NAME = "trash"; ··· 42 43 return try parent.openDir(TRASH_DIR_NAME, .{ .iterate = true }); 43 44 } 44 45 45 - pub fn parse(self: *Config, alloc: std.mem.Allocator) !void { 46 + pub fn parse(self: *Config, alloc: std.mem.Allocator, app: *App) !void { 46 47 var dir = lbl: { 47 48 if (try environment.getXdgConfigHomeDir()) |home_dir| { 48 49 defer { ··· 122 123 123 124 const res = try key_map.getOrPut(codepoint); 124 125 if (res.found_existing) { 126 + var keybind_str: [1024]u8 = undefined; 127 + const keybind_str_bytes = try std.unicode.utf8Encode(codepoint, &keybind_str); 128 + 125 129 const message = try std.fmt.allocPrint( 126 130 alloc, 127 - "'{s}' and '{s}' have the same keybind: '{d}'", 128 - .{ res.value_ptr.*, field.name, codepoint }, 131 + "'{s}' and '{s}' have the same keybind: '{s}'", 132 + .{ res.value_ptr.*, field.name, keybind_str[0..keybind_str_bytes] }, 129 133 ); 130 134 defer alloc.free(message); 131 135 136 + try app.notification.write(message, .err); 132 137 file_logger.write(message, .err) catch {}; 133 138 134 139 return error.DuplicateKeybind;
+2 -2
src/main.zig
··· 27 27 var app = try App.init(alloc); 28 28 defer app.deinit(); 29 29 30 - config.parse(alloc) catch |err| switch (err) { 30 + config.parse(alloc, &app) catch |err| switch (err) { 31 31 error.SyntaxError => { 32 32 try app.notification.writeErr(.ConfigSyntaxError); 33 33 }, ··· 35 35 try app.notification.writeErr(.InvalidKeybind); 36 36 }, 37 37 error.DuplicateKeybind => { 38 - try app.notification.writeErr(.DuplicateKeybinds); 38 + // Error logged in function 39 39 }, 40 40 else => { 41 41 try app.notification.writeErr(.ConfigUnknownError);
-2
src/notification.zig
··· 28 28 ConfigUnknownError, 29 29 ConfigPathNotFound, 30 30 CannotDeleteTrashDir, 31 - DuplicateKeybinds, 32 31 InvalidKeybind, 33 32 NotADir, 34 33 }; ··· 80 79 .ConfigUnknownError => self.write("Could not read config due to an unknown error.", .err), 81 80 .ConfigPathNotFound => self.write("Could not read config due to unset env variables. Please set either $HOME or $XDG_CONFIG_HOME.", .err), 82 81 .CannotDeleteTrashDir => self.write("Cannot delete trash directory.", .err), 83 - .DuplicateKeybinds => self.write("Config has keybinds with the same key. This can lead to undefined behaviour. Check log file for more information.", .err), 84 82 .InvalidKeybind => self.write("Config has keybind(s) with invalid key(s).", .err), 85 83 }; 86 84 }