From 199563550dd41c3dfb703bd3747604a8a03cdbc5 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 11 Jun 2026 14:20:49 +0200 Subject: chore: Remove all `pub`s They will not be marked by rustc/cargo as unused, and as atuin doesn't expose an API all of them _should_ be `pub(crate)` --- crates/turtle/src/command/client/search/cursor.rs | 44 +++++++++++----------- .../turtle/src/command/client/search/duration.rs | 4 +- crates/turtle/src/command/client/search/engines.rs | 20 +++++----- .../src/command/client/search/engines/daemon.rs | 4 +- .../turtle/src/command/client/search/engines/db.rs | 4 +- .../src/command/client/search/engines/skim.rs | 4 +- .../src/command/client/search/history_list.rs | 24 ++++++------ .../turtle/src/command/client/search/inspector.rs | 10 ++--- .../src/command/client/search/interactive.rs | 26 ++++++------- .../command/client/search/keybindings/actions.rs | 6 +-- .../client/search/keybindings/conditions.rs | 36 +++++++++--------- .../command/client/search/keybindings/defaults.rs | 26 ++++++------- .../src/command/client/search/keybindings/key.rs | 22 +++++------ .../command/client/search/keybindings/keymap.rs | 34 ++++++++--------- .../src/command/client/search/keybindings/mod.rs | 20 +++++----- 15 files changed, 142 insertions(+), 142 deletions(-) (limited to 'crates/turtle/src/command/client/search') diff --git a/crates/turtle/src/command/client/search/cursor.rs b/crates/turtle/src/command/client/search/cursor.rs index 84f94082..a69f1359 100644 --- a/crates/turtle/src/command/client/search/cursor.rs +++ b/crates/turtle/src/command/client/search/cursor.rs @@ -1,6 +1,6 @@ use crate::atuin_client::settings::WordJumpMode; -pub struct Cursor { +pub(crate) struct Cursor { source: String, index: usize, } @@ -11,7 +11,7 @@ impl From for Cursor { } } -pub struct WordJumper<'a> { +pub(crate) struct WordJumper<'a> { word_chars: &'a str, word_jump_mode: WordJumpMode, } @@ -93,25 +93,25 @@ impl WordJumper<'_> { } impl Cursor { - pub fn as_str(&self) -> &str { + pub(crate) fn as_str(&self) -> &str { self.source.as_str() } - pub fn into_inner(self) -> String { + pub(crate) fn into_inner(self) -> String { self.source } /// Returns the string before the cursor - pub fn substring(&self) -> &str { + pub(crate) fn substring(&self) -> &str { &self.source[..self.index] } /// Returns the currently selected [`char`] - pub fn char(&self) -> Option { + pub(crate) fn char(&self) -> Option { self.source[self.index..].chars().next() } - pub fn right(&mut self) { + pub(crate) fn right(&mut self) { if self.index < self.source.len() { loop { self.index += 1; @@ -122,7 +122,7 @@ impl Cursor { } } - pub fn left(&mut self) -> bool { + pub(crate) fn left(&mut self) -> bool { if self.index > 0 { loop { self.index -= 1; @@ -135,7 +135,7 @@ impl Cursor { } } - pub fn next_word(&mut self, word_chars: &str, word_jump_mode: WordJumpMode) { + pub(crate) fn next_word(&mut self, word_chars: &str, word_jump_mode: WordJumpMode) { let word_jumper = WordJumper { word_chars, word_jump_mode, @@ -143,7 +143,7 @@ impl Cursor { self.index = word_jumper.get_next_word_pos(&self.source, self.index); } - pub fn prev_word(&mut self, word_chars: &str, word_jump_mode: WordJumpMode) { + pub(crate) fn prev_word(&mut self, word_chars: &str, word_jump_mode: WordJumpMode) { let word_jumper = WordJumper { word_chars, word_jump_mode, @@ -156,7 +156,7 @@ impl Cursor { /// If cursor is in the middle of a word, moves to the end of that word. /// If cursor is at the end of a word (or on whitespace), moves to the /// end of the next word. - pub fn word_end(&mut self, word_chars: &str) { + pub(crate) fn word_end(&mut self, word_chars: &str) { let len = self.source.len(); if self.index >= len { return; @@ -213,12 +213,12 @@ impl Cursor { self.index = chars.iter().take(char_idx).map(|c| c.len_utf8()).sum(); } - pub fn insert(&mut self, c: char) { + pub(crate) fn insert(&mut self, c: char) { self.source.insert(self.index, c); self.index += c.len_utf8(); } - pub fn remove(&mut self) -> Option { + pub(crate) fn remove(&mut self) -> Option { if self.index < self.source.len() { Some(self.source.remove(self.index)) } else { @@ -226,7 +226,7 @@ impl Cursor { } } - pub fn remove_next_word(&mut self, word_chars: &str, word_jump_mode: WordJumpMode) { + pub(crate) fn remove_next_word(&mut self, word_chars: &str, word_jump_mode: WordJumpMode) { let word_jumper = WordJumper { word_chars, word_jump_mode, @@ -235,7 +235,7 @@ impl Cursor { self.source.replace_range(self.index..next_index, ""); } - pub fn remove_prev_word(&mut self, word_chars: &str, word_jump_mode: WordJumpMode) { + pub(crate) fn remove_prev_word(&mut self, word_chars: &str, word_jump_mode: WordJumpMode) { let word_jumper = WordJumper { word_chars, word_jump_mode, @@ -245,34 +245,34 @@ impl Cursor { self.index = next_index; } - pub fn back(&mut self) -> Option { + pub(crate) fn back(&mut self) -> Option { if self.left() { self.remove() } else { None } } - pub fn clear(&mut self) { + pub(crate) fn clear(&mut self) { self.source.clear(); self.index = 0; } - pub fn clear_to_start(&mut self) { + pub(crate) fn clear_to_start(&mut self) { self.source.replace_range(..self.index, ""); self.index = 0; } - pub fn clear_to_end(&mut self) { + pub(crate) fn clear_to_end(&mut self) { self.source.replace_range(self.index.., ""); self.index = self.source.len(); } - pub fn end(&mut self) { + pub(crate) fn end(&mut self) { self.index = self.source.len(); } - pub fn start(&mut self) { + pub(crate) fn start(&mut self) { self.index = 0; } - pub fn position(&self) -> usize { + pub(crate) fn position(&self) -> usize { self.index } } diff --git a/crates/turtle/src/command/client/search/duration.rs b/crates/turtle/src/command/client/search/duration.rs index 54856c87..bc8dbed3 100644 --- a/crates/turtle/src/command/client/search/duration.rs +++ b/crates/turtle/src/command/client/search/duration.rs @@ -2,7 +2,7 @@ use core::fmt; use std::{ops::ControlFlow, time::Duration}; #[expect(clippy::module_name_repetitions)] -pub fn format_duration_into(dur: Duration, f: &mut fmt::Formatter<'_>) -> fmt::Result { +pub(crate) fn format_duration_into(dur: Duration, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn item(unit: &'static str, value: u64) -> ControlFlow<(&'static str, u64)> { if value > 0 { ControlFlow::Break((unit, value)) @@ -54,7 +54,7 @@ pub fn format_duration_into(dur: Duration, f: &mut fmt::Formatter<'_>) -> fmt::R } #[expect(clippy::module_name_repetitions)] -pub fn format_duration(f: Duration) -> String { +pub(crate) fn format_duration(f: Duration) -> String { struct F(Duration); impl fmt::Display for F { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/crates/turtle/src/command/client/search/engines.rs b/crates/turtle/src/command/client/search/engines.rs index 0f92b4c7..d6335a38 100644 --- a/crates/turtle/src/command/client/search/engines.rs +++ b/crates/turtle/src/command/client/search/engines.rs @@ -9,12 +9,12 @@ use eyre::Result; use super::cursor::Cursor; #[cfg(feature = "daemon")] -pub mod daemon; -pub mod db; -pub mod skim; +pub(crate) mod daemon; +pub(crate) mod db; +pub(crate) mod skim; #[expect(unused)] // settings is only used if daemon feature is enabled -pub fn engine(search_mode: SearchMode, settings: &Settings) -> Box { +pub(crate) fn engine(search_mode: SearchMode, settings: &Settings) -> Box { match search_mode { SearchMode::Skim => Box::new(skim::Search::new()) as Box<_>, #[cfg(feature = "daemon")] @@ -28,11 +28,11 @@ pub fn engine(search_mode: SearchMode, settings: &Settings) -> Box, +pub(crate) struct SearchState { + pub(crate) input: Cursor, + pub(crate) filter_mode: FilterMode, + pub(crate) context: Context, + pub(crate) custom_context: Option, } impl SearchState { @@ -63,7 +63,7 @@ impl SearchState { } #[async_trait] -pub trait SearchEngine: Send + Sync + 'static { +pub(crate) trait SearchEngine: Send + Sync + 'static { async fn full_query( &mut self, state: &SearchState, diff --git a/crates/turtle/src/command/client/search/engines/daemon.rs b/crates/turtle/src/command/client/search/engines/daemon.rs index b1299c02..df5ab9f8 100644 --- a/crates/turtle/src/command/client/search/engines/daemon.rs +++ b/crates/turtle/src/command/client/search/engines/daemon.rs @@ -16,7 +16,7 @@ use uuid::Uuid; use super::{SearchEngine, SearchState}; use crate::command::client::daemon; -pub struct Search { +pub(crate) struct Search { client: Option, query_id: u64, settings: Settings, @@ -25,7 +25,7 @@ pub struct Search { } impl Search { - pub fn new(settings: &Settings) -> Self { + pub(crate) fn new(settings: &Settings) -> Self { Search { client: None, query_id: 0, diff --git a/crates/turtle/src/command/client/search/engines/db.rs b/crates/turtle/src/command/client/search/engines/db.rs index 2765faf5..86917a02 100644 --- a/crates/turtle/src/command/client/search/engines/db.rs +++ b/crates/turtle/src/command/client/search/engines/db.rs @@ -13,7 +13,7 @@ use norm::fzf::{FzfParser, FzfV2}; use std::ops::Range; use tracing::{Level, instrument}; -pub struct Search(pub SearchMode); +pub(crate) struct Search(pub(crate) SearchMode); #[async_trait] impl SearchEngine for Search { @@ -60,7 +60,7 @@ impl SearchEngine for Search { } #[instrument(skip_all, level = Level::TRACE, name = "db_highlight_fulltext")] -pub fn get_highlight_indices_fulltext(command: &str, search_input: &str) -> Vec { +pub(crate) fn get_highlight_indices_fulltext(command: &str, search_input: &str) -> Vec { let mut ranges = vec![]; let lower_command = command.to_ascii_lowercase(); diff --git a/crates/turtle/src/command/client/search/engines/skim.rs b/crates/turtle/src/command/client/search/engines/skim.rs index 96a6574d..fe2bdea3 100644 --- a/crates/turtle/src/command/client/search/engines/skim.rs +++ b/crates/turtle/src/command/client/search/engines/skim.rs @@ -16,13 +16,13 @@ use uuid; use super::{SearchEngine, SearchState}; -pub struct Search { +pub(crate) struct Search { all_history: Vec<(History, i32)>, engine: SkimMatcherV2, } impl Search { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Search { all_history: vec![], engine: SkimMatcherV2::default(), diff --git a/crates/turtle/src/command/client/search/history_list.rs b/crates/turtle/src/command/client/search/history_list.rs index 4c83d7eb..9d3a60e0 100644 --- a/crates/turtle/src/command/client/search/history_list.rs +++ b/crates/turtle/src/command/client/search/history_list.rs @@ -19,19 +19,19 @@ use ratatui::{ }; use time::OffsetDateTime; -pub struct HistoryHighlighter<'a> { - pub engine: &'a dyn SearchEngine, - pub search_input: &'a str, +pub(crate) struct HistoryHighlighter<'a> { + pub(crate) engine: &'a dyn SearchEngine, + pub(crate) search_input: &'a str, } impl HistoryHighlighter<'_> { - pub fn get_highlight_indices(&self, command: &str) -> Vec { + pub(crate) fn get_highlight_indices(&self, command: &str) -> Vec { self.engine .get_highlight_indices(command, self.search_input) } } -pub struct HistoryList<'a> { +pub(crate) struct HistoryList<'a> { history: &'a [History], block: Option>, inverted: bool, @@ -47,26 +47,26 @@ pub struct HistoryList<'a> { } #[derive(Default)] -pub struct ListState { +pub(crate) struct ListState { offset: usize, selected: usize, max_entries: usize, } impl ListState { - pub fn selected(&self) -> usize { + pub(crate) fn selected(&self) -> usize { self.selected } - pub fn max_entries(&self) -> usize { + pub(crate) fn max_entries(&self) -> usize { self.max_entries } - pub fn offset(&self) -> usize { + pub(crate) fn offset(&self) -> usize { self.offset } - pub fn select(&mut self, index: usize) { + pub(crate) fn select(&mut self, index: usize) { self.selected = index; } } @@ -118,7 +118,7 @@ impl StatefulWidget for HistoryList<'_> { impl<'a> HistoryList<'a> { #[expect(clippy::too_many_arguments)] - pub fn new( + pub(crate) fn new( history: &'a [History], inverted: bool, alternate_highlight: bool, @@ -143,7 +143,7 @@ impl<'a> HistoryList<'a> { } } - pub fn block(mut self, block: Block<'a>) -> Self { + pub(crate) fn block(mut self, block: Block<'a>) -> Self { self.block = Some(block); self } diff --git a/crates/turtle/src/command/client/search/inspector.rs b/crates/turtle/src/command/client/search/inspector.rs index 1ebc4383..a1bf803f 100644 --- a/crates/turtle/src/command/client/search/inspector.rs +++ b/crates/turtle/src/command/client/search/inspector.rs @@ -25,7 +25,7 @@ fn u64_or_zero(num: i64) -> u64 { if num < 0 { 0 } else { num as u64 } } -pub fn draw_commands( +pub(crate) fn draw_commands( f: &mut Frame<'_>, parent: Rect, history: &History, @@ -113,7 +113,7 @@ pub fn draw_commands( f.render_widget(next, commands[2]); } -pub fn draw_stats_table( +pub(crate) fn draw_stats_table( f: &mut Frame<'_>, parent: Rect, history: &History, @@ -285,7 +285,7 @@ fn draw_stats_charts(f: &mut Frame<'_>, parent: Rect, stats: &HistoryStats, them f.render_widget(duration_over_time, layout[2]); } -pub fn draw( +pub(crate) fn draw( f: &mut Frame<'_>, chunk: Rect, history: &History, @@ -302,7 +302,7 @@ pub fn draw( } } -pub fn draw_ultracompact( +pub(crate) fn draw_ultracompact( f: &mut Frame<'_>, chunk: Rect, history: &History, @@ -312,7 +312,7 @@ pub fn draw_ultracompact( draw_commands(f, chunk, history, stats, true, theme); } -pub fn draw_full( +pub(crate) fn draw_full( f: &mut Frame<'_>, chunk: Rect, history: &History, diff --git a/crates/turtle/src/command/client/search/interactive.rs b/crates/turtle/src/command/client/search/interactive.rs index a3d2cb79..380fc33b 100644 --- a/crates/turtle/src/command/client/search/interactive.rs +++ b/crates/turtle/src/command/client/search/interactive.rs @@ -52,7 +52,7 @@ use ratatui::crossterm::event::{ const TAB_TITLES: [&str; 2] = ["Search", "Inspect"]; -pub enum InputAction { +pub(crate) enum InputAction { Accept(usize), AcceptInspecting, Copy(usize), @@ -66,33 +66,33 @@ pub enum InputAction { } #[derive(Clone)] -pub struct InspectingState { +pub(crate) struct InspectingState { current: Option, next: Option, previous: Option, } impl InspectingState { - pub fn move_to_previous(&mut self) { + pub(crate) fn move_to_previous(&mut self) { let previous = self.previous.clone(); self.reset(); self.current = previous; } - pub fn move_to_next(&mut self) { + pub(crate) fn move_to_next(&mut self) { let next = self.next.clone(); self.reset(); self.current = next; } - pub fn reset(&mut self) { + pub(crate) fn reset(&mut self) { self.current = None; self.next = None; self.previous = None; } } -pub fn to_compactness(f: &Frame, settings: &Settings) -> Compactness { +pub(crate) fn to_compactness(f: &Frame, settings: &Settings) -> Compactness { if match settings.style { crate::atuin_client::settings::Style::Auto => f.area().height < 14, crate::atuin_client::settings::Style::Compact => true, @@ -110,7 +110,7 @@ pub fn to_compactness(f: &Frame, settings: &Settings) -> Compactness { #[expect(clippy::struct_field_names)] #[expect(clippy::struct_excessive_bools)] -pub struct State { +pub(crate) struct State { history_count: i64, results_state: ListState, switched_search_mode: bool, @@ -124,7 +124,7 @@ pub struct State { pending_vim_key: Option, original_input_empty: bool, - pub inspecting_state: InspectingState, + pub(crate) inspecting_state: InspectingState, keymaps: KeymapSet, search: SearchState, @@ -133,7 +133,7 @@ pub struct State { } #[derive(Clone, Copy)] -pub enum Compactness { +pub(crate) enum Compactness { Ultracompact, Compact, Full, @@ -231,7 +231,7 @@ impl State { } } - pub fn initialize_keymap_cursor(&mut self, settings: &Settings) { + pub(crate) fn initialize_keymap_cursor(&mut self, settings: &Settings) { match self.keymap_mode { KeymapMode::Emacs => self.set_keymap_cursor(settings, "emacs"), KeymapMode::VimNormal => self.set_keymap_cursor(settings, "vim_normal"), @@ -240,7 +240,7 @@ impl State { } } - pub fn finalize_keymap_cursor(&mut self, settings: &Settings) { + pub(crate) fn finalize_keymap_cursor(&mut self, settings: &Settings) { match settings.keymap_mode_shell { KeymapMode::Emacs => self.set_keymap_cursor(settings, "emacs"), KeymapMode::VimNormal => self.set_keymap_cursor(settings, "vim_normal"), @@ -1433,7 +1433,7 @@ struct Stdout { } impl Stdout { - pub fn new(inline_mode: bool, no_mouse: bool) -> std::io::Result { + pub(crate) fn new(inline_mode: bool, no_mouse: bool) -> std::io::Result { terminal::enable_raw_mode()?; let mut writer = TerminalWriter::new()?; @@ -1547,7 +1547,7 @@ fn compute_popup_placement( clippy::too_many_lines, clippy::cognitive_complexity )] -pub async fn history( +pub(crate) async fn history( query: &[String], settings: &Settings, mut db: impl Database, 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 { + pub(crate) fn from_str(s: &str) -> Result { // Handle accept-N and return-selection-N patterns if let Some(rest) = s.strip_prefix("accept-") && let Ok(n) = rest.parse::() @@ -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), And(Box, Box), @@ -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 { + pub(crate) fn from_str(s: &str) -> Result { 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 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 { + pub(crate) fn parse(s: &str) -> Result { 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 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), } impl SingleKey { /// Convert a crossterm `KeyEvent` into a `SingleKey`. - pub fn from_event(event: &KeyEvent) -> Option { + pub(crate) fn from_event(event: &KeyEvent) -> Option { 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 { + pub(crate) fn parse(s: &str) -> Result { 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 { + pub(crate) fn parse(s: &str) -> Result { 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, - pub action: Action, +pub(crate) struct KeyRule { + pub(crate) condition: Option, + 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, +pub(crate) struct KeyBinding { + pub(crate) rules: Vec, } /// A keymap is a collection of keybindings indexed by key input. #[derive(Debug, Clone)] -pub struct Keymap { - pub bindings: HashMap, +pub(crate) struct Keymap { + pub(crate) bindings: HashMap, } 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, action: Action) -> Self { + pub(crate) fn when(condition: impl Into, 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) -> Self { + pub(crate) fn conditional(rules: Vec) -> 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) { + pub(crate) fn bind_conditional(&mut self, key: KeyInput, rules: Vec) { 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 { + pub(crate) fn resolve(&self, key: &KeyInput, ctx: &EvalContext) -> Option { 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}; -- cgit v1.3.1