aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/command/client/search/keybindings
diff options
context:
space:
mode:
Diffstat (limited to 'crates/turtle/src/command/client/search/keybindings')
-rw-r--r--crates/turtle/src/command/client/search/keybindings/defaults.rs32
-rw-r--r--crates/turtle/src/command/client/search/keybindings/key.rs24
2 files changed, 24 insertions, 32 deletions
diff --git a/crates/turtle/src/command/client/search/keybindings/defaults.rs b/crates/turtle/src/command/client/search/keybindings/defaults.rs
index 6627c84d..82219b33 100644
--- a/crates/turtle/src/command/client/search/keybindings/defaults.rs
+++ b/crates/turtle/src/command/client/search/keybindings/defaults.rs
@@ -527,7 +527,11 @@ impl KeymapSet {
#[cfg(test)]
mod tests {
- use super::*;
+ use super::{
+ Action, HashMap, KeymapSet, Settings, default_emacs_keymap, default_inspector_keymap,
+ default_prefix_keymap, default_vim_insert_keymap, default_vim_normal_keymap, key,
+ parse_binding_config,
+ };
use crate::command::client::search::keybindings::conditions::EvalContext;
fn make_ctx(cursor: usize, width: usize, selected: usize, len: usize) -> EvalContext {
@@ -543,7 +547,7 @@ mod tests {
}
fn default_settings() -> Settings {
- Settings::utc()
+ Settings::new().unwrap()
}
// -- Emacs keymap tests --
@@ -977,7 +981,7 @@ mod tests {
fn parse_simple_binding_config() {
use crate::atuin_client::settings::KeyBindingConfig;
let cfg = KeyBindingConfig::Simple("accept".to_string());
- let binding = super::parse_binding_config(&cfg).unwrap();
+ let binding = parse_binding_config(&cfg).unwrap();
assert_eq!(binding.rules.len(), 1);
assert!(binding.rules[0].condition.is_none());
assert_eq!(binding.rules[0].action, Action::Accept);
@@ -996,7 +1000,7 @@ mod tests {
action: "cursor-left".to_string(),
},
]);
- let binding = super::parse_binding_config(&cfg).unwrap();
+ let binding = parse_binding_config(&cfg).unwrap();
assert_eq!(binding.rules.len(), 2);
assert!(binding.rules[0].condition.is_some());
assert_eq!(binding.rules[0].action, Action::Exit);
@@ -1008,7 +1012,7 @@ mod tests {
fn parse_binding_config_invalid_action() {
use crate::atuin_client::settings::KeyBindingConfig;
let cfg = KeyBindingConfig::Simple("not-a-real-action".to_string());
- assert!(super::parse_binding_config(&cfg).is_err());
+ assert!(parse_binding_config(&cfg).is_err());
}
#[test]
@@ -1018,7 +1022,7 @@ mod tests {
when: Some("not-a-real-condition".to_string()),
action: "exit".to_string(),
}]);
- assert!(super::parse_binding_config(&cfg).is_err());
+ assert!(parse_binding_config(&cfg).is_err());
}
#[test]
@@ -1213,22 +1217,6 @@ mod tests {
}
#[test]
- fn keys_has_non_default_values_detection() {
- use crate::atuin_client::settings::Keys;
-
- let standard = Keys::standard_defaults();
- assert!(!standard.has_non_default_values());
-
- let mut modified = Keys::standard_defaults();
- modified.scroll_exits = false;
- assert!(modified.has_non_default_values());
-
- let mut modified = Keys::standard_defaults();
- modified.prefix = "x".to_string();
- assert!(modified.has_non_default_values());
- }
-
- #[test]
fn original_input_empty_condition_in_config() {
use crate::atuin_client::settings::{KeyBindingConfig, KeyRuleConfig};
use std::collections::HashMap;
diff --git a/crates/turtle/src/command/client/search/keybindings/key.rs b/crates/turtle/src/command/client/search/keybindings/key.rs
index 35107a24..841656d2 100644
--- a/crates/turtle/src/command/client/search/keybindings/key.rs
+++ b/crates/turtle/src/command/client/search/keybindings/key.rs
@@ -16,6 +16,10 @@ pub(crate) struct SingleKey {
/// The key code portion of a key press.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+#[expect(
+ variant_size_differences,
+ reason = "It's not that much. So should be ok?"
+)]
pub(crate) enum KeyCodeValue {
Char(char),
Enter,
@@ -59,7 +63,7 @@ impl SingleKey {
// we store the uppercase char directly and clear the shift flag
// since the case already encodes it.
if shift && !ctrl && !alt && !super_key && c.is_ascii_uppercase() {
- return Some(SingleKey {
+ return Some(Self {
code: KeyCodeValue::Char(c),
ctrl: false,
alt: false,
@@ -74,7 +78,7 @@ impl SingleKey {
KeyCode::Tab => KeyCodeValue::Tab,
// BackTab is sent by many terminals for Shift+Tab
KeyCode::BackTab => {
- return Some(SingleKey {
+ return Some(Self {
code: KeyCodeValue::Tab,
ctrl,
alt,
@@ -98,7 +102,7 @@ impl SingleKey {
_ => return None,
};
- Some(SingleKey {
+ Some(Self {
code,
ctrl,
alt,
@@ -185,7 +189,7 @@ impl SingleKey {
let c = chars[0];
// An uppercase letter implies shift (unless shift already specified)
if c.is_ascii_uppercase() && !ctrl && !alt && !super_key {
- return Ok(SingleKey {
+ return Ok(Self {
code: KeyCodeValue::Char(c),
ctrl: false,
alt: false,
@@ -200,7 +204,7 @@ impl SingleKey {
}
};
- Ok(SingleKey {
+ Ok(Self {
code,
ctrl,
alt,
@@ -272,9 +276,9 @@ impl KeyInput {
if parts.len() > 1 {
let keys: Result<Vec<SingleKey>, String> =
parts.iter().map(|p| SingleKey::parse(p)).collect();
- Ok(KeyInput::Sequence(keys?))
+ Ok(Self::Sequence(keys?))
} else {
- Ok(KeyInput::Single(SingleKey::parse(s)?))
+ Ok(Self::Single(SingleKey::parse(s)?))
}
}
}
@@ -282,8 +286,8 @@ impl KeyInput {
impl fmt::Display for KeyInput {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
- KeyInput::Single(k) => write!(f, "{k}"),
- KeyInput::Sequence(keys) => {
+ Self::Single(k) => write!(f, "{k}"),
+ Self::Sequence(keys) => {
for (i, k) in keys.iter().enumerate() {
if i > 0 {
write!(f, " ")?;
@@ -305,7 +309,7 @@ impl Serialize for KeyInput {
impl<'de> Deserialize<'de> for KeyInput {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let s = String::deserialize(deserializer)?;
- KeyInput::parse(&s).map_err(serde::de::Error::custom)
+ Self::parse(&s).map_err(serde::de::Error::custom)
}
}