From 8214bfe080b9e2ea345212e87c82bc3a7b2e7f7d Mon Sep 17 00:00:00 2001 From: konsti Date: Tue, 27 Feb 2024 17:02:23 +0100 Subject: [PATCH] Always remove color codes from output file (#2018) Always strip color codes when we're writing to a file. I don't really know how to test this. Fixes #2017 --- crates/uv/src/commands/pip_compile.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/uv/src/commands/pip_compile.rs b/crates/uv/src/commands/pip_compile.rs index cce4acfe6..c56aca9f2 100644 --- a/crates/uv/src/commands/pip_compile.rs +++ b/crates/uv/src/commands/pip_compile.rs @@ -6,7 +6,7 @@ use std::ops::Deref; use std::path::Path; use std::str::FromStr; -use anstream::{eprint, AutoStream}; +use anstream::{eprint, AutoStream, StripStream}; use anyhow::{anyhow, Context, Result}; use chrono::{DateTime, Utc}; use itertools::Itertools; @@ -484,7 +484,7 @@ fn cmd(include_index_url: bool, include_find_links: bool) -> String { #[allow(clippy::disallowed_types)] struct OutputWriter { stdout: Option>, - output_file: Option>, + output_file: Option>, } #[allow(clippy::disallowed_types)] @@ -493,10 +493,9 @@ impl OutputWriter { fn new(include_stdout: bool, output_file: Option<&Path>) -> Result { let stdout = include_stdout.then(|| AutoStream::::auto(stdout())); let output_file = output_file - .map(|output_file| { + .map(|output_file| -> Result<_, std::io::Error> { let output_file = fs_err::File::create(output_file)?; - let output_file = AutoStream::auto(output_file.into()); - Ok::, std::io::Error>(output_file) + Ok(StripStream::new(output_file.into())) }) .transpose()?; Ok(Self {