diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-12 17:16:19 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-12 17:16:19 +0200 |
| commit | 2ca7dd57b12861e8c9bbc9238cda612e0ff22ff3 (patch) | |
| tree | 302a644f6a50d60cc8304c4498fe6bbb72ddaaa9 /crates/turtle/src/command/client/search/interactive.rs | |
| parent | feat(server): Really make users stateless (with tests) (diff) | |
| download | atuin-2ca7dd57b12861e8c9bbc9238cda612e0ff22ff3.zip | |
chore(treewide): Cleanup themes
Diffstat (limited to 'crates/turtle/src/command/client/search/interactive.rs')
| -rw-r--r-- | crates/turtle/src/command/client/search/interactive.rs | 140 |
1 files changed, 59 insertions, 81 deletions
diff --git a/crates/turtle/src/command/client/search/interactive.rs b/crates/turtle/src/command/client/search/interactive.rs index 1d067e50..2c6af8cf 100644 --- a/crates/turtle/src/command/client/search/interactive.rs +++ b/crates/turtle/src/command/client/search/interactive.rs @@ -7,7 +7,10 @@ use std::{ use std::io::Read as _; use crate::{ - atuin_client::database::ClientSqlite, + atuin_client::{ + database::ClientSqlite, + theme::{style_annotation, style_base, style_important}, + }, atuin_common::{shell::Shell, utils::Escapable as _}, }; use eyre::Result; @@ -30,7 +33,6 @@ use crate::atuin_client::{ use crate::command::client::search::history_list::HistoryHighlighter; use crate::command::client::search::keybindings::KeymapSet; -use crate::command::client::theme::{Meaning, Theme}; use crate::{VERSION, command::client::search::engines}; use ratatui::{ @@ -42,7 +44,7 @@ use ratatui::{ execute, queue, terminal, }, layout::{Alignment, Constraint, Direction, Layout}, - prelude::*, + prelude::Rect, style::{Modifier, Style}, text::{Line, Span, Text}, widgets::{Block, BorderType, Borders, Clear, Padding, Paragraph, Tabs}, @@ -800,9 +802,6 @@ impl State { } } - #[expect(clippy::bool_to_int_with_if)] - #[expect(clippy::too_many_lines)] - #[expect(clippy::too_many_arguments)] fn draw( &mut self, f: &mut Frame, @@ -810,17 +809,16 @@ impl State { stats: Option<HistoryStats>, inspecting: Option<&History>, settings: &Settings, - theme: &Theme, + popup_mode: bool, ) { let area = f.area(); if popup_mode { f.render_widget(Clear, area); } - self.draw_inner(f, area, results, stats, inspecting, settings, theme); + self.draw_inner(f, area, results, stats, inspecting, settings); } - #[expect(clippy::too_many_arguments)] #[expect(clippy::too_many_lines)] #[expect(clippy::bool_to_int_with_if)] fn draw_inner( @@ -831,7 +829,6 @@ impl State { stats: Option<HistoryStats>, inspecting: Option<&History>, settings: &Settings, - theme: &Theme, ) { let compactness = to_compactness(f, settings); let invert = settings.invert; @@ -905,7 +902,7 @@ impl State { .block(Block::default().borders(Borders::NONE)) .select(self.tab_index) .style(Style::default()) - .highlight_style(Style::from_crossterm(theme.as_style(Meaning::Important))); + .highlight_style(Style::from_crossterm(style_important())); f.render_widget(tabs, tabs_chunk); } @@ -928,13 +925,13 @@ impl State { ) .split(header_chunk); - let title = Self::build_title(theme); + let title = Self::build_title(); f.render_widget(title, header_chunks[0]); - let help = self.build_help(settings, theme); + let help = self.build_help(settings); f.render_widget(help, header_chunks[1]); - let stats_tab = self.build_stats(theme); + let stats_tab = self.build_stats(); f.render_widget(stats_tab, header_chunks[2]); let indicator: String = match compactness { @@ -968,7 +965,6 @@ impl State { self.keymap_mode, &self.now, indicator.as_str(), - theme, history_highlighter, settings.show_numeric_shortcuts, &settings.ui.columns, @@ -999,7 +995,6 @@ impl State { inspecting, &stats.expect("Drawing inspector, but no stats"), settings, - theme, settings.timezone, ); } @@ -1029,7 +1024,6 @@ impl State { compactness, preview_width, preview_chunk.width.into(), - theme, ); #[expect(clippy::cast_possible_truncation)] let prefix_width = settings @@ -1083,9 +1077,9 @@ impl State { )); } - fn build_title(theme: &Theme) -> Paragraph<'_> { + fn build_title<'a>() -> Paragraph<'a> { let title = { - let style: Style = Style::from_crossterm(theme.as_style(Meaning::Base)); + let style: Style = Style::from_crossterm(style_base()); Paragraph::new(Text::from(Span::styled( format!("Atuin v{VERSION}"), style.add_modifier(Modifier::BOLD), @@ -1095,7 +1089,7 @@ impl State { } #[expect(clippy::unused_self)] - fn build_help(&self, settings: &Settings, theme: &Theme) -> Paragraph<'_> { + fn build_help(&self, settings: &Settings) -> Paragraph<'_> { match self.tab_index { // search 0 => Paragraph::new(Text::from(Line::from(vec![ @@ -1129,16 +1123,16 @@ impl State { _ => unreachable!("invalid tab index"), } - .style(Style::from_crossterm(theme.as_style(Meaning::Annotation))) + .style(Style::from_crossterm(style_annotation())) .alignment(Alignment::Center) } - fn build_stats(&self, theme: &Theme) -> Paragraph<'_> { + fn build_stats(&self) -> Paragraph<'_> { Paragraph::new(Text::from(Span::raw(format!( "history count: {}", self.history_count, )))) - .style(Style::from_crossterm(theme.as_style(Meaning::Annotation))) + .style(Style::from_crossterm(style_annotation())) .alignment(Alignment::Right) } @@ -1149,7 +1143,7 @@ impl State { keymap_mode: KeymapMode, now: &'a dyn Fn() -> OffsetDateTime, indicator: &'a str, - theme: &'a Theme, + history_highlighter: HistoryHighlighter<'a>, show_numeric_shortcuts: bool, columns: &'a [UiColumn], @@ -1160,7 +1154,6 @@ impl State { keymap_mode == KeymapMode::VimNormal, now, indicator, - theme, history_highlighter, show_numeric_shortcuts, columns, @@ -1228,7 +1221,6 @@ impl State { compactness: Compactness, preview_width: u16, chunk_width: usize, - theme: &Theme, ) -> Paragraph<'_> { let selected = self.results_state.selected(); let command = if results.is_empty() { @@ -1264,8 +1256,7 @@ impl State { .border_type(BorderType::Rounded) .title(format!("{:─>width$}", "", width = chunk_width - 2)), ), - _ => Paragraph::new(command) - .style(Style::from_crossterm(theme.as_style(Meaning::Annotation))), + _ => Paragraph::new(command).style(Style::from_crossterm(style_annotation())), } } } @@ -1320,9 +1311,7 @@ impl Write for TerminalWriter { /// Screen state captured from atuin pty-proxy's screen server. #[cfg(unix)] struct SavedScreen { - #[expect(dead_code)] rows: u16, - #[expect(dead_code)] cols: u16, cursor_row: u16, cursor_col: u16, @@ -1555,7 +1544,6 @@ pub(crate) async fn history( settings: &Settings, mut db: ClientSqlite, history_store: &HistoryStore, - theme: &Theme, ) -> Result<String> { let inline_height = if settings.shell_up_key_binding { settings @@ -1752,7 +1740,6 @@ pub(crate) async fn history( stats.clone(), inspecting.as_ref(), settings, - theme, popup_mode, ); })?; @@ -1832,7 +1819,7 @@ pub(crate) async fn history( terminal.clear()?; } terminal.draw(|f| { - app.draw(f, &results, stats.clone(), inspecting.as_ref(), settings, theme, popup_mode); + app.draw(f, &results, stats.clone(), inspecting.as_ref(), settings, popup_mode); })?; }, r => { @@ -1979,10 +1966,7 @@ pub(crate) async fn history( // cli-clipboard only works on Windows, Mac, and Linux. -#[cfg(all( - feature = "clipboard", - any(target_os = "windows", target_os = "macos", target_os = "linux") -))] +#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))] fn set_clipboard(s: String) { let mut ctx = arboard::Clipboard::new().unwrap(); ctx.set_text(s).unwrap(); @@ -1990,12 +1974,6 @@ fn set_clipboard(s: String) { ctx.get_text().unwrap(); } -#[cfg(not(all( - feature = "clipboard", - any(target_os = "windows", target_os = "macos", target_os = "linux") -)))] -fn set_clipboard(_s: String) {} - #[cfg(test)] mod tests { use crate::atuin_client::database::Context; @@ -2018,7 +1996,7 @@ mod tests { strategy: PreviewStrategy::Auto, }, show_preview: true, - ..Settings::utc() + ..Settings::now() }; let settings_preview_auto_h2 = Settings { @@ -2027,7 +2005,7 @@ mod tests { }, show_preview: true, max_preview_height: 2, - ..Settings::utc() + ..Settings::now() }; let settings_preview_h4 = Settings { @@ -2036,7 +2014,7 @@ mod tests { }, show_preview: true, max_preview_height: 4, - ..Settings::utc() + ..Settings::now() }; let settings_preview_fixed = Settings { @@ -2045,7 +2023,7 @@ mod tests { }, show_preview: true, max_preview_height: 15, - ..Settings::utc() + ..Settings::now() }; let cmd_60: History = History::capture() @@ -2167,7 +2145,7 @@ mod tests { // Test when there's no results, scrolling up or down doesn't underflow #[test] fn state_scroll_up_underflow() { - let settings = Settings::utc(); + let settings = Settings::now(); let mut state = State { history_count: 0, results_state: ListState::default(), @@ -2212,7 +2190,7 @@ mod tests { use crate::atuin_client::settings::Keys; use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; - let mut settings = Settings::utc(); + let mut settings = Settings::now(); settings.keys = Keys { scroll_exits: true, exit_past_line_start: false, @@ -2338,7 +2316,7 @@ mod tests { fn test_vim_gg_multikey_sequence() { use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; - let settings = Settings::utc(); + let settings = Settings::now(); let mut state = State { history_count: 100, @@ -2396,7 +2374,7 @@ mod tests { fn test_vim_g_key_clears_on_other_input() { use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; - let settings = Settings::utc(); + let settings = Settings::now(); let mut state = State { history_count: 100, @@ -2450,7 +2428,7 @@ mod tests { fn test_vim_big_g_jump_to_bottom() { use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; - let settings = Settings::utc(); + let settings = Settings::now(); let mut state = State { history_count: 100, @@ -2500,7 +2478,7 @@ mod tests { fn test_vim_ctrl_u_d_half_page_scroll() { use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; - let settings = Settings::utc(); + let settings = Settings::now(); let mut state = State { history_count: 100, @@ -2559,7 +2537,7 @@ mod tests { fn test_vim_ctrl_f_b_full_page_scroll() { use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; - let settings = Settings::utc(); + let settings = Settings::now(); let mut state = State { history_count: 100, @@ -2620,7 +2598,7 @@ mod tests { /// Helper to build a State for executor tests. fn make_executor_state(results_len: usize, selected: usize) -> State { - let settings = Settings::utc(); + let settings = Settings::now(); let mut state = State { history_count: results_len as i64, results_state: ListState::default(), @@ -2664,7 +2642,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 50); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::SelectNext, &settings); assert!(matches!(result, super::InputAction::Continue)); // Non-inverted: SelectNext = scroll_down = selected - 1 @@ -2676,7 +2654,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 50); - let mut settings = Settings::utc(); + let mut settings = Settings::now(); settings.invert = true; let result = state.execute_action(&Action::SelectNext, &settings); assert!(matches!(result, super::InputAction::Continue)); @@ -2689,7 +2667,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 50); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::SelectPrevious, &settings); assert!(matches!(result, super::InputAction::Continue)); // Non-inverted: SelectPrevious = scroll_up = selected + 1 @@ -2701,7 +2679,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 0); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::VimEnterNormal, &settings); assert!(matches!(result, super::InputAction::Continue)); assert_eq!(state.keymap_mode, KeymapMode::VimNormal); @@ -2713,7 +2691,7 @@ mod tests { let mut state = make_executor_state(100, 0); state.keymap_mode = KeymapMode::VimNormal; - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::VimEnterInsert, &settings); assert!(matches!(result, super::InputAction::Continue)); assert_eq!(state.keymap_mode, KeymapMode::VimInsert); @@ -2724,7 +2702,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 5); - let mut settings = Settings::utc(); + let mut settings = Settings::now(); settings.enter_accept = true; let result = state.execute_action(&Action::Accept, &settings); assert!(matches!(result, super::InputAction::Accept(5))); @@ -2736,7 +2714,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 5); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::ReturnSelection, &settings); assert!(matches!(result, super::InputAction::Accept(5))); assert!(!state.accept); @@ -2747,7 +2725,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 5); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::AcceptNth(3), &settings); assert!(matches!(result, super::InputAction::Accept(8))); } @@ -2757,7 +2735,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 50); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::ScrollToTop, &settings); assert!(matches!(result, super::InputAction::Continue)); // Non-inverted: visual top = highest index @@ -2769,7 +2747,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 50); - let mut settings = Settings::utc(); + let mut settings = Settings::now(); settings.invert = true; let result = state.execute_action(&Action::ScrollToTop, &settings); assert!(matches!(result, super::InputAction::Continue)); @@ -2782,7 +2760,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 50); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::ScrollToBottom, &settings); assert!(matches!(result, super::InputAction::Continue)); // Non-inverted: visual bottom = index 0 @@ -2794,7 +2772,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 0); - let settings = Settings::utc(); + let settings = Settings::now(); assert_eq!(state.tab_index, 0); state.execute_action(&Action::ToggleTab, &settings); assert_eq!(state.tab_index, 1); @@ -2807,7 +2785,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 0); - let settings = Settings::utc(); + let settings = Settings::now(); assert!(!state.prefix); state.execute_action(&Action::EnterPrefixMode, &settings); assert!(state.prefix); @@ -2819,7 +2797,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 0); - let mut settings = Settings::utc(); + let mut settings = Settings::now(); settings.exit_mode = ExitMode::ReturnOriginal; let result = state.execute_action(&Action::Exit, &settings); @@ -2835,7 +2813,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 0); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::ReturnOriginal, &settings); assert!(matches!(result, super::InputAction::ReturnOriginal)); } @@ -2845,7 +2823,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 7); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::Copy, &settings); assert!(matches!(result, super::InputAction::Copy(7))); } @@ -2855,7 +2833,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 7); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::Delete, &settings); assert!(matches!(result, super::InputAction::Delete(7))); } @@ -2865,7 +2843,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 7); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::SwitchContext, &settings); assert!(matches!(result, super::InputAction::SwitchContext(Some(7)))); } @@ -2875,7 +2853,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 7); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::ClearContext, &settings); assert!(matches!(result, super::InputAction::SwitchContext(None))); } @@ -2885,7 +2863,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 50); - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::Noop, &settings); assert!(matches!(result, super::InputAction::Continue)); assert_eq!(state.results_state.selected(), 50); @@ -2897,7 +2875,7 @@ mod tests { let mut state = make_executor_state(100, 5); state.tab_index = 1; - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::Accept, &settings); assert!(matches!(result, super::InputAction::AcceptInspecting)); } @@ -2907,7 +2885,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 0); - let settings = Settings::utc(); + let settings = Settings::now(); let original_mode = state.search_mode; let result = state.execute_action(&Action::CycleSearchMode, &settings); assert!(matches!(result, super::InputAction::Continue)); @@ -2923,7 +2901,7 @@ mod tests { state.search.input.insert('h'); state.search.input.insert('i'); state.keymap_mode = KeymapMode::VimNormal; - let settings = Settings::utc(); + let settings = Settings::now(); let result = state.execute_action(&Action::VimSearchInsert, &settings); assert!(matches!(result, super::InputAction::Continue)); // Should clear input and switch to insert mode @@ -2936,7 +2914,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 0); - let settings = Settings::utc(); + let settings = Settings::now(); // Insert some text state.search.input.insert('h'); @@ -2968,7 +2946,7 @@ mod tests { use crate::command::client::search::keybindings::Action; let mut state = make_executor_state(100, 0); - let settings = Settings::utc(); + let settings = Settings::now(); // Insert "hello" state.search.input.insert('h'); @@ -2992,7 +2970,7 @@ mod tests { use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use std::collections::HashMap; - let mut settings = Settings::utc(); + let mut settings = Settings::now(); // Configure tab to return-query settings.keymap.emacs = HashMap::from([( "tab".to_string(), |
