Skip to content

Commit

Permalink
Fix for when service name is short
Browse files Browse the repository at this point in the history
  • Loading branch information
OTheDev committed May 6, 2024
1 parent 34c1ced commit 3be8858
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,20 @@ fn list_passwords(pwd_manager: &PwdManager) -> Result<()> {
if uids.is_empty() {
println!("No passwords stored.");
} else {
let max_service_len =
uids.iter().map(|uid| uid.service.len()).max().unwrap_or(0);
let max_service_len = uids
.iter()
.map(|uid| uid.service.len())
.max()
.unwrap_or(0)
.max("Service".len());
let max_username_len = uids
.iter()
.filter_map(|uid| uid.username.as_ref().map(String::len))
.max()
.unwrap_or(0);
let separator_len = " | ".len();
let header_len = max_service_len + separator_len + "Username".len();

println!(
"\n{0:<pad$} | {1}",
"Service".cyan(),
Expand Down

0 comments on commit 3be8858

Please sign in to comment.