fixed spinners and trimmed result

i18n
Michal S 2 years ago
parent 40a342dd3c
commit d55845090f
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -9,7 +9,6 @@ use internal::error::SilentUnwrap;
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use std::str::FromStr; use std::str::FromStr;
use textwrap::{termwidth, wrap};
use crate::args::{ use crate::args::{
GenCompArgs, InfoArgs, InstallArgs, Operation, QueryArgs, RemoveArgs, SearchArgs, UpgradeArgs, GenCompArgs, InfoArgs, InstallArgs, Operation, QueryArgs, RemoveArgs, SearchArgs, UpgradeArgs,
@ -160,36 +159,43 @@ fn cmd_search(args: &SearchArgs, options: Options) {
let repo = args.repo || both; let repo = args.repo || both;
let aur = args.aur || both; let aur = args.aur || both;
// Start repo spinner
let repo_results = if repo { let repo_results = if repo {
info!("Searching repos for {}", &query_string); let rsp = spinner!("Searching repos for {}", query_string);
// Search repos // Search repos
operations::search(&query_string, options) let ret = operations::search(&query_string, options);
rsp.stop_bold("Repo search complete");
ret
} else { } else {
"".to_string() "".to_string()
}; };
// Start AUR spinner
let aur_results = if aur { let aur_results = if aur {
info!("Searching AUR for {}", &query_string); let asp = spinner!("Searching AUR for {}", query_string);
// Search AUR // Search AUR
operations::aur_search(&query_string, options) let ret = operations::aur_search(&query_string, options);
asp.stop_bold("AUR search complete");
ret
} else { } else {
"".to_string() "".to_string()
}; };
let opts = textwrap::Options::new(termwidth()); let results = repo_results + "\n" + &aur_results;
// Attempt to wrap result text // Print results either way, so that the user can see the results after they exit `less`
let results = wrap(&(repo_results + "\n" + &aur_results), opts).join("\n"); println!("{}", results.trim());
// Check if results are longer than terminal height // Check if results are longer than terminal height
if results.lines().count() > crossterm::terminal::size().unwrap().1 as usize { if results.lines().count() > crossterm::terminal::size().unwrap().1 as usize {
// If so, paginate results // If so, paginate results
#[allow(clippy::let_underscore_drop)] #[allow(clippy::let_underscore_drop)]
let _ = pager(&results); let _ = pager(&results.trim().to_string());
} }
// Print results either way, so that the user can see the results after they exit `less`
println!("{}", results);
} }
fn cmd_query(args: &QueryArgs) { fn cmd_query(args: &QueryArgs) {

Loading…
Cancel
Save