Skip to content

Commit b58ec5a

Browse files
purplesyringaneuschaefer
authored andcommitted
Update owo-colors
The goal here is to remove a transitive dependency on the deprecated `atty` crate, which trips `cargo deny` because it's unmaintained. This currently does not eliminate the dependency completely, as we're still waiting on `color-eyre` to release [1], and merging this PR as-is would result in `cargo deny` being even more angry at using different versions of the same crate, so this PR is a draft for now. The update is non-trivial because `owo-colors` no longer supports checking whether stdin supports colors, which is, well, reasonable. Semantically, this cements the `Stream` trait as something that can be printed onto, rather than a generic-purpose stream. Uses of `as_tty` are replaced with a direct call to the `std` `is_terminal` function, and `Stream` (now called `OwoStream`) now exclusively handles mapping `std` I/O streams to `owo-colors` streams. [1]: eyre-rs/eyre#215
1 parent baf457e commit b58ec5a

File tree

7 files changed

+45
-74
lines changed

7 files changed

+45
-74
lines changed

Cargo.lock

Lines changed: 24 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ signal-hook = { version = "0.3.15" }
4646
directories = "4.0.1"
4747
walkdir = { version = "2.3.2", optional = true }
4848
tempfile = "3.3.0"
49-
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
49+
owo-colors = { version = "4.0", features = ["supports-colors"] }
5050
semver = "1.0.16"
5151
is_ci = "1.1.1"
5252

deny.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ targets = [
99

1010
[advisories]
1111
version = 2
12-
ignore = [
13-
# FIXME: remove this if/when clap changes to is-terminal, atty is
14-
# patched, or we migrated to an MSRV of 1.66.0.
15-
"RUSTSEC-2021-0145",
16-
"RUSTSEC-2024-0375"
17-
]
1812

1913
[bans]
2014
multiple-versions = "deny"

src/bin/commands/containers.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use std::io;
33
use clap::{Args, Subcommand};
44
use cross::docker::ImagePlatform;
55
use cross::rustc::{QualifiedToolchain, Toolchain};
6-
use cross::shell::{MessageInfo, Stream};
6+
use cross::shell::MessageInfo;
77
use cross::{docker, CommandExt, TargetTriple};
8+
use is_terminal::IsTerminal;
89

910
#[derive(Args, Debug)]
1011
pub struct ListVolumes {
@@ -327,7 +328,8 @@ pub fn create_persistent_volume(
327328
docker.arg("--rm");
328329
docker.args(["-v", &format!("{}:{}", volume_id, mount_prefix)]);
329330
docker.arg("-d");
330-
let is_tty = io::Stdin::is_atty() && io::Stdout::is_atty() && io::Stderr::is_atty();
331+
let is_tty =
332+
io::stdin().is_terminal() && io::stdout().is_terminal() && io::stderr().is_terminal();
331333
if is_tty {
332334
docker.arg("-t");
333335
}

src/docker/local.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use super::shared::*;
77
use crate::errors::Result;
88
use crate::extensions::CommandExt;
99
use crate::file::{PathExt, ToUtf8};
10-
use crate::shell::{MessageInfo, Stream};
10+
use crate::shell::MessageInfo;
1111
use eyre::Context;
12+
use is_terminal::IsTerminal;
1213

1314
// NOTE: host path must be absolute
1415
fn mount(
@@ -136,7 +137,7 @@ pub(crate) fn run(
136137
]);
137138
}
138139

139-
if io::Stdin::is_atty() && io::Stdout::is_atty() && io::Stderr::is_atty() {
140+
if io::stdin().is_terminal() && io::stdout().is_terminal() && io::stderr().is_terminal() {
140141
docker.arg("-t");
141142
}
142143

src/docker/remote.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::process::{Command, ExitStatus};
55
use std::{env, fs, time};
66

77
use eyre::Context;
8+
use is_terminal::IsTerminal;
89

910
use super::engine::Engine;
1011
use super::shared::*;
@@ -13,7 +14,7 @@ use crate::errors::Result;
1314
use crate::extensions::CommandExt;
1415
use crate::file::{self, PathExt, ToUtf8};
1516
use crate::rustc::{self, QualifiedToolchain, VersionMetaExt};
16-
use crate::shell::{MessageInfo, Stream};
17+
use crate::shell::MessageInfo;
1718
use crate::temp;
1819
use crate::TargetTriple;
1920

@@ -774,7 +775,8 @@ pub(crate) fn run(
774775
}
775776

776777
docker.arg("-d");
777-
let is_tty = io::Stdin::is_atty() && io::Stdout::is_atty() && io::Stderr::is_atty();
778+
let is_tty =
779+
io::stdin().is_terminal() && io::stdout().is_terminal() && io::stderr().is_terminal();
778780
if is_tty {
779781
docker.arg("-t");
780782
}

src/shell.rs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::str::FromStr;
88

99
use crate::config::bool_from_envvar;
1010
use crate::errors::Result;
11-
use is_terminal::IsTerminal;
1211
use owo_colors::{self, OwoColorize};
1312

1413
// get the prefix for stderr messages
@@ -201,7 +200,7 @@ impl MessageInfo {
201200
self.as_verbosity(call, Verbosity::Verbose(2))
202201
}
203202

204-
fn erase_line<S: Stream + Write>(&mut self, stream: &mut S) -> Result<()> {
203+
fn erase_line<S: OwoStream + Write>(&mut self, stream: &mut S) -> Result<()> {
205204
// this is the Erase in Line sequence
206205
stream.write_all(b"\x1B[K").map_err(Into::into)
207206
}
@@ -449,42 +448,19 @@ fn get_verbosity(
449448
})
450449
}
451450

452-
pub trait Stream {
453-
type TTY: IsTerminal;
454-
const OWO: owo_colors::Stream;
455-
456-
#[must_use]
457-
fn is_atty() -> bool;
458-
459-
fn owo(&self) -> owo_colors::Stream {
460-
Self::OWO
461-
}
451+
trait OwoStream {
452+
fn owo(&self) -> owo_colors::Stream;
462453
}
463454

464-
impl Stream for io::Stdin {
465-
type TTY = io::Stdin;
466-
const OWO: owo_colors::Stream = owo_colors::Stream::Stdin;
467-
468-
fn is_atty() -> bool {
469-
io::stdin().is_terminal()
470-
}
471-
}
472-
473-
impl Stream for io::Stdout {
474-
type TTY = io::Stdout;
475-
const OWO: owo_colors::Stream = owo_colors::Stream::Stdout;
476-
477-
fn is_atty() -> bool {
478-
io::stdout().is_terminal()
455+
impl OwoStream for io::Stdout {
456+
fn owo(&self) -> owo_colors::Stream {
457+
owo_colors::Stream::Stdout
479458
}
480459
}
481460

482-
impl Stream for io::Stderr {
483-
type TTY = io::Stderr;
484-
const OWO: owo_colors::Stream = owo_colors::Stream::Stderr;
485-
486-
fn is_atty() -> bool {
487-
io::stderr().is_terminal()
461+
impl OwoStream for io::Stderr {
462+
fn owo(&self) -> owo_colors::Stream {
463+
owo_colors::Stream::Stderr
488464
}
489465
}
490466

0 commit comments

Comments
 (0)