mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2026-02-02 15:45:11 +01:00
feat: candidates in list
This commit is contained in:
parent
0141cb0635
commit
7626c2278d
3 changed files with 18 additions and 16 deletions
|
|
@ -19,7 +19,7 @@ sys-locale = "0.3"
|
||||||
rust-i18n = "3"
|
rust-i18n = "3"
|
||||||
regex-lite = "0.1"
|
regex-lite = "0.1"
|
||||||
|
|
||||||
inquire = "0.7.5"
|
inquire = "0.7"
|
||||||
|
|
||||||
pay-respects-parser = { version = "0.3", path = "../parser" }
|
pay-respects-parser = { version = "0.3", path = "../parser" }
|
||||||
pay-respects-utils = { version ="0.1", path = "../utils"}
|
pay-respects-utils = { version ="0.1", path = "../utils"}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use colored::Colorize;
|
||||||
use inquire::*;
|
use inquire::*;
|
||||||
use pay_respects_utils::evals::best_matches_path;
|
use pay_respects_utils::evals::best_matches_path;
|
||||||
use pay_respects_utils::files::best_match_file;
|
use pay_respects_utils::files::best_match_file;
|
||||||
|
use ui::Color;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
|
@ -143,7 +144,13 @@ pub fn cnf(data: &mut Data) {
|
||||||
eprintln!("packages: {:?}", packages);
|
eprintln!("packages: {:?}", packages);
|
||||||
|
|
||||||
let style = ui::Styled::default();
|
let style = ui::Styled::default();
|
||||||
let render_config = ui::RenderConfig::default().with_prompt_prefix(style);
|
let render_config = ui::RenderConfig::default()
|
||||||
|
.with_prompt_prefix(style)
|
||||||
|
.with_highlighted_option_prefix(ui::Styled::new(">").with_fg(Color::LightBlue))
|
||||||
|
.with_scroll_up_prefix(ui::Styled::new("^"))
|
||||||
|
.with_scroll_down_prefix(ui::Styled::new("v"))
|
||||||
|
.with_option_index_prefix(ui::IndexPrefix::SpacePadded);
|
||||||
|
|
||||||
let msg = format!("{}:", t!("install-package")).bold().blue();
|
let msg = format!("{}:", t!("install-package")).bold().blue();
|
||||||
let confirm = format!("[{}]", t!("confirm-yes")).green();
|
let confirm = format!("[{}]", t!("confirm-yes")).green();
|
||||||
let hint = format!("{} {} {}", "[↑/↓]".blue(), confirm, "[Ctrl+C]".red());
|
let hint = format!("{} {} {}", "[↑/↓]".blue(), confirm, "[Ctrl+C]".red());
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use inquire::*;
|
use inquire::*;
|
||||||
|
use ui::Color;
|
||||||
|
|
||||||
use crate::rules::match_pattern;
|
use crate::rules::match_pattern;
|
||||||
use crate::shell::{add_candidates_no_dup, module_output, shell_evaluated_commands, Data};
|
use crate::shell::{add_candidates_no_dup, module_output, shell_evaluated_commands, Data};
|
||||||
|
|
@ -85,8 +86,8 @@ pub fn select_candidate(data: &mut Data) {
|
||||||
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, &suggestion).unwrap();
|
let highlighted = highlight_difference(data, &suggestion).unwrap();
|
||||||
eprintln!("{}\n", highlighted);
|
|
||||||
let confirm = format!("[{}]", t!("confirm-yes")).green();
|
let confirm = format!("[{}]", t!("confirm-yes")).green();
|
||||||
|
eprintln!("{}\n", highlighted);
|
||||||
eprintln!("{}: {} {}", t!("confirm"), confirm, "[Ctrl+C]".red());
|
eprintln!("{}: {} {}", t!("confirm"), confirm, "[Ctrl+C]".red());
|
||||||
std::io::stdin().read_line(&mut String::new()).unwrap();
|
std::io::stdin().read_line(&mut String::new()).unwrap();
|
||||||
data.update_suggest(&suggestion);
|
data.update_suggest(&suggestion);
|
||||||
|
|
@ -97,24 +98,19 @@ pub fn select_candidate(data: &mut Data) {
|
||||||
.map(|candidate| highlight_difference(data, candidate).unwrap())
|
.map(|candidate| highlight_difference(data, candidate).unwrap())
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
for candidate in highlight_candidates.iter_mut() {
|
if highlight_candidates.iter().any(|x| x.contains('\n')) {
|
||||||
let lines = candidate.lines().collect::<Vec<&str>>();
|
for candidate in highlight_candidates.iter_mut() {
|
||||||
let mut formated = String::new();
|
*candidate = format!("\t{}", candidate.replace("\n", "\n\t"));
|
||||||
for (j, line) in lines.iter().enumerate() {
|
|
||||||
if j == 0 {
|
|
||||||
formated = line.to_string();
|
|
||||||
} else {
|
|
||||||
formated = format!("{}\n {}", formated, line);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*candidate = formated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let style = ui::Styled::default();
|
let style = ui::Styled::default();
|
||||||
let render_config = ui::RenderConfig::default()
|
let render_config = ui::RenderConfig::default()
|
||||||
.with_prompt_prefix(style)
|
.with_prompt_prefix(style)
|
||||||
.with_answered_prompt_prefix(style)
|
.with_highlighted_option_prefix(ui::Styled::new(">").with_fg(Color::LightBlue))
|
||||||
.with_highlighted_option_prefix(style);
|
.with_scroll_up_prefix(ui::Styled::new("^").with_fg(Color::LightBlue))
|
||||||
|
.with_scroll_down_prefix(ui::Styled::new("v").with_fg(Color::LightBlue))
|
||||||
|
.with_option_index_prefix(ui::IndexPrefix::SpacePadded);
|
||||||
|
|
||||||
let msg = format!("{}", t!("multi-suggest", num = candidates.len()))
|
let msg = format!("{}", t!("multi-suggest", num = candidates.len()))
|
||||||
.bold()
|
.bold()
|
||||||
|
|
@ -125,7 +121,6 @@ pub fn select_candidate(data: &mut Data) {
|
||||||
eprintln!("{}", hint);
|
eprintln!("{}", hint);
|
||||||
|
|
||||||
let ans = Select::new("\n", highlight_candidates.clone())
|
let ans = Select::new("\n", highlight_candidates.clone())
|
||||||
.with_page_size(1)
|
|
||||||
.with_vim_mode(true)
|
.with_vim_mode(true)
|
||||||
.without_filtering()
|
.without_filtering()
|
||||||
.without_help_message()
|
.without_help_message()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue