refactor: use scoped log in keybind module
This commit is contained in:
parent
fb5c67280f
commit
67c6965eaa
1 changed files with 12 additions and 10 deletions
|
|
@ -15,6 +15,8 @@ const KeyEvent = input.KeyEvent;
|
||||||
const SelectionStyle = @import("Buffer").Selection.Style;
|
const SelectionStyle = @import("Buffer").Selection.Style;
|
||||||
pub const CursorShape = @import("config").CursorShape;
|
pub const CursorShape = @import("config").CursorShape;
|
||||||
|
|
||||||
|
const log = std.log.scoped(.keybind);
|
||||||
|
|
||||||
const parse_flow = @import("parse_flow.zig");
|
const parse_flow = @import("parse_flow.zig");
|
||||||
const parse_vim = @import("parse_vim.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 {
|
fn get_mode_binding_set(mode_name: []const u8, insert_command: []const u8) LoadError!*const BindingSet {
|
||||||
const namespace = current_namespace();
|
const namespace = current_namespace();
|
||||||
var binding_set = namespace.get_mode(mode_name) orelse {
|
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();
|
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;
|
return error.NotFound;
|
||||||
};
|
};
|
||||||
binding_set.set_insert_command(insert_command);
|
binding_set.set_insert_command(insert_command);
|
||||||
|
|
@ -365,7 +367,7 @@ const Command = struct {
|
||||||
var buf: [2048]u8 = undefined;
|
var buf: [2048]u8 = undefined;
|
||||||
@memcpy(buf[0..self.args.len], self.args);
|
@memcpy(buf[0..self.args.len], self.args);
|
||||||
command.executeName(self.command, .{ .args = .{ .buf = buf[0..self.args.len] } }) catch |e|
|
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 {
|
fn has_integer_argument(id: command.ID) bool {
|
||||||
|
|
@ -384,7 +386,7 @@ const Command = struct {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
.command => {
|
.command => {
|
||||||
if (token != .string) {
|
if (token != .string) {
|
||||||
std.log.err("ERROR: invalid command token {any}", .{token});
|
log.err("ERROR: invalid command token {any}", .{token});
|
||||||
return error.InvalidFormat;
|
return error.InvalidFormat;
|
||||||
}
|
}
|
||||||
command_ = try allocator.dupe(u8, token.string);
|
command_ = try allocator.dupe(u8, token.string);
|
||||||
|
|
@ -396,7 +398,7 @@ const Command = struct {
|
||||||
else => {
|
else => {
|
||||||
const json = try std.json.Stringify.valueAlloc(allocator, token, .{});
|
const json = try std.json.Stringify.valueAlloc(allocator, token, .{});
|
||||||
defer allocator.free(json);
|
defer allocator.free(json);
|
||||||
std.log.err("ERROR: invalid command argument '{s}'", .{json});
|
log.err("ERROR: invalid command argument '{s}'", .{json});
|
||||||
return error.InvalidFormat;
|
return error.InvalidFormat;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -528,22 +530,22 @@ const BindingSet = struct {
|
||||||
_ = event;
|
_ = event;
|
||||||
bindings: for (bindings) |entry| {
|
bindings: for (bindings) |entry| {
|
||||||
if (entry.len < 2) {
|
if (entry.len < 2) {
|
||||||
std.log.err("ERROR: invalid binding definition {any}", .{entry});
|
log.err("ERROR: invalid binding definition {any}", .{entry});
|
||||||
continue :bindings;
|
continue :bindings;
|
||||||
}
|
}
|
||||||
const keys = entry[0];
|
const keys = entry[0];
|
||||||
if (keys != .string) {
|
if (keys != .string) {
|
||||||
std.log.err("ERROR: invalid binding key definition {any}", .{keys});
|
log.err("ERROR: invalid binding key definition {any}", .{keys});
|
||||||
continue :bindings;
|
continue :bindings;
|
||||||
}
|
}
|
||||||
|
|
||||||
const key_events = switch (self.syntax) {
|
const key_events = switch (self.syntax) {
|
||||||
.flow => parse_flow.parse_key_events(allocator, keys.string) catch |e| {
|
.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;
|
break;
|
||||||
},
|
},
|
||||||
.vim => parse_vim.parse_key_events(allocator, keys.string) catch |e| {
|
.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;
|
break;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -559,7 +561,7 @@ const BindingSet = struct {
|
||||||
if (cmd_entry != .array) {
|
if (cmd_entry != .array) {
|
||||||
const json = try std.json.Stringify.valueAlloc(allocator, cmd_entry, .{});
|
const json = try std.json.Stringify.valueAlloc(allocator, cmd_entry, .{});
|
||||||
defer allocator.free(json);
|
defer allocator.free(json);
|
||||||
std.log.err("ERROR: invalid command definition {s}", .{json});
|
log.err("ERROR: invalid command definition {s}", .{json});
|
||||||
continue :bindings;
|
continue :bindings;
|
||||||
}
|
}
|
||||||
try cmds.append(allocator, try Command.load(allocator, cmd_entry.array.items));
|
try cmds.append(allocator, try Command.load(allocator, cmd_entry.array.items));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue