config: keybind = clear clears unmaps all keybinds

Fixes #1033

This introduces `keybind = clear` which will unmap all keybindings set
up to that point (including defaults).
This commit is contained in:
Mitchell Hashimoto
2023-12-10 13:57:14 -08:00
parent d51614d319
commit 715782b60f

View File

@ -462,6 +462,13 @@ class: ?[:0]const u8 = null,
/// send a string value that includes spaces, wrap the entire
/// trigger/action in double quotes. Example: --keybind="up=csi:A B"
///
/// There are some additional special values that can be specified for
/// keybind:
///
/// - `keybind = clear` will clear all set keybindings. Warning: this
/// removes ALL keybindings up to this point, including the default
/// keybindings.
///
keybind: Keybinds = .{},
/// Window padding. This applies padding between the terminal cells and
@ -2307,6 +2314,17 @@ pub const Keybinds = struct {
};
errdefer if (copy) |v| alloc.free(v);
// Check for special values
if (std.mem.eql(u8, value, "clear")) {
// We don't clear the memory because its in the arena and unlikely
// to be free-able anyways (since arenas can only clear the last
// allocated value). This isn't a memory leak because the arena
// will be freed when the config is freed.
log.info("config has 'keybind = clear', all keybinds cleared", .{});
self.set = .{};
return;
}
const binding = try inputpkg.Binding.parse(value);
switch (binding.action) {
.unbind => self.set.remove(binding.trigger),