From 838eac5852f5fb1c79083fd2831728a2f14ace73 Mon Sep 17 00:00:00 2001 From: iff Date: Sat, 7 Dec 2024 00:14:30 +0100 Subject: [PATCH] fix: style --- src/style.rs | 5 +---- src/suggestions.rs | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/style.rs b/src/style.rs index 4eb5719..edd7636 100644 --- a/src/style.rs +++ b/src/style.rs @@ -8,7 +8,6 @@ pub fn highlight_difference( shell: &str, suggested_command: &str, last_command: &str, - difference_only: bool, ) -> Option { // let replaced_newline = suggested_command.replace('\n', r" {{newline}} "); let mut split_suggested_command = split_command(suggested_command); @@ -43,9 +42,7 @@ pub fn highlight_difference( } for old in &old_entries { if old == entry { - if !difference_only { - *entry = entry.blue().to_string(); - } + *entry = entry.blue().to_string(); continue 'next; } } diff --git a/src/suggestions.rs b/src/suggestions.rs index 06620fb..7f526d7 100644 --- a/src/suggestions.rs +++ b/src/suggestions.rs @@ -60,7 +60,7 @@ pub fn select_candidate(data: &mut Data) { let candidates = &data.candidates; if candidates.len() == 1 { let suggestion = candidates[0].to_string(); - let highlighted = highlight_difference(&data.shell, &suggestion, &data.command, false).unwrap(); + let highlighted = highlight_difference(&data.shell, &suggestion, &data.command).unwrap(); eprintln!("{}\n", highlighted); let confirm = format!("[{}]", t!("confirm-yes")).green(); eprintln!("{}: {} {}", t!("confirm"), confirm, "[Ctrl+C]".red()); @@ -70,7 +70,7 @@ pub fn select_candidate(data: &mut Data) { } else { let mut highlight_candidates = candidates .iter() - .map(|candidate| highlight_difference(&data.shell, candidate, &data.command, true).unwrap()) + .map(|candidate| highlight_difference(&data.shell, candidate, &data.command).unwrap()) .collect::>(); for candidate in highlight_candidates.iter_mut() { @@ -80,13 +80,31 @@ pub fn select_candidate(data: &mut Data) { if j == 0 { formated = line.to_string(); } else { - formated = format!("{}\n {}", formated, line); + formated = format!("{}\n {}", formated, line); } } *candidate = formated; } - let ans = Select::new("Select a suggestion:", highlight_candidates.clone()) + let style = ui::Styled::default(); + let render_config = ui::RenderConfig::default() + .with_prompt_prefix(style) + .with_answered_prompt_prefix(style) + .with_highlighted_option_prefix(style); + + let msg = format!("{} suggestions found:", candidates.len()).bold().blue(); + let hint = format!("{} {} {}", + "[↑/↓]".blue(), + t!("confirm-yes").green(), + "[Ctrl+C]".red()); + eprintln!("{}", msg); + eprintln!("{}", hint); + + let ans = Select::new("\n", highlight_candidates.clone()) + .with_page_size(1) + .without_filtering() + .without_help_message() + .with_render_config(render_config) .prompt() .unwrap(); let pos = highlight_candidates.iter().position(|x| x == &ans).unwrap();