fix: style

This commit is contained in:
iff 2024-12-07 00:14:30 +01:00
parent 1ddfbef7e7
commit 838eac5852
2 changed files with 23 additions and 8 deletions

View file

@ -8,7 +8,6 @@ pub fn highlight_difference(
shell: &str, shell: &str,
suggested_command: &str, suggested_command: &str,
last_command: &str, last_command: &str,
difference_only: bool,
) -> Option<String> { ) -> Option<String> {
// let replaced_newline = suggested_command.replace('\n', r" {{newline}} "); // let replaced_newline = suggested_command.replace('\n', r" {{newline}} ");
let mut split_suggested_command = split_command(suggested_command); let mut split_suggested_command = split_command(suggested_command);
@ -43,9 +42,7 @@ pub fn highlight_difference(
} }
for old in &old_entries { for old in &old_entries {
if old == entry { if old == entry {
if !difference_only { *entry = entry.blue().to_string();
*entry = entry.blue().to_string();
}
continue 'next; continue 'next;
} }
} }

View file

@ -60,7 +60,7 @@ pub fn select_candidate(data: &mut Data) {
let candidates = &data.candidates; let candidates = &data.candidates;
if candidates.len() == 1 { if candidates.len() == 1 {
let suggestion = candidates[0].to_string(); 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); eprintln!("{}\n", highlighted);
let confirm = format!("[{}]", t!("confirm-yes")).green(); let confirm = format!("[{}]", t!("confirm-yes")).green();
eprintln!("{}: {} {}", t!("confirm"), confirm, "[Ctrl+C]".red()); eprintln!("{}: {} {}", t!("confirm"), confirm, "[Ctrl+C]".red());
@ -70,7 +70,7 @@ pub fn select_candidate(data: &mut Data) {
} else { } else {
let mut highlight_candidates = candidates let mut highlight_candidates = candidates
.iter() .iter()
.map(|candidate| highlight_difference(&data.shell, candidate, &data.command, true).unwrap()) .map(|candidate| highlight_difference(&data.shell, candidate, &data.command).unwrap())
.collect::<Vec<String>>(); .collect::<Vec<String>>();
for candidate in highlight_candidates.iter_mut() { for candidate in highlight_candidates.iter_mut() {
@ -80,13 +80,31 @@ pub fn select_candidate(data: &mut Data) {
if j == 0 { if j == 0 {
formated = line.to_string(); formated = line.to_string();
} else { } else {
formated = format!("{}\n {}", formated, line); formated = format!("{}\n {}", formated, line);
} }
} }
*candidate = formated; *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() .prompt()
.unwrap(); .unwrap();
let pos = highlight_candidates.iter().position(|x| x == &ans).unwrap(); let pos = highlight_candidates.iter().position(|x| x == &ans).unwrap();