From ef5d75e328ce443541c148405b3af685547a10be Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 5 Aug 2023 21:31:34 -0700 Subject: [PATCH] input: support assigning integer binding action values This enables jump_to_prompt --- src/input/Binding.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/input/Binding.zig b/src/input/Binding.zig index e3a66527d..4dec02d6f 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -124,6 +124,14 @@ pub fn parse(input: []const u8) !Binding { break :action @unionInit(Action, field.name, value); }, + .Int => { + const idx = colonIdx orelse return Error.InvalidFormat; + const param = actionRaw[idx + 1 ..]; + const value = std.fmt.parseInt(field.type, param, 10) catch + return Error.InvalidFormat; + break :action @unionInit(Action, field.name, value); + }, + else => unreachable, }, } @@ -418,3 +426,19 @@ test "parse: action with enum" { try testing.expectEqual(Action.SplitDirection.right, binding.action.new_split); } } + +test "parse: action with int" { + const testing = std.testing; + + // parameter + { + const binding = try parse("a=jump_to_prompt:-1"); + try testing.expect(binding.action == .jump_to_prompt); + try testing.expectEqual(@as(i16, -1), binding.action.jump_to_prompt); + } + { + const binding = try parse("a=jump_to_prompt:10"); + try testing.expect(binding.action == .jump_to_prompt); + try testing.expectEqual(@as(i16, 10), binding.action.jump_to_prompt); + } +}