From c9aff94b8e3ddf12e9b7508cadc24fabbb6e691a Mon Sep 17 00:00:00 2001 From: Michal S Date: Sun, 4 Sep 2022 22:14:49 +0100 Subject: [PATCH] Fix printing Add padding opt to print_list --- src/internal/alpm.rs | 3 +++ src/logging/handler.rs | 9 +++++++-- src/logging/output.rs | 7 ++++--- src/main.rs | 4 +++- src/operations/search.rs | 8 ++++---- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/internal/alpm.rs b/src/internal/alpm.rs index d62b466..f43f7dd 100644 --- a/src/internal/alpm.rs +++ b/src/internal/alpm.rs @@ -22,9 +22,12 @@ impl From for Error { } } +#[tracing::instrument(level = "trace")] pub fn get_handler() -> Result { let config = Config::from_file(Path::new("/etc/pacman.conf"))?; let alpm = alpm_with_conf(&config)?; + tracing::debug!("Initialized alpm handler"); + Ok(alpm) } diff --git a/src/logging/handler.rs b/src/logging/handler.rs index 7c5f0d3..8b704bb 100644 --- a/src/logging/handler.rs +++ b/src/logging/handler.rs @@ -91,7 +91,12 @@ impl LogHandler { } } - pub fn print_list, T: Display>(&self, list: I, separator: &str) { + pub fn print_list, T: Display>( + &self, + list: I, + separator: &str, + padding: usize, + ) { let lines = list .into_iter() .map(|l| self.preformat_msg(l.to_string())) @@ -99,7 +104,7 @@ impl LogHandler { format!("{}{}{}", acc, separator, line) }); - let lines = wrap_text(lines, 2).join("\n"); + let lines = wrap_text(lines, padding).join("\n"); self.log(lines) } diff --git a/src/logging/output.rs b/src/logging/output.rs index 224a713..e76fef5 100644 --- a/src/logging/output.rs +++ b/src/logging/output.rs @@ -36,7 +36,7 @@ pub async fn print_dependency_list(dependencies: &[DependencyInformation]) -> bo let mut empty = true; if !deps_repo.is_empty() { tracing::info!("Repo dependencies"); - get_logger().print_list(&deps_repo, " "); + get_logger().print_list(&deps_repo, " ", 2); empty = false; get_logger().print_newline(); } @@ -49,7 +49,7 @@ pub async fn print_dependency_list(dependencies: &[DependencyInformation]) -> bo if !makedeps_repo.is_empty() { tracing::info!("Repo make dependencies"); - get_logger().print_list(&makedeps_repo, " "); + get_logger().print_list(&makedeps_repo, " ", 2); empty = false; get_logger().print_newline(); } @@ -94,7 +94,8 @@ pub async fn print_aur_package_list(packages: &[&PackageInfo]) -> bool { .magenta() ) }), - "\n ", + "\n", + 2, ); !installed.is_empty() diff --git a/src/main.rs b/src/main.rs index 863ed9c..0a29bbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use crate::args::{InstallArgs, Operation, QueryArgs, RemoveArgs, SearchArgs}; use crate::internal::detect; use crate::internal::exit_code::AppExitCode; use crate::internal::{sort, start_sudoloop, structs::Options}; +use crate::logging::get_logger; use crate::logging::Printable; use clap_complete::{Generator, Shell}; @@ -131,7 +132,8 @@ async fn cmd_search(args: SearchArgs, options: Options) { tracing::info!("No results found"); } else { tracing::info!("Results:"); - + let list: Vec = results.iter().map(|x| x.to_print_string()).collect(); + get_logger().print_list(list, "\n", 0); } } diff --git a/src/operations/search.rs b/src/operations/search.rs index 1d3f75f..f72f4bc 100644 --- a/src/operations/search.rs +++ b/src/operations/search.rs @@ -59,11 +59,11 @@ impl Printable for PackageSearchResult { .timestamp(self.out_of_date.unwrap().try_into().unwrap(), 0) .date_naive() ) - .bold() - .red() } else { - "".bold() - }; + "".to_string() + } + .bold() + .red(); let description = wrap_text(&self.description, 4).join("\n"); format!("{repo}{name} {version} {group} {out_of_date}\n {description}")