aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/command/client/search/interactive.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/turtle/src/command/client/search/interactive.rs')
-rw-r--r--crates/turtle/src/command/client/search/interactive.rs158
1 files changed, 80 insertions, 78 deletions
diff --git a/crates/turtle/src/command/client/search/interactive.rs b/crates/turtle/src/command/client/search/interactive.rs
index 2c6af8cf..49d483b0 100644
--- a/crates/turtle/src/command/client/search/interactive.rs
+++ b/crates/turtle/src/command/client/search/interactive.rs
@@ -97,7 +97,7 @@ impl InspectingState {
}
}
-pub(crate) 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,
@@ -232,7 +232,7 @@ impl State {
&& let Some(style) = cursor_style
{
self.current_cursor = cursor_style;
- let _ = execute!(stdout(), Self::cast_cursor_style(style));
+ drop(execute!(stdout(), Self::cast_cursor_style(style)));
}
}
@@ -804,7 +804,7 @@ impl State {
fn draw(
&mut self,
- f: &mut Frame,
+ f: &mut Frame<'_>,
results: &[History],
stats: Option<HistoryStats>,
inspecting: Option<&History>,
@@ -823,7 +823,7 @@ impl State {
#[expect(clippy::bool_to_int_with_if)]
fn draw_inner(
&mut self,
- f: &mut Frame,
+ f: &mut Frame<'_>,
area: Rect,
results: &[History],
stats: Option<HistoryStats>,
@@ -1051,12 +1051,12 @@ impl State {
#[expect(clippy::cast_possible_truncation, clippy::too_many_arguments)]
fn draw_preview(
&self,
- f: &mut Frame,
+ f: &mut Frame<'_>,
style: StyleState,
input_chunk: Rect,
compactness: Compactness,
preview_chunk: Rect,
- preview: Paragraph,
+ preview: Paragraph<'_>,
prefix_width: u16,
) {
let input = self.build_input(style, prefix_width);
@@ -1088,7 +1088,6 @@ impl State {
title.alignment(Alignment::Left)
}
- #[expect(clippy::unused_self)]
fn build_help(&self, settings: &Settings) -> Paragraph<'_> {
match self.tab_index {
// search
@@ -1272,7 +1271,7 @@ impl TerminalWriter {
fn new() -> std::io::Result<Self> {
let stdout = stdout();
if stdout.is_terminal() {
- return Ok(TerminalWriter::Stdout(stdout));
+ return Ok(Self::Stdout(stdout));
}
// If stdout is not a terminal (e.g., captured by command substitution),
@@ -1280,7 +1279,7 @@ impl TerminalWriter {
// This allows usage like: VAR=$(atuin search -i)
#[cfg(unix)]
{
- Ok(TerminalWriter::Tty(
+ Ok(Self::Tty(
std::fs::File::options()
.read(true)
.write(true)
@@ -1293,17 +1292,17 @@ impl TerminalWriter {
impl Write for TerminalWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
match self {
- TerminalWriter::Stdout(stdout) => stdout.write(buf),
+ Self::Stdout(stdout) => stdout.write(buf),
#[cfg(unix)]
- TerminalWriter::Tty(file) => file.write(buf),
+ Self::Tty(file) => file.write(buf),
}
}
fn flush(&mut self) -> std::io::Result<()> {
match self {
- TerminalWriter::Stdout(stdout) => stdout.flush(),
+ Self::Stdout(stdout) => stdout.flush(),
#[cfg(unix)]
- TerminalWriter::Tty(file) => file.flush(),
+ Self::Tty(file) => file.flush(),
}
}
}
@@ -1395,27 +1394,32 @@ fn restore_popup_area(saved: &SavedScreen, popup_rect: Rect, scroll_offset: u16)
// beforehand. We write `popup_rect.width` spaces instead of
// ClearType::CurrentLine so that only the popup area is cleared, not
// the entire terminal line.
- let _ = execute!(
+ drop(execute!(
stdout,
MoveTo(popup_rect.x, target_row),
- ratatui::crossterm::style::SetAttribute(ratatui::crossterm::style::Attribute::Reset),
- );
- let _ = write!(stdout, "{:width$}", "", width = popup_rect.width as usize);
- let _ = execute!(stdout, MoveTo(popup_rect.x, target_row));
+ crossterm::style::SetAttribute(crossterm::style::Attribute::Reset),
+ ));
+ drop(write!(
+ stdout,
+ "{:width$}",
+ "",
+ width = popup_rect.width as usize
+ ));
+ drop(execute!(stdout, MoveTo(popup_rect.x, target_row)));
if let Some(row_bytes) = saved.rows_data.get(source_row) {
- let _ = stdout.write_all(row_bytes);
+ drop(stdout.write_all(row_bytes));
}
}
- let _ = execute!(
+ drop(execute!(
stdout,
MoveTo(
saved.cursor_col,
saved.cursor_row.saturating_sub(scroll_offset)
)
- );
- let _ = stdout.flush();
+ ));
+ drop(stdout.flush());
}
struct Stdout {
@@ -1534,11 +1538,7 @@ fn compute_popup_placement(
// for now, it works. But it'd be great if it were more easily readable, and
// modular. I'd like to add some more stats and stuff at some point
-#[expect(
- clippy::cast_possible_truncation,
- clippy::too_many_lines,
- clippy::cognitive_complexity
-)]
+#[expect(clippy::too_many_lines, clippy::cognitive_complexity)]
pub(crate) async fn history(
query: &[String],
settings: &Settings,
@@ -1589,11 +1589,11 @@ pub(crate) async fn history(
if scroll > 0 {
use ratatui::crossterm::cursor::MoveTo;
let mut stdout = stdout();
- let _ = execute!(stdout, MoveTo(0, term_rows - 1));
+ drop(execute!(stdout, MoveTo(0, term_rows - 1)));
for _ in 0..scroll {
- let _ = writeln!(stdout);
+ drop(writeln!(stdout));
}
- let _ = stdout.flush();
+ drop(stdout.flush());
}
(saved, popup_rect, scroll)
@@ -1619,20 +1619,20 @@ pub(crate) async fn history(
let mut raw_stdout = std::io::stdout();
// Queue all commands without flushing so the terminal receives them
// as a single write — no intermediate cursor positions are visible.
- let _ = queue!(
+ drop(queue!(
raw_stdout,
- ratatui::crossterm::style::SetAttribute(ratatui::crossterm::style::Attribute::Reset)
- );
+ crossterm::style::SetAttribute(crossterm::style::Attribute::Reset)
+ ));
for row in popup_rect.y..popup_rect.y.saturating_add(popup_rect.height) {
- let _ = queue!(raw_stdout, MoveTo(popup_rect.x, row));
- let _ = write!(
+ drop(queue!(raw_stdout, MoveTo(popup_rect.x, row)));
+ drop(write!(
raw_stdout,
"{:width$}",
"",
width = popup_rect.width as usize
- );
+ ));
}
- let _ = raw_stdout.flush();
+ drop(raw_stdout.flush());
}
let backend = CrosstermBackend::new(stdout);
@@ -1996,7 +1996,7 @@ mod tests {
strategy: PreviewStrategy::Auto,
},
show_preview: true,
- ..Settings::now()
+ ..Settings::new().unwrap()
};
let settings_preview_auto_h2 = Settings {
@@ -2005,7 +2005,7 @@ mod tests {
},
show_preview: true,
max_preview_height: 2,
- ..Settings::now()
+ ..Settings::new().unwrap()
};
let settings_preview_h4 = Settings {
@@ -2014,7 +2014,7 @@ mod tests {
},
show_preview: true,
max_preview_height: 4,
- ..Settings::now()
+ ..Settings::new().unwrap()
};
let settings_preview_fixed = Settings {
@@ -2023,25 +2023,25 @@ mod tests {
},
show_preview: true,
max_preview_height: 15,
- ..Settings::now()
+ ..Settings::new().unwrap()
};
let cmd_60: History = History::capture()
- .timestamp(time::OffsetDateTime::now_utc())
+ .timestamp(OffsetDateTime::now_utc())
.command("for i in $(seq -w 10); do echo \"item number $i - abcd\"; done")
.cwd("/")
.build()
.into();
let cmd_124: History = History::capture()
- .timestamp(time::OffsetDateTime::now_utc())
+ .timestamp(OffsetDateTime::now_utc())
.command("echo 'Aurea prima sata est aetas, quae vindice nullo, sponte sua, sine lege fidem rectumque colebat. Poena metusque aberant'")
.cwd("/")
.build()
.into();
let cmd_200: History = History::capture()
- .timestamp(time::OffsetDateTime::now_utc())
+ .timestamp(OffsetDateTime::now_utc())
.command("CREATE USER atuin WITH ENCRYPTED PASSWORD 'supersecretpassword'; CREATE DATABASE atuin WITH OWNER = atuin; \\c atuin; REVOKE ALL PRIVILEGES ON SCHEMA public FROM PUBLIC; echo 'All done. 200 characters'")
.cwd("/")
.build()
@@ -2145,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::now();
+ let settings = Settings::new().unwrap();
let mut state = State {
history_count: 0,
results_state: ListState::default(),
@@ -2190,7 +2190,7 @@ mod tests {
use crate::atuin_client::settings::Keys;
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
- let mut settings = Settings::now();
+ let mut settings = Settings::new().unwrap();
settings.keys = Keys {
scroll_exits: true,
exit_past_line_start: false,
@@ -2316,7 +2316,7 @@ mod tests {
fn test_vim_gg_multikey_sequence() {
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let mut state = State {
history_count: 100,
@@ -2374,7 +2374,7 @@ mod tests {
fn test_vim_g_key_clears_on_other_input() {
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let mut state = State {
history_count: 100,
@@ -2428,7 +2428,7 @@ mod tests {
fn test_vim_big_g_jump_to_bottom() {
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let mut state = State {
history_count: 100,
@@ -2475,10 +2475,11 @@ mod tests {
}
#[test]
+ #[allow(clippy::similar_names)]
fn test_vim_ctrl_u_d_half_page_scroll() {
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let mut state = State {
history_count: 100,
@@ -2534,10 +2535,11 @@ mod tests {
}
#[test]
+ #[allow(clippy::similar_names)]
fn test_vim_ctrl_f_b_full_page_scroll() {
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let mut state = State {
history_count: 100,
@@ -2598,7 +2600,7 @@ mod tests {
/// Helper to build a State for executor tests.
fn make_executor_state(results_len: usize, selected: usize) -> State {
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let mut state = State {
history_count: results_len as i64,
results_state: ListState::default(),
@@ -2642,7 +2644,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 50);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::SelectNext, &settings);
assert!(matches!(result, super::InputAction::Continue));
// Non-inverted: SelectNext = scroll_down = selected - 1
@@ -2654,7 +2656,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 50);
- let mut settings = Settings::now();
+ let mut settings = Settings::new().unwrap();
settings.invert = true;
let result = state.execute_action(&Action::SelectNext, &settings);
assert!(matches!(result, super::InputAction::Continue));
@@ -2667,7 +2669,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 50);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::SelectPrevious, &settings);
assert!(matches!(result, super::InputAction::Continue));
// Non-inverted: SelectPrevious = scroll_up = selected + 1
@@ -2679,7 +2681,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 0);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::VimEnterNormal, &settings);
assert!(matches!(result, super::InputAction::Continue));
assert_eq!(state.keymap_mode, KeymapMode::VimNormal);
@@ -2691,7 +2693,7 @@ mod tests {
let mut state = make_executor_state(100, 0);
state.keymap_mode = KeymapMode::VimNormal;
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::VimEnterInsert, &settings);
assert!(matches!(result, super::InputAction::Continue));
assert_eq!(state.keymap_mode, KeymapMode::VimInsert);
@@ -2702,7 +2704,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 5);
- let mut settings = Settings::now();
+ let mut settings = Settings::new().unwrap();
settings.enter_accept = true;
let result = state.execute_action(&Action::Accept, &settings);
assert!(matches!(result, super::InputAction::Accept(5)));
@@ -2714,7 +2716,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 5);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::ReturnSelection, &settings);
assert!(matches!(result, super::InputAction::Accept(5)));
assert!(!state.accept);
@@ -2725,7 +2727,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 5);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::AcceptNth(3), &settings);
assert!(matches!(result, super::InputAction::Accept(8)));
}
@@ -2735,7 +2737,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 50);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::ScrollToTop, &settings);
assert!(matches!(result, super::InputAction::Continue));
// Non-inverted: visual top = highest index
@@ -2747,7 +2749,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 50);
- let mut settings = Settings::now();
+ let mut settings = Settings::new().unwrap();
settings.invert = true;
let result = state.execute_action(&Action::ScrollToTop, &settings);
assert!(matches!(result, super::InputAction::Continue));
@@ -2760,7 +2762,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 50);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::ScrollToBottom, &settings);
assert!(matches!(result, super::InputAction::Continue));
// Non-inverted: visual bottom = index 0
@@ -2772,7 +2774,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 0);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
assert_eq!(state.tab_index, 0);
state.execute_action(&Action::ToggleTab, &settings);
assert_eq!(state.tab_index, 1);
@@ -2785,7 +2787,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 0);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
assert!(!state.prefix);
state.execute_action(&Action::EnterPrefixMode, &settings);
assert!(state.prefix);
@@ -2797,7 +2799,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 0);
- let mut settings = Settings::now();
+ let mut settings = Settings::new().unwrap();
settings.exit_mode = ExitMode::ReturnOriginal;
let result = state.execute_action(&Action::Exit, &settings);
@@ -2813,7 +2815,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 0);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::ReturnOriginal, &settings);
assert!(matches!(result, super::InputAction::ReturnOriginal));
}
@@ -2823,7 +2825,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 7);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::Copy, &settings);
assert!(matches!(result, super::InputAction::Copy(7)));
}
@@ -2833,7 +2835,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 7);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::Delete, &settings);
assert!(matches!(result, super::InputAction::Delete(7)));
}
@@ -2843,7 +2845,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 7);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::SwitchContext, &settings);
assert!(matches!(result, super::InputAction::SwitchContext(Some(7))));
}
@@ -2853,7 +2855,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 7);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::ClearContext, &settings);
assert!(matches!(result, super::InputAction::SwitchContext(None)));
}
@@ -2863,7 +2865,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 50);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::Noop, &settings);
assert!(matches!(result, super::InputAction::Continue));
assert_eq!(state.results_state.selected(), 50);
@@ -2875,7 +2877,7 @@ mod tests {
let mut state = make_executor_state(100, 5);
state.tab_index = 1;
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::Accept, &settings);
assert!(matches!(result, super::InputAction::AcceptInspecting));
}
@@ -2885,7 +2887,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 0);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let original_mode = state.search_mode;
let result = state.execute_action(&Action::CycleSearchMode, &settings);
assert!(matches!(result, super::InputAction::Continue));
@@ -2901,7 +2903,7 @@ mod tests {
state.search.input.insert('h');
state.search.input.insert('i');
state.keymap_mode = KeymapMode::VimNormal;
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
let result = state.execute_action(&Action::VimSearchInsert, &settings);
assert!(matches!(result, super::InputAction::Continue));
// Should clear input and switch to insert mode
@@ -2914,7 +2916,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 0);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
// Insert some text
state.search.input.insert('h');
@@ -2946,7 +2948,7 @@ mod tests {
use crate::command::client::search::keybindings::Action;
let mut state = make_executor_state(100, 0);
- let settings = Settings::now();
+ let settings = Settings::new().unwrap();
// Insert "hello"
state.search.input.insert('h');
@@ -2970,7 +2972,7 @@ mod tests {
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use std::collections::HashMap;
- let mut settings = Settings::now();
+ let mut settings = Settings::new().unwrap();
// Configure tab to return-query
settings.keymap.emacs = HashMap::from([(
"tab".to_string(),