refactor: move formatters for input types to input module
This commit is contained in:
parent
572f74d8ba
commit
5d381dcc7b
2 changed files with 44 additions and 16 deletions
|
@ -1,8 +1,8 @@
|
|||
const std = @import("std");
|
||||
const input = @import("input");
|
||||
|
||||
key: input.Key = 0,
|
||||
event: input.Event = input.event.press,
|
||||
key: input.Key = 0,
|
||||
modifiers: input.Mods = 0,
|
||||
|
||||
pub fn eql(self: @This(), other: @This()) bool {
|
||||
|
@ -10,19 +10,5 @@ pub fn eql(self: @This(), other: @This()) bool {
|
|||
}
|
||||
|
||||
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);
|
||||
try writer.print("{}:{}{}", .{ input.event_fmt(self.event), input.mod_fmt(self.modifiers), input.key_fmt(self.key) });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue