From ae242c3b8f81737e06fddba0a548e522d4f05b71 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 7 Jul 2024 20:52:30 -0500 Subject: [PATCH] Ensure Pythons are aligned in `uv python list` (#4884) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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](https://github.com/astral-sh/uv/assets/1309177/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](https://github.com/astral-sh/uv/assets/1309177/1c89c83b-9562-4597-a892-021573c48f8d) --- crates/uv/src/commands/python/list.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/uv/src/commands/python/list.rs b/crates/uv/src/commands/python/list.rs index b8fb9ae4c..a621285f6 100644 --- a/crates/uv/src/commands/python/list.rs +++ b/crates/uv/src/commands/python/list.rs @@ -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")?; + writeln!( + printer.stdout(), + "{key:width$} {}", + "".dimmed() + )?; } }