refactor: log event and match counts in dynamic keybind
This commit is contained in:
parent
18f321bf41
commit
14167d7869
2 changed files with 31 additions and 2 deletions
|
@ -8,3 +8,21 @@ modifiers: input.Mods = 0,
|
||||||
pub fn eql(self: @This(), other: @This()) bool {
|
pub fn eql(self: @This(), other: @This()) bool {
|
||||||
return std.meta.eql(self, other);
|
return std.meta.eql(self, other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn format(self: @This(), comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
|
||||||
|
if (self.event == input.event.press) try writer.writeAll("press ");
|
||||||
|
if (self.event == input.event.repeat) try writer.writeAll("repeat ");
|
||||||
|
if (self.event == input.event.release) try writer.writeAll("release ");
|
||||||
|
const mods: input.ModSet = @bitCast(self.modifiers);
|
||||||
|
if (mods.super) try writer.writeAll("super+");
|
||||||
|
if (mods.ctrl) try writer.writeAll("ctrl+");
|
||||||
|
if (mods.alt) try writer.writeAll("alt+");
|
||||||
|
if (mods.shift) try writer.writeAll("shift+");
|
||||||
|
var key_string = input.utils.key_id_string(self.key);
|
||||||
|
var buf: [6]u8 = undefined;
|
||||||
|
if (key_string.len == 0) {
|
||||||
|
const bytes = try input.ucs32_to_utf8(&[_]u32{self.key}, &buf);
|
||||||
|
key_string = buf[0..bytes];
|
||||||
|
}
|
||||||
|
try writer.writeAll(key_string);
|
||||||
|
}
|
||||||
|
|
|
@ -587,17 +587,26 @@ const BindingSet = struct {
|
||||||
try self.current_sequence_egc.appendSlice(buf[0..bytes]);
|
try self.current_sequence_egc.appendSlice(buf[0..bytes]);
|
||||||
|
|
||||||
var all_matches_impossible = true;
|
var all_matches_impossible = true;
|
||||||
defer if (!builtin.is_test) self.logger.print("process_key_event all_matches_impossible:{any} event:{any} egc:{d} text:'{s}' sequence:'{s}' bindings:{d}", .{
|
var matched_count: usize = 0;
|
||||||
all_matches_impossible,
|
var match_possible_count: usize = 0;
|
||||||
|
var match_impossible_count: usize = 0;
|
||||||
|
if (!builtin.is_test) self.logger.print("process_key_event begin event:{} egc:{d} text:'{s}' sequence:'{s}' bindings:{d}", .{
|
||||||
event,
|
event,
|
||||||
egc,
|
egc,
|
||||||
buf[0..bytes],
|
buf[0..bytes],
|
||||||
self.current_sequence_egc.items,
|
self.current_sequence_egc.items,
|
||||||
self.bindings.items.len,
|
self.bindings.items.len,
|
||||||
});
|
});
|
||||||
|
defer if (!builtin.is_test) self.logger.print("process_key_event end all_matches_impossible:{any} bindings matched:{d} possible:{d} impossible:{d}", .{
|
||||||
|
all_matches_impossible,
|
||||||
|
matched_count,
|
||||||
|
match_possible_count,
|
||||||
|
match_impossible_count,
|
||||||
|
});
|
||||||
for (self.bindings.items) |binding| blk: {
|
for (self.bindings.items) |binding| blk: {
|
||||||
switch (binding.match(self.current_sequence.items)) {
|
switch (binding.match(self.current_sequence.items)) {
|
||||||
.matched => {
|
.matched => {
|
||||||
|
matched_count += 1;
|
||||||
errdefer {
|
errdefer {
|
||||||
//clear current sequence if command execution fails
|
//clear current sequence if command execution fails
|
||||||
self.current_sequence.clearRetainingCapacity();
|
self.current_sequence.clearRetainingCapacity();
|
||||||
|
@ -614,10 +623,12 @@ const BindingSet = struct {
|
||||||
break :blk;
|
break :blk;
|
||||||
},
|
},
|
||||||
.match_possible => {
|
.match_possible => {
|
||||||
|
match_possible_count += 1;
|
||||||
if (!builtin.is_test) self.logger.print("match possible for binding -> {s}", .{binding.command});
|
if (!builtin.is_test) self.logger.print("match possible for binding -> {s}", .{binding.command});
|
||||||
all_matches_impossible = false;
|
all_matches_impossible = false;
|
||||||
},
|
},
|
||||||
.match_impossible => {
|
.match_impossible => {
|
||||||
|
match_impossible_count += 1;
|
||||||
if (!builtin.is_test) self.logger.print("match impossible for binding -> {s}", .{binding.command});
|
if (!builtin.is_test) self.logger.print("match impossible for binding -> {s}", .{binding.command});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue