From c72d54eb4a57bca9e614f119dfdef5bb39206979 Mon Sep 17 00:00:00 2001 From: xdavidwu Date: Wed, 29 Jun 2022 23:33:38 +0800 Subject: [PATCH] evdev-dump-events: show events by name --- tools/evdev-dump-events/main.ha | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/evdev-dump-events/main.ha b/tools/evdev-dump-events/main.ha index 8b65376..deed99b 100644 --- a/tools/evdev-dump-events/main.ha +++ b/tools/evdev-dump-events/main.ha @@ -1,9 +1,11 @@ +use errors; use evdev; use fmt; use fs; use io; -use rt; use os; +use rt; +use strconv; export fn main() void = { if (len(os::args) != 2) { @@ -37,6 +39,18 @@ export fn main() void = { fmt::fatalf("Failed to get event: {}", rt::strerror(err)); }; }; - fmt::printfln("event {} {} {}", ev._type, ev.code, ev.value)!; + match (evdev::event_type_get_name(ev._type)) { + case errors::invalid => + fmt::printf("{:-13}", ev._type)!; + case let s: const str => + fmt::printf("{:-13}", s)!; + }; + match (evdev::event_code_get_name(ev._type, ev.code)) { + case errors::invalid => + fmt::printf(" {:-29}", ev.code)!; + case let s: const str => + fmt::printf(" {:-29}", s)!; + }; + fmt::printfln(" {}", ev.value)!; }; }; -- 2.45.2