Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update owo-colors #1611

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 24 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ signal-hook = { version = "0.3.15" }
directories = "4.0.1"
walkdir = { version = "2.3.2", optional = true }
tempfile = "3.3.0"
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
owo-colors = { version = "4.0", features = ["supports-colors"] }
semver = "1.0.16"
is_ci = "1.1.1"

Expand Down
5 changes: 0 additions & 5 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ targets = [

[advisories]
version = 2
# FIXME: remove this if/when clap changes to is-terminal, atty is
# patched, or we migrated to an MSRV of 1.66.0.
ignore = [
"RUSTSEC-2021-0145",
]

[bans]
multiple-versions = "deny"
Expand Down
6 changes: 4 additions & 2 deletions src/bin/commands/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::io;
use clap::{Args, Subcommand};
use cross::docker::ImagePlatform;
use cross::rustc::{QualifiedToolchain, Toolchain};
use cross::shell::{MessageInfo, Stream};
use cross::shell::MessageInfo;
use cross::{docker, CommandExt, TargetTriple};
use is_terminal::IsTerminal;

#[derive(Args, Debug)]
pub struct ListVolumes {
Expand Down Expand Up @@ -327,7 +328,8 @@ pub fn create_persistent_volume(
docker.arg("--rm");
docker.args(["-v", &format!("{}:{}", volume_id, mount_prefix)]);
docker.arg("-d");
let is_tty = io::Stdin::is_atty() && io::Stdout::is_atty() && io::Stderr::is_atty();
let is_tty =
io::stdin().is_terminal() && io::stdout().is_terminal() && io::stderr().is_terminal();
if is_tty {
docker.arg("-t");
}
Expand Down
5 changes: 3 additions & 2 deletions src/docker/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use crate::errors::Result;
use crate::extensions::CommandExt;
use crate::file::{PathExt, ToUtf8};
use crate::shell::{MessageInfo, Stream};
use crate::shell::MessageInfo;
use eyre::Context;
use is_terminal::IsTerminal;

// NOTE: host path must be absolute
fn mount(
Expand Down Expand Up @@ -136,7 +137,7 @@
]);
}

if io::Stdin::is_atty() && io::Stdout::is_atty() && io::Stderr::is_atty() {
if io::stdin().is_terminal() && io::stdout().is_terminal() && io::stderr().is_terminal() {
docker.arg("-t");
}

Expand Down Expand Up @@ -165,7 +166,7 @@
// terminate or it may be a known interrupt return status (130, 137, 143).
// simpler: just test if the program termination handler was called.
// SAFETY: an atomic load.
let is_terminated = unsafe { crate::errors::TERMINATED.load(Ordering::SeqCst) };

Check warning on line 169 in src/docker/local.rs

View workflow job for this annotation

GitHub Actions / docker-in-docker

creating a shared reference to mutable static is discouraged
if !is_terminated {
ChildContainer::exit_static();
}
Expand Down
6 changes: 4 additions & 2 deletions src/docker/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::process::{Command, ExitStatus};
use std::{env, fs, time};

use eyre::Context;
use is_terminal::IsTerminal;

use super::engine::Engine;
use super::shared::*;
Expand All @@ -13,7 +14,7 @@ use crate::errors::Result;
use crate::extensions::CommandExt;
use crate::file::{self, PathExt, ToUtf8};
use crate::rustc::{self, QualifiedToolchain, VersionMetaExt};
use crate::shell::{MessageInfo, Stream};
use crate::shell::MessageInfo;
use crate::temp;
use crate::TargetTriple;

Expand Down Expand Up @@ -774,7 +775,8 @@ pub(crate) fn run(
}

docker.arg("-d");
let is_tty = io::Stdin::is_atty() && io::Stdout::is_atty() && io::Stderr::is_atty();
let is_tty =
io::stdin().is_terminal() && io::stdout().is_terminal() && io::stderr().is_terminal();
if is_tty {
docker.arg("-t");
}
Expand Down
42 changes: 9 additions & 33 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::str::FromStr;

use crate::config::bool_from_envvar;
use crate::errors::Result;
use is_terminal::IsTerminal;
use owo_colors::{self, OwoColorize};

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

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

pub trait Stream {
type TTY: IsTerminal;
const OWO: owo_colors::Stream;

#[must_use]
fn is_atty() -> bool;

fn owo(&self) -> owo_colors::Stream {
Self::OWO
}
trait OwoStream {
fn owo(&self) -> owo_colors::Stream;
}

impl Stream for io::Stdin {
type TTY = io::Stdin;
const OWO: owo_colors::Stream = owo_colors::Stream::Stdin;

fn is_atty() -> bool {
io::stdin().is_terminal()
}
}

impl Stream for io::Stdout {
type TTY = io::Stdout;
const OWO: owo_colors::Stream = owo_colors::Stream::Stdout;

fn is_atty() -> bool {
io::stdout().is_terminal()
impl OwoStream for io::Stdout {
fn owo(&self) -> owo_colors::Stream {
owo_colors::Stream::Stdout
}
}

impl Stream for io::Stderr {
type TTY = io::Stderr;
const OWO: owo_colors::Stream = owo_colors::Stream::Stderr;

fn is_atty() -> bool {
io::stderr().is_terminal()
impl OwoStream for io::Stderr {
fn owo(&self) -> owo_colors::Stream {
owo_colors::Stream::Stderr
}
}

Expand Down
Loading