refactor: merge BindingSet functions init and load_json
This commit is contained in:
parent
ce76589f5c
commit
00597ce93f
1 changed files with 5 additions and 4 deletions
|
@ -50,9 +50,8 @@ fn Handler(namespace_name: []const u8, mode_name: []const u8) type {
|
||||||
const self: *@This() = try allocator.create(@This());
|
const self: *@This() = try allocator.create(@This());
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.bindings = try BindingSet.init(allocator),
|
.bindings = try BindingSet.init(allocator, @embedFile("keybindings.json"), namespace_name, mode_name),
|
||||||
};
|
};
|
||||||
try self.bindings.load_json(@embedFile("keybindings.json"), namespace_name, mode_name);
|
|
||||||
return EventHandler.to_owned(self);
|
return EventHandler.to_owned(self);
|
||||||
}
|
}
|
||||||
pub fn deinit(self: *@This()) void {
|
pub fn deinit(self: *@This()) void {
|
||||||
|
@ -459,8 +458,8 @@ const BindingSet = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(allocator: std.mem.Allocator) !@This() {
|
fn init(allocator: std.mem.Allocator, json_string: []const u8, namespace_name: []const u8, mode_name: []const u8) !@This() {
|
||||||
return .{
|
var self: @This() = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.current_sequence = try std.ArrayList(KeyEvent).initCapacity(allocator, 16),
|
.current_sequence = try std.ArrayList(KeyEvent).initCapacity(allocator, 16),
|
||||||
.current_sequence_egc = try std.ArrayList(u8).initCapacity(allocator, 16),
|
.current_sequence_egc = try std.ArrayList(u8).initCapacity(allocator, 16),
|
||||||
|
@ -468,6 +467,8 @@ const BindingSet = struct {
|
||||||
.input_buffer = try std.ArrayList(u8).initCapacity(allocator, 16),
|
.input_buffer = try std.ArrayList(u8).initCapacity(allocator, 16),
|
||||||
.bindings = std.ArrayList(Binding).init(allocator),
|
.bindings = std.ArrayList(Binding).init(allocator),
|
||||||
};
|
};
|
||||||
|
try self.load_json(json_string, namespace_name, mode_name);
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deinit(self: *const BindingSet) void {
|
fn deinit(self: *const BindingSet) void {
|
||||||
|
|
Loading…
Add table
Reference in a new issue