Skip to content

Commit cc82e49

Browse files
committed
feat: add draft implementation for leader key
1 parent b9d8879 commit cc82e49

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

frontends/rioterm/src/bindings/mod.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod kitty_keyboard;
77
use crate::crosswords::vi_mode::ViMotion;
88
use crate::crosswords::Mode;
99
use bitflags::bitflags;
10-
use rio_backend::config::bindings::KeyBinding as ConfigKeyBinding;
10+
use rio_backend::config::bindings::{Bindings, KeyBinding as ConfigKeyBinding};
1111
use rio_backend::config::keyboard::Keyboard as ConfigKeyboard;
1212
use rio_window::event::MouseButton;
1313
use rio_window::keyboard::Key::*;
@@ -162,6 +162,7 @@ bitflags! {
162162
const SEARCH = 0b0001_0000;
163163
const DISAMBIGUATE_KEYS = 0b0010_0000;
164164
const ALL_KEYS_AS_ESC = 0b0100_0000;
165+
const LEADER = 0b1000_0000;
165166
}
166167
}
167168

@@ -181,6 +182,7 @@ impl BindingMode {
181182
mode.contains(Mode::REPORT_ALL_KEYS_AS_ESC),
182183
);
183184
binding_mode.set(BindingMode::VI, mode.contains(Mode::VI));
185+
binding_mode.set(BindingMode::LEADER, mode.contains(Mode::LEADER));
184186
binding_mode
185187
}
186188
}
@@ -553,7 +555,7 @@ pub fn default_mouse_bindings() -> Vec<MouseBinding> {
553555
}
554556

555557
pub fn default_key_bindings(
556-
unprocessed_config_key_bindings: Vec<ConfigKeyBinding>,
558+
unprocessed_config_key_bindings: Bindings,
557559
use_navigation_key_bindings: bool,
558560
config_keyboard: ConfigKeyboard,
559561
) -> Vec<KeyBinding> {
@@ -942,31 +944,41 @@ fn convert(config_key_binding: ConfigKeyBinding) -> Result<KeyBinding, String> {
942944
"~alt" => res_mode.not_mode |= BindingMode::ALT_SCREEN,
943945
"vi" => res_mode.mode |= BindingMode::VI,
944946
"~vi" => res_mode.not_mode |= BindingMode::VI,
947+
"leader" => res_mode.mode |= BindingMode::LEADER,
945948
_ => {
946949
res_mode.not_mode |= BindingMode::empty();
947950
res_mode.mode |= BindingMode::empty();
948951
}
949952
}
950953
}
951-
952-
Ok(KeyBinding {
954+
let key_binding = KeyBinding {
953955
trigger,
954956
mods: res,
955957
action,
956958
mode: res_mode.mode,
957959
notmode: res_mode.not_mode,
958-
})
960+
};
961+
962+
// panic!("Parsed key binding: {:?}", key_binding);
963+
964+
Ok(key_binding)
959965
}
960966

961967
pub fn config_key_bindings(
962-
config_key_bindings: Vec<ConfigKeyBinding>,
968+
config_key_bindings: Bindings,
963969
mut bindings: Vec<KeyBinding>,
964970
) -> Vec<KeyBinding> {
965-
if config_key_bindings.is_empty() {
971+
if config_key_bindings.keys.is_empty() {
966972
return bindings;
967973
}
968974

969-
for ckb in config_key_bindings {
975+
if let Some(leader) = config_key_bindings.leader {
976+
let mut binding = convert(leader).unwrap();
977+
binding.mode |= BindingMode::LEADER;
978+
bindings.push(binding);
979+
}
980+
981+
for ckb in config_key_bindings.keys {
970982
match convert(ckb) {
971983
Ok(key_binding) => match key_binding.action {
972984
Action::None | Action::ReceiveChar => {

frontends/rioterm/src/screen/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl Screen<'_> {
178178
let renderer = Renderer::new(config, font_library);
179179

180180
let bindings = crate::bindings::default_key_bindings(
181-
config.bindings.keys.to_owned(),
181+
config.bindings.to_owned(),
182182
config.navigation.has_navigation_key_bindings(),
183183
config.keyboard,
184184
);

rio-backend/src/config/bindings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub type KeyBindings = Vec<KeyBinding>;
2525
#[derive(Default, Debug, PartialEq, Clone, Serialize, Deserialize)]
2626
pub struct Bindings {
2727
pub keys: KeyBindings,
28+
pub leader: Option<KeyBinding>,
2829
}
2930

3031
#[cfg(test)]

rio-backend/src/crosswords/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ bitflags! {
110110
const SIXEL_DISPLAY = 1 << 28;
111111
const SIXEL_PRIV_PALETTE = 1 << 29;
112112
const SIXEL_CURSOR_TO_THE_RIGHT = 1 << 31;
113+
const LEADER = 1 << 30;
114+
const ANY = u32::MAX;
113115
}
114116
}
115117

0 commit comments

Comments
 (0)