From 67c6965eaa886f688b73543cfc416c566a6a5f80 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 2 Dec 2025 13:25:33 +0100 Subject: [PATCH] refactor: use scoped log in keybind module --- src/keybind/keybind.zig | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/keybind/keybind.zig b/src/keybind/keybind.zig index c6e4e75..ed7d1a7 100644 --- a/src/keybind/keybind.zig +++ b/src/keybind/keybind.zig @@ -15,6 +15,8 @@ const KeyEvent = input.KeyEvent; const SelectionStyle = @import("Buffer").Selection.Style; pub const CursorShape = @import("config").CursorShape; +const log = std.log.scoped(.keybind); + const parse_flow = @import("parse_flow.zig"); const parse_vim = @import("parse_vim.zig"); @@ -244,9 +246,9 @@ pub fn set_namespace(namespace_name: []const u8) LoadError!void { fn get_mode_binding_set(mode_name: []const u8, insert_command: []const u8) LoadError!*const BindingSet { const namespace = current_namespace(); var binding_set = namespace.get_mode(mode_name) orelse { - std.log.err("ERROR: mode not found: {s}", .{mode_name}); + log.err("ERROR: mode not found: {s}", .{mode_name}); var iter = namespace.modes.iterator(); - while (iter.next()) |entry| std.log.info("available modes: {s}", .{entry.key_ptr.*}); + while (iter.next()) |entry| log.info("available modes: {s}", .{entry.key_ptr.*}); return error.NotFound; }; binding_set.set_insert_command(insert_command); @@ -365,7 +367,7 @@ const Command = struct { var buf: [2048]u8 = undefined; @memcpy(buf[0..self.args.len], self.args); command.executeName(self.command, .{ .args = .{ .buf = buf[0..self.args.len] } }) catch |e| - std.log.err("ERROR: {s} {s}", .{ self.command, @errorName(e) }); + log.err("ERROR: {s} {s}", .{ self.command, @errorName(e) }); } fn has_integer_argument(id: command.ID) bool { @@ -384,7 +386,7 @@ const Command = struct { switch (state) { .command => { if (token != .string) { - std.log.err("ERROR: invalid command token {any}", .{token}); + log.err("ERROR: invalid command token {any}", .{token}); return error.InvalidFormat; } command_ = try allocator.dupe(u8, token.string); @@ -396,7 +398,7 @@ const Command = struct { else => { const json = try std.json.Stringify.valueAlloc(allocator, token, .{}); defer allocator.free(json); - std.log.err("ERROR: invalid command argument '{s}'", .{json}); + log.err("ERROR: invalid command argument '{s}'", .{json}); return error.InvalidFormat; }, } @@ -528,22 +530,22 @@ const BindingSet = struct { _ = event; bindings: for (bindings) |entry| { if (entry.len < 2) { - std.log.err("ERROR: invalid binding definition {any}", .{entry}); + log.err("ERROR: invalid binding definition {any}", .{entry}); continue :bindings; } const keys = entry[0]; if (keys != .string) { - std.log.err("ERROR: invalid binding key definition {any}", .{keys}); + log.err("ERROR: invalid binding key definition {any}", .{keys}); continue :bindings; } const key_events = switch (self.syntax) { .flow => parse_flow.parse_key_events(allocator, keys.string) catch |e| { - std.log.err("ERROR: {s} {s}", .{ @errorName(e), parse_flow.parse_error_message }); + log.err("ERROR: {s} {s}", .{ @errorName(e), parse_flow.parse_error_message }); break; }, .vim => parse_vim.parse_key_events(allocator, keys.string) catch |e| { - std.log.err("ERROR: {s} {s}", .{ @errorName(e), parse_vim.parse_error_message }); + log.err("ERROR: {s} {s}", .{ @errorName(e), parse_vim.parse_error_message }); break; }, }; @@ -559,7 +561,7 @@ const BindingSet = struct { if (cmd_entry != .array) { const json = try std.json.Stringify.valueAlloc(allocator, cmd_entry, .{}); defer allocator.free(json); - std.log.err("ERROR: invalid command definition {s}", .{json}); + log.err("ERROR: invalid command definition {s}", .{json}); continue :bindings; } try cmds.append(allocator, try Command.load(allocator, cmd_entry.array.items));