diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 6d73bf2f..d17b081f 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -39,7 +39,7 @@ serde = { features = ["derive"], version = "1.0.125" } serde_json = "1.0.64" tar = "0.4.38" tempfile = "3.2.0" -term_size = "0.3.2" +terminal_size = "0.3" tokio = { features = ["io-std", "time", "process", "rt", "net"], version = ">= 1.13.0" } tokio-util = { features = ["io-util"], version = "0.7" } tokio-stream = { features = ["sync"], version = "0.1.8" } diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 4a994ca3..4544bc31 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -724,16 +724,17 @@ async fn container_store( Ok(()) } -fn print_column(s: &str, clen: usize, remaining: &mut usize) { - let l = s.len().min(*remaining); - print!("{}", &s[0..l]); +fn print_column(s: &str, clen: u16, remaining: &mut terminal_size::Width) { + let l: u16 = s.len().try_into().unwrap(); + let l = l.min(remaining.0); + print!("{}", &s[0..l as usize]); if clen > 0 { // We always want two trailing spaces let pad = clen.saturating_sub(l) + 2; for _ in 0..pad { print!(" "); } - *remaining = remaining.checked_sub(l + pad).unwrap(); + remaining.0 = remaining.0.checked_sub(l + pad).unwrap(); } } @@ -741,8 +742,10 @@ fn print_column(s: &str, clen: usize, remaining: &mut usize) { async fn container_history(repo: &ostree::Repo, imgref: &ImageReference) -> Result<()> { let img = crate::container::store::query_image_ref(repo, imgref)? .ok_or_else(|| anyhow::anyhow!("No such image: {}", imgref))?; - let columns = [("ID", 20), ("SIZE", 10), ("CREATED BY", 0usize)]; - let width = term_size::dimensions().map(|x| x.0).unwrap_or(80); + let columns = [("ID", 20u16), ("SIZE", 10), ("CREATED BY", 0)]; + let width = terminal_size::terminal_size() + .map(|x| x.0) + .unwrap_or(terminal_size::Width(80)); if let Some(config) = img.configuration.as_ref() { { let mut remaining = width; @@ -766,7 +769,7 @@ async fn container_history(repo: &ostree::Repo, imgref: &ImageReference) -> Resu // Verify it's OK to slice, this should all be ASCII assert!(digest.chars().all(|c| c.is_ascii())); let digest_max = columns[0].1; - let digest = &digest[0..digest_max]; + let digest = &digest[0..digest_max as usize]; print_column(digest, digest_max, &mut remaining); let size = glib::format_size(layer.size() as u64); print_column(size.as_str(), columns[1].1, &mut remaining);