mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
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?  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. 
This commit is contained in:
parent
98a720ec08
commit
ae242c3b8f
1 changed files with 22 additions and 2 deletions
|
@ -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()
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue