mirror of https://git.sr.ht/~kikoodx/kble
Allow user to configure keybindings.
This commit is contained in:
parent
75351eb8b5
commit
25335e94a6
|
@ -40,6 +40,14 @@ $ kble sample.kble
|
|||
$ kble $HOME/projects/kble/sample.kble
|
||||
```
|
||||
|
||||
# Configuration.
|
||||
In `src/conf.zig`, edit values from `BEGIN USER CONFIG`.
|
||||
The configuration is applied at compile time. You have the possibility to:
|
||||
* Disable mouse support.
|
||||
* Swap mouse buttons.
|
||||
* Change and add colors.
|
||||
* Edit keybindings.
|
||||
|
||||
# Default keybindings
|
||||
Repetition/parameter:
|
||||
* `0` → `9`: behavior similar to Vi.
|
||||
|
|
21
src/conf.zig
21
src/conf.zig
|
@ -41,4 +41,25 @@ pub fn cell_color(cell: cell_type) ray.Color {
|
|||
else => ray.PURPLE, // undefined
|
||||
};
|
||||
}
|
||||
|
||||
/// Used to set keybindings.
|
||||
/// Only bind to default keybindings, use 0 to unbind a key.
|
||||
pub fn bind_key(key: u8) u8 {
|
||||
return switch (key) {
|
||||
// // jkl; movement.
|
||||
// 'j' => 'h',
|
||||
// 'k' => 'j',
|
||||
// 'l' => 'k',
|
||||
// ';' => 'l',
|
||||
// // Backward movement with HJKL.
|
||||
// 'H' => 'l',
|
||||
// 'J' => 'k',
|
||||
// 'K' => 'j',
|
||||
// 'L' => 'h',
|
||||
// // Use x instead of return for normal mode.
|
||||
// '\n' => 0,
|
||||
// 'x' => '\n',
|
||||
else => key
|
||||
};
|
||||
}
|
||||
// END USER CONFIG
|
||||
|
|
71
src/main.zig
71
src/main.zig
|
@ -76,39 +76,48 @@ pub fn main() void {
|
|||
|
||||
// Create binding "table".
|
||||
var bindings = [_]*const actions.Action{&actions.ActionsDef.none} ** char_range;
|
||||
// Set default bindings.
|
||||
// Parameters/repetition.
|
||||
{
|
||||
var i: u8 = 0;
|
||||
while (i < 10) : (i += 1) {
|
||||
bindings['0' + i] = &ActionsDef.parameter;
|
||||
comptime {
|
||||
// Set default bindings.
|
||||
var default_bindings = [_]*const actions.Action{&actions.ActionsDef.none} ** char_range;
|
||||
comptime {
|
||||
var i: u8 = 0;
|
||||
while (i < 10) : (i += 1) {
|
||||
default_bindings['0' + i] = &ActionsDef.parameter;
|
||||
}
|
||||
}
|
||||
// Movement.
|
||||
default_bindings['h'] = &ActionsDef.move_left;
|
||||
default_bindings['j'] = &ActionsDef.move_down;
|
||||
default_bindings['k'] = &ActionsDef.move_up;
|
||||
default_bindings['l'] = &ActionsDef.move_right;
|
||||
default_bindings['y'] = &ActionsDef.move_up_left;
|
||||
default_bindings['u'] = &ActionsDef.move_up_right;
|
||||
default_bindings['b'] = &ActionsDef.move_down_left;
|
||||
default_bindings['n'] = &ActionsDef.move_down_right;
|
||||
// Verbs.
|
||||
default_bindings[' '] = &ActionsDef.verb_clear_selection;
|
||||
default_bindings['d'] = &ActionsDef.verb_delete;
|
||||
default_bindings['r'] = &ActionsDef.verb_replace;
|
||||
// Scale.
|
||||
default_bindings['='] = &ActionsDef.scale_reset;
|
||||
default_bindings['+'] = &ActionsDef.scale_up;
|
||||
default_bindings['-'] = &ActionsDef.scale_down;
|
||||
// File.
|
||||
default_bindings['e'] = &ActionsDef.file_read;
|
||||
default_bindings['w'] = &ActionsDef.file_write;
|
||||
// Mode.
|
||||
default_bindings['\n'] = &ActionsDef.mode_normal;
|
||||
default_bindings['i'] = &ActionsDef.mode_select;
|
||||
default_bindings['v'] = &ActionsDef.mode_rectangle;
|
||||
default_bindings['c'] = &ActionsDef.mode_camera;
|
||||
// Map user bindings.
|
||||
comptime {
|
||||
var i: u8 = 0;
|
||||
while (i < char_range) : (i += 1) {
|
||||
bindings[i] = default_bindings[conf.bind_key(i)];
|
||||
}
|
||||
}
|
||||
}
|
||||
// Movement.
|
||||
bindings['h'] = &ActionsDef.move_left;
|
||||
bindings['j'] = &ActionsDef.move_down;
|
||||
bindings['k'] = &ActionsDef.move_up;
|
||||
bindings['l'] = &ActionsDef.move_right;
|
||||
bindings['y'] = &ActionsDef.move_up_left;
|
||||
bindings['u'] = &ActionsDef.move_up_right;
|
||||
bindings['b'] = &ActionsDef.move_down_left;
|
||||
bindings['n'] = &ActionsDef.move_down_right;
|
||||
// Verbs.
|
||||
bindings[' '] = &ActionsDef.verb_clear_selection;
|
||||
bindings['d'] = &ActionsDef.verb_delete;
|
||||
bindings['r'] = &ActionsDef.verb_replace;
|
||||
// Scale.
|
||||
bindings['='] = &ActionsDef.scale_reset;
|
||||
bindings['+'] = &ActionsDef.scale_up;
|
||||
bindings['-'] = &ActionsDef.scale_down;
|
||||
// File.
|
||||
bindings['e'] = &ActionsDef.file_read;
|
||||
bindings['w'] = &ActionsDef.file_write;
|
||||
// Mode.
|
||||
bindings['\n'] = &ActionsDef.mode_normal;
|
||||
bindings['i'] = &ActionsDef.mode_select;
|
||||
bindings['v'] = &ActionsDef.mode_rectangle;
|
||||
bindings['c'] = &ActionsDef.mode_camera;
|
||||
|
||||
// Create input buffer.
|
||||
const input_buffer_len = 255;
|
||||
|
|
Loading…
Reference in New Issue