aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-01-01 21:01:39 +0100
committerdec05eba <dec05eba@protonmail.com>2024-01-01 21:01:39 +0100
commite8c0da93a7393e25818da7bc8e93b600060aa662 (patch)
tree6c760b2ed73d0b615d1aa41e863b39d23018f464 /src/main.zig
parent5d22db4adac6d21845e3450ef6b95b818307a4fe (diff)
Better example, formatHEADmaster
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/main.zig b/src/main.zig
index 9969741..718c6ed 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -11,18 +11,18 @@ pub fn main() !void {
var args = std.process.args();
defer args.deinit();
- if(!args.skip())
+ if (!args.skip())
usage();
var input_filepath: []const u8 = "";
- if(args.next()) |arg| {
+ if (args.next()) |arg| {
input_filepath = arg[0..arg.len];
} else {
std.debug.print("error: missing required argument input_device\n", .{});
usage();
}
- while(args.next()) |arg| {
+ while (args.next()) |arg| {
const keybind = Keybind.parse_string(arg) catch {
std.debug.print("error: invalid keybind: {s}\n", .{arg});
usage();
@@ -38,22 +38,22 @@ pub fn main() !void {
defer std.os.close(event_fd);
var event: c.js_event = undefined;
- while(true) {
+ while (true) {
const read_size = try std.os.read(event_fd, std.mem.asBytes(&event));
- if(read_size != @sizeOf(@TypeOf(event)))
+ if (read_size != @sizeOf(@TypeOf(event)))
continue;
- if(event.type & c.JS_EVENT_BUTTON == 0)
+ if (event.type & c.JS_EVENT_BUTTON == 0)
continue;
- if(event.value != 1)
+ if (event.value != 1)
continue;
- for(keybinds.items) |*keybind| {
- if(event.number != keybind.key)
+ for (keybinds.items) |*keybind| {
+ if (event.number != keybind.key)
continue;
- std.debug.print("key pressed: {d}, running command: {s}\n", .{keybind.key, keybind.command});
+ std.debug.print("key pressed: {d}, running command: {s}\n", .{ keybind.key, keybind.command });
keybind.execute_command(allocator);
}
}
@@ -68,8 +68,8 @@ fn usage() void {
\\ binds There may be multiple keybindings in the format key,command
\\
\\EXAMPLES:
- \\ zbind /dev/input/by-id/usb-Joystick "0,echo 'hello world' > log.log" "4,script.sh"
- , .{});
+ \\ zbind /dev/input/js0 "0,echo 'hello world' > log.log" "4,script.sh"
+ , .{});
std.os.exit(1);
}
@@ -94,4 +94,4 @@ const Keybind = struct {
child.spawn() catch return;
_ = child.wait() catch return;
}
-}; \ No newline at end of file
+};