Ensure Pythons are aligned in uv python list (#4884)

## Summary

The existing tab input sometimes leads to misalignment on my machine, I
think it has to do with breakpoints?

![Screenshot 2024-07-07 at 9 22
43 PM](c95c5d26-3acb-48a6-8cce-d76f219f5afe)

This PR computes the width explicitly, and then pads each line. I also
added some colors to the RHS. I think it makes it easier to scan, but
don't feel strongly.

![Screenshot 2024-07-07 at 9 36
56 PM](1c89c83b-9562-4597-a892-021573c48f8d)
This commit is contained in:
Charlie Marsh 2024-07-07 20:52:30 -05:00 committed by GitHub
parent 98a720ec08
commit ae242c3b8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@ use std::collections::{BTreeSet, HashSet};
use std::fmt::Write;
use anyhow::Result;
use owo_colors::OwoColorize;
use uv_cache::Cache;
use uv_configuration::PreviewMode;
@ -107,6 +108,7 @@ pub(crate) async fn list(
let mut seen_minor = HashSet::new();
let mut seen_patch = HashSet::new();
let mut include = Vec::new();
for (version, os, key, kind, path) in output.iter().rev() {
// Only show the latest patch version for each download unless all were requested
if !matches!(kind, Kind::System) {
@ -125,10 +127,28 @@ pub(crate) async fn list(
}
}
}
include.push((key, path));
}
// Compute the width of the first column.
let width = include
.iter()
.fold(0usize, |acc, (key, _)| acc.max(key.to_string().len()));
for (key, path) in include {
let key = key.to_string();
if let Some(path) = path {
writeln!(printer.stdout(), "{key}\t{}", path.user_display())?;
writeln!(
printer.stdout(),
"{key:width$} {}",
path.user_display().cyan()
)?;
} else {
writeln!(printer.stdout(), "{key}\t<download available>")?;
writeln!(
printer.stdout(),
"{key:width$} {}",
"<download available>".dimmed()
)?;
}
}