diff options
Diffstat (limited to 'crates/turtle/src/command/client/search/keybindings')
6 files changed, 72 insertions, 72 deletions
diff --git a/crates/turtle/src/command/client/search/keybindings/actions.rs b/crates/turtle/src/command/client/search/keybindings/actions.rs index ff2ef7de..341b030c 100644 --- a/crates/turtle/src/command/client/search/keybindings/actions.rs +++ b/crates/turtle/src/command/client/search/keybindings/actions.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// All possible actions that can be triggered by a keybinding. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum Action { +pub(crate) enum Action { // Cursor movement CursorLeft, CursorRight, @@ -77,7 +77,7 @@ pub enum Action { impl Action { /// Convert from a kebab-case string. - pub fn from_str(s: &str) -> Result<Self, String> { + pub(crate) fn from_str(s: &str) -> Result<Self, String> { // Handle accept-N and return-selection-N patterns if let Some(rest) = s.strip_prefix("accept-") && let Ok(n) = rest.parse::<u8>() @@ -156,7 +156,7 @@ impl Action { } /// Convert to a kebab-case string. - pub fn as_str(&self) -> String { + pub(crate) fn as_str(&self) -> String { match self { Action::CursorLeft => "cursor-left".to_string(), Action::CursorRight => "cursor-right".to_string(), diff --git a/crates/turtle/src/command/client/search/keybindings/conditions.rs b/crates/turtle/src/command/client/search/keybindings/conditions.rs index 055ae905..f870d9a0 100644 --- a/crates/turtle/src/command/client/search/keybindings/conditions.rs +++ b/crates/turtle/src/command/client/search/keybindings/conditions.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// Atomic (leaf) conditions that can be evaluated against state. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum ConditionAtom { +pub(crate) enum ConditionAtom { CursorAtStart, CursorAtEnd, InputEmpty, @@ -28,7 +28,7 @@ pub enum ConditionAtom { /// - `"list-at-start || no-results"` (disjunction) /// - `"(cursor-at-start && !input-empty) || no-results"` (grouping) #[derive(Debug, Clone, PartialEq, Eq)] -pub enum ConditionExpr { +pub(crate) enum ConditionExpr { Atom(ConditionAtom), Not(Box<ConditionExpr>), And(Box<ConditionExpr>, Box<ConditionExpr>), @@ -37,21 +37,21 @@ pub enum ConditionExpr { /// Context needed to evaluate conditions. This is a pure snapshot of state — /// no references to mutable data. -pub struct EvalContext { +pub(crate) struct EvalContext { /// Current cursor position (unicode width units). - pub cursor_position: usize, + pub(crate) cursor_position: usize, /// Width of the input string in unicode width units. - pub input_width: usize, + pub(crate) input_width: usize, /// Byte length of the input string. - pub input_byte_len: usize, + pub(crate) input_byte_len: usize, /// Currently selected index in the results list. - pub selected_index: usize, + pub(crate) selected_index: usize, /// Total number of results. - pub results_len: usize, + pub(crate) results_len: usize, /// Whether the original input (query passed to the TUI) was empty. - pub original_input_empty: bool, + pub(crate) original_input_empty: bool, /// Whether we use a search context of a command from the history. - pub has_context: bool, + pub(crate) has_context: bool, } // --------------------------------------------------------------------------- @@ -60,7 +60,7 @@ pub struct EvalContext { impl ConditionAtom { /// Evaluate this atom against the given context. - pub fn evaluate(&self, ctx: &EvalContext) -> bool { + pub(crate) fn evaluate(&self, ctx: &EvalContext) -> bool { match self { ConditionAtom::CursorAtStart => ctx.cursor_position == 0, ConditionAtom::CursorAtEnd => ctx.cursor_position == ctx.input_width, @@ -77,7 +77,7 @@ impl ConditionAtom { } /// Parse from a kebab-case string. - pub fn from_str(s: &str) -> Result<Self, String> { + pub(crate) fn from_str(s: &str) -> Result<Self, String> { match s { "cursor-at-start" => Ok(ConditionAtom::CursorAtStart), "cursor-at-end" => Ok(ConditionAtom::CursorAtEnd), @@ -93,7 +93,7 @@ impl ConditionAtom { } /// Convert to a kebab-case string. - pub fn as_str(&self) -> &'static str { + pub(crate) fn as_str(&self) -> &'static str { match self { ConditionAtom::CursorAtStart => "cursor-at-start", ConditionAtom::CursorAtEnd => "cursor-at-end", @@ -120,7 +120,7 @@ impl fmt::Display for ConditionAtom { impl ConditionExpr { /// Evaluate this expression against the given context. - pub fn evaluate(&self, ctx: &EvalContext) -> bool { + pub(crate) fn evaluate(&self, ctx: &EvalContext) -> bool { match self { ConditionExpr::Atom(atom) => atom.evaluate(ctx), ConditionExpr::Not(inner) => !inner.evaluate(ctx), @@ -143,17 +143,17 @@ impl From<ConditionAtom> for ConditionExpr { #[expect(dead_code)] impl ConditionExpr { /// Negate this expression: `!self`. - pub fn not(self) -> Self { + pub(crate) fn not(self) -> Self { ConditionExpr::Not(Box::new(self)) } /// Conjoin with another expression: `self && other`. - pub fn and(self, other: ConditionExpr) -> Self { + pub(crate) fn and(self, other: ConditionExpr) -> Self { ConditionExpr::And(Box::new(self), Box::new(other)) } /// Disjoin with another expression: `self || other`. - pub fn or(self, other: ConditionExpr) -> Self { + pub(crate) fn or(self, other: ConditionExpr) -> Self { ConditionExpr::Or(Box::new(self), Box::new(other)) } } @@ -286,7 +286,7 @@ impl<'a> ExprParser<'a> { impl ConditionExpr { /// Parse a condition expression from a string. - pub fn parse(s: &str) -> Result<Self, String> { + pub(crate) fn parse(s: &str) -> Result<Self, String> { let parser = ExprParser::new(s); parser.parse() } diff --git a/crates/turtle/src/command/client/search/keybindings/defaults.rs b/crates/turtle/src/command/client/search/keybindings/defaults.rs index c8401e37..6627c84d 100644 --- a/crates/turtle/src/command/client/search/keybindings/defaults.rs +++ b/crates/turtle/src/command/client/search/keybindings/defaults.rs @@ -49,12 +49,12 @@ fn key(s: &str) -> KeyInput { /// All five keymaps bundled together. #[derive(Debug, Clone)] -pub struct KeymapSet { - pub emacs: Keymap, - pub vim_normal: Keymap, - pub vim_insert: Keymap, - pub inspector: Keymap, - pub prefix: Keymap, +pub(crate) struct KeymapSet { + pub(crate) emacs: Keymap, + pub(crate) vim_normal: Keymap, + pub(crate) vim_insert: Keymap, + pub(crate) inspector: Keymap, + pub(crate) prefix: Keymap, } // --------------------------------------------------------------------------- @@ -101,7 +101,7 @@ fn accept_action(settings: &Settings) -> Action { /// - `ctrl_n_shortcuts` — whether alt or ctrl is used for numeric shortcuts // Keymap builder that enumerates every default binding; not worth splitting. #[expect(clippy::too_many_lines)] -pub fn default_emacs_keymap(settings: &Settings) -> Keymap { +pub(crate) fn default_emacs_keymap(settings: &Settings) -> Keymap { let mut km = Keymap::new(); add_common_bindings(&mut km); @@ -252,7 +252,7 @@ pub fn default_emacs_keymap(settings: &Settings) -> Keymap { // --------------------------------------------------------------------------- /// Build the default vim-normal keymap. -pub fn default_vim_normal_keymap(settings: &Settings) -> Keymap { +pub(crate) fn default_vim_normal_keymap(settings: &Settings) -> Keymap { let mut km = Keymap::new(); add_common_bindings(&mut km); @@ -333,7 +333,7 @@ pub fn default_vim_normal_keymap(settings: &Settings) -> Keymap { /// Build the default vim-insert keymap. This clones the emacs keymap and /// overlays vim-insert-specific bindings (esc → enter normal mode). -pub fn default_vim_insert_keymap(settings: &Settings) -> Keymap { +pub(crate) fn default_vim_insert_keymap(settings: &Settings) -> Keymap { let mut km = default_emacs_keymap(settings); // Override esc and ctrl-[ to enter normal mode instead of exiting @@ -353,7 +353,7 @@ pub fn default_vim_insert_keymap(settings: &Settings) -> Keymap { /// text input, so we build a minimal keymap with only inspector-relevant /// bindings. We respect the user's `keymap_mode` to provide vim-style j/k /// navigation for vim users. -pub fn default_inspector_keymap(settings: &Settings) -> Keymap { +pub(crate) fn default_inspector_keymap(settings: &Settings) -> Keymap { use crate::atuin_client::settings::KeymapMode; let mut km = Keymap::new(); @@ -400,7 +400,7 @@ pub fn default_inspector_keymap(settings: &Settings) -> Keymap { // --------------------------------------------------------------------------- /// Build the default prefix keymap (active after ctrl-a prefix). -pub fn default_prefix_keymap() -> Keymap { +pub(crate) fn default_prefix_keymap() -> Keymap { let mut km = Keymap::new(); km.bind(key("d"), Action::Delete); @@ -476,7 +476,7 @@ fn apply_config_to_keymap(keymap: &mut Keymap, overrides: &HashMap<String, KeyBi impl KeymapSet { /// Build the complete set of default keymaps from settings. - pub fn defaults(settings: &Settings) -> Self { + pub(crate) fn defaults(settings: &Settings) -> Self { KeymapSet { emacs: default_emacs_keymap(settings), vim_normal: default_vim_normal_keymap(settings), @@ -494,7 +494,7 @@ impl KeymapSet { /// overrides are applied per-key. /// - If `[keymap]` is empty/absent, `[keys]` customizes the defaults /// (current behavior for backward compatibility). - pub fn from_settings(settings: &Settings) -> Self { + pub(crate) fn from_settings(settings: &Settings) -> Self { use crate::atuin_client::settings::Keys; if settings.keymap.is_empty() { diff --git a/crates/turtle/src/command/client/search/keybindings/key.rs b/crates/turtle/src/command/client/search/keybindings/key.rs index c2eb31c6..35107a24 100644 --- a/crates/turtle/src/command/client/search/keybindings/key.rs +++ b/crates/turtle/src/command/client/search/keybindings/key.rs @@ -6,17 +6,17 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// A single key press with modifiers (e.g. `ctrl-c`, `alt-f`, `enter`). #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[expect(clippy::struct_excessive_bools)] -pub struct SingleKey { - pub code: KeyCodeValue, - pub ctrl: bool, - pub alt: bool, - pub shift: bool, - pub super_key: bool, +pub(crate) struct SingleKey { + pub(crate) code: KeyCodeValue, + pub(crate) ctrl: bool, + pub(crate) alt: bool, + pub(crate) shift: bool, + pub(crate) super_key: bool, } /// The key code portion of a key press. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum KeyCodeValue { +pub(crate) enum KeyCodeValue { Char(char), Enter, Esc, @@ -39,14 +39,14 @@ pub enum KeyCodeValue { /// A key input that may be a single key or a multi-key sequence (e.g. `g g`). #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum KeyInput { +pub(crate) enum KeyInput { Single(SingleKey), Sequence(Vec<SingleKey>), } impl SingleKey { /// Convert a crossterm `KeyEvent` into a `SingleKey`. - pub fn from_event(event: &KeyEvent) -> Option<Self> { + pub(crate) fn from_event(event: &KeyEvent) -> Option<Self> { let ctrl = event.modifiers.contains(KeyModifiers::CONTROL); let alt = event.modifiers.contains(KeyModifiers::ALT); let shift = event.modifiers.contains(KeyModifiers::SHIFT); @@ -112,7 +112,7 @@ impl SingleKey { } /// Parse a key string like `"ctrl-c"`, `"alt-f"`, `"enter"`, `"G"`. - pub fn parse(s: &str) -> Result<Self, String> { + pub(crate) fn parse(s: &str) -> Result<Self, String> { let s = s.trim(); let parts: Vec<&str> = s.split('-').collect(); @@ -264,7 +264,7 @@ impl fmt::Display for SingleKey { impl KeyInput { /// Parse a key input string. Supports multi-key sequences separated by spaces /// (e.g. `"g g"`). - pub fn parse(s: &str) -> Result<Self, String> { + pub(crate) fn parse(s: &str) -> Result<Self, String> { let s = s.trim(); // Check for space-separated multi-key sequences // But don't split "space" or modifier combos like "ctrl-a" diff --git a/crates/turtle/src/command/client/search/keybindings/keymap.rs b/crates/turtle/src/command/client/search/keybindings/keymap.rs index 0d362863..c3b93b59 100644 --- a/crates/turtle/src/command/client/search/keybindings/keymap.rs +++ b/crates/turtle/src/command/client/search/keybindings/keymap.rs @@ -7,27 +7,27 @@ use super::key::{KeyInput, SingleKey}; /// A single rule within a keybinding: an optional condition and an action. /// If the condition is `None`, the rule always matches. #[derive(Debug, Clone)] -pub struct KeyRule { - pub condition: Option<ConditionExpr>, - pub action: Action, +pub(crate) struct KeyRule { + pub(crate) condition: Option<ConditionExpr>, + pub(crate) action: Action, } /// A keybinding is an ordered list of rules. The first rule whose condition /// matches (or has no condition) wins. #[derive(Debug, Clone)] -pub struct KeyBinding { - pub rules: Vec<KeyRule>, +pub(crate) struct KeyBinding { + pub(crate) rules: Vec<KeyRule>, } /// A keymap is a collection of keybindings indexed by key input. #[derive(Debug, Clone)] -pub struct Keymap { - pub bindings: HashMap<KeyInput, KeyBinding>, +pub(crate) struct Keymap { + pub(crate) bindings: HashMap<KeyInput, KeyBinding>, } impl KeyRule { /// Create an unconditional rule. - pub fn always(action: Action) -> Self { + pub(crate) fn always(action: Action) -> Self { KeyRule { condition: None, action, @@ -36,7 +36,7 @@ impl KeyRule { /// Create a conditional rule. Accepts any type convertible to `ConditionExpr`, /// including bare `ConditionAtom` values. - pub fn when(condition: impl Into<ConditionExpr>, action: Action) -> Self { + pub(crate) fn when(condition: impl Into<ConditionExpr>, action: Action) -> Self { KeyRule { condition: Some(condition.into()), action, @@ -46,39 +46,39 @@ impl KeyRule { impl KeyBinding { /// Create a simple (unconditional) binding. - pub fn simple(action: Action) -> Self { + pub(crate) fn simple(action: Action) -> Self { KeyBinding { rules: vec![KeyRule::always(action)], } } /// Create a conditional binding from a list of rules. - pub fn conditional(rules: Vec<KeyRule>) -> Self { + pub(crate) fn conditional(rules: Vec<KeyRule>) -> Self { KeyBinding { rules } } } impl Keymap { /// Create an empty keymap. - pub fn new() -> Self { + pub(crate) fn new() -> Self { Keymap { bindings: HashMap::new(), } } /// Bind a key input to a simple (unconditional) action. - pub fn bind(&mut self, key: KeyInput, action: Action) { + pub(crate) fn bind(&mut self, key: KeyInput, action: Action) { self.bindings.insert(key, KeyBinding::simple(action)); } /// Bind a key input to a conditional set of rules. - pub fn bind_conditional(&mut self, key: KeyInput, rules: Vec<KeyRule>) { + pub(crate) fn bind_conditional(&mut self, key: KeyInput, rules: Vec<KeyRule>) { self.bindings.insert(key, KeyBinding::conditional(rules)); } /// Resolve a key input to an action given the current evaluation context. /// Returns `None` if the key has no binding or no rule's condition matches. - pub fn resolve(&self, key: &KeyInput, ctx: &EvalContext) -> Option<Action> { + pub(crate) fn resolve(&self, key: &KeyInput, ctx: &EvalContext) -> Option<Action> { let binding = self.bindings.get(key)?; for rule in &binding.rules { match &rule.condition { @@ -92,7 +92,7 @@ impl Keymap { /// Check if any binding starts with the given single key as the first key /// of a multi-key sequence. Used to detect pending multi-key sequences. - pub fn has_sequence_starting_with(&self, prefix: &SingleKey) -> bool { + pub(crate) fn has_sequence_starting_with(&self, prefix: &SingleKey) -> bool { self.bindings.keys().any(|ki| match ki { KeyInput::Sequence(keys) => keys.first() == Some(prefix), KeyInput::Single(_) => false, @@ -101,7 +101,7 @@ impl Keymap { /// Merge another keymap into this one. Keys from `other` override keys in `self`. #[expect(dead_code)] - pub fn merge(&mut self, other: &Keymap) { + pub(crate) fn merge(&mut self, other: &Keymap) { for (key, binding) in &other.bindings { self.bindings.insert(key.clone(), binding.clone()); } diff --git a/crates/turtle/src/command/client/search/keybindings/mod.rs b/crates/turtle/src/command/client/search/keybindings/mod.rs index 3b6eb2b2..cdca0406 100644 --- a/crates/turtle/src/command/client/search/keybindings/mod.rs +++ b/crates/turtle/src/command/client/search/keybindings/mod.rs @@ -1,14 +1,14 @@ -pub mod actions; -pub mod conditions; -pub mod defaults; -pub mod key; -pub mod keymap; +pub(crate) mod actions; +pub(crate) mod conditions; +pub(crate) mod defaults; +pub(crate) mod key; +pub(crate) mod keymap; -pub use actions::Action; +pub(crate) use actions::Action; #[expect(unused_imports)] -pub use conditions::{ConditionAtom, ConditionExpr, EvalContext}; -pub use defaults::KeymapSet; +pub(crate) use conditions::{ConditionAtom, ConditionExpr, EvalContext}; +pub(crate) use defaults::KeymapSet; #[expect(unused_imports)] -pub use key::{KeyCodeValue, KeyInput, SingleKey}; +pub(crate) use key::{KeyCodeValue, KeyInput, SingleKey}; #[expect(unused_imports)] -pub use keymap::{KeyBinding, KeyRule, Keymap}; +pub(crate) use keymap::{KeyBinding, KeyRule, Keymap}; |
