Skip to content

Commit

Permalink
feat: add draft implementation for leader key
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Sep 29, 2024
1 parent 5e6e919 commit 4aab2d0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
28 changes: 20 additions & 8 deletions frontends/rioterm/src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod kitty_keyboard;
use crate::crosswords::vi_mode::ViMotion;
use crate::crosswords::Mode;
use bitflags::bitflags;
use rio_backend::config::bindings::KeyBinding as ConfigKeyBinding;
use rio_backend::config::bindings::{Bindings, KeyBinding as ConfigKeyBinding};
use rio_backend::config::keyboard::Keyboard as ConfigKeyboard;
use rio_window::event::MouseButton;
use rio_window::keyboard::Key::*;
Expand Down Expand Up @@ -162,6 +162,7 @@ bitflags! {
const SEARCH = 0b0001_0000;
const DISAMBIGUATE_KEYS = 0b0010_0000;
const ALL_KEYS_AS_ESC = 0b0100_0000;
const LEADER = 0b1000_0000;
}
}

Expand All @@ -181,6 +182,7 @@ impl BindingMode {
mode.contains(Mode::REPORT_ALL_KEYS_AS_ESC),
);
binding_mode.set(BindingMode::VI, mode.contains(Mode::VI));
binding_mode.set(BindingMode::LEADER, mode.contains(Mode::LEADER));
binding_mode
}
}
Expand Down Expand Up @@ -553,7 +555,7 @@ pub fn default_mouse_bindings() -> Vec<MouseBinding> {
}

pub fn default_key_bindings(
unprocessed_config_key_bindings: Vec<ConfigKeyBinding>,
unprocessed_config_key_bindings: Bindings,
use_navigation_key_bindings: bool,
config_keyboard: ConfigKeyboard,
) -> Vec<KeyBinding> {
Expand Down Expand Up @@ -937,31 +939,41 @@ fn convert(config_key_binding: ConfigKeyBinding) -> Result<KeyBinding, String> {
"~alt" => res_mode.not_mode |= BindingMode::ALT_SCREEN,
"vi" => res_mode.mode |= BindingMode::VI,
"~vi" => res_mode.not_mode |= BindingMode::VI,
"leader" => res_mode.mode |= BindingMode::LEADER,
_ => {
res_mode.not_mode |= BindingMode::empty();
res_mode.mode |= BindingMode::empty();
}
}
}

Ok(KeyBinding {
let key_binding = KeyBinding {
trigger,
mods: res,
action,
mode: res_mode.mode,
notmode: res_mode.not_mode,
})
};

// panic!("Parsed key binding: {:?}", key_binding);

Ok(key_binding)
}

pub fn config_key_bindings(
config_key_bindings: Vec<ConfigKeyBinding>,
config_key_bindings: Bindings,
mut bindings: Vec<KeyBinding>,
) -> Vec<KeyBinding> {
if config_key_bindings.is_empty() {
if config_key_bindings.keys.is_empty() {
return bindings;
}

for ckb in config_key_bindings {
if let Some(leader) = config_key_bindings.leader {
let mut binding = convert(leader).unwrap();
binding.mode |= BindingMode::LEADER;
bindings.push(binding);
}

for ckb in config_key_bindings.keys {
match convert(ckb) {
Ok(key_binding) => match key_binding.action {
Action::None | Action::ReceiveChar => {
Expand Down
2 changes: 1 addition & 1 deletion frontends/rioterm/src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl Screen<'_> {
let renderer = Renderer::new(config, font_library);

let bindings = crate::bindings::default_key_bindings(
config.bindings.keys.to_owned(),
config.bindings.to_owned(),
config.navigation.has_navigation_key_bindings(),
config.keyboard,
);
Expand Down
1 change: 1 addition & 0 deletions rio-backend/src/config/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub type KeyBindings = Vec<KeyBinding>;
#[derive(Default, Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct Bindings {
pub keys: KeyBindings,
pub leader: Option<KeyBinding>,
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions rio-backend/src/crosswords/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ bitflags! {
const SIXEL_DISPLAY = 1 << 28;
const SIXEL_PRIV_PALETTE = 1 << 29;
const SIXEL_CURSOR_TO_THE_RIGHT = 1 << 31;
const LEADER = 1 << 30;
const ANY = u32::MAX;
}
}

Expand Down

0 comments on commit 4aab2d0

Please sign in to comment.