From 4e616ef684e39703dcd5aed38791ecca46404d19 Mon Sep 17 00:00:00 2001 From: Jeremiah Peschka Date: Wed, 4 May 2016 18:29:13 -0700 Subject: [PATCH] Refactoring TTY checks into rustup-utils --- Cargo.lock | 1 + src/rustup-cli/download_tracker.rs | 2 +- src/rustup-cli/main.rs | 1 - src/rustup-cli/term2.rs | 2 +- src/rustup-utils/Cargo.toml | 1 + src/rustup-utils/src/lib.rs | 4 ++++ src/{rustup-cli => rustup-utils/src}/tty.rs | 0 src/rustup/command.rs | 10 ++++++---- 8 files changed, 14 insertions(+), 7 deletions(-) rename src/{rustup-cli => rustup-utils/src}/tty.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 10fd679e97..9237e17b03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -483,6 +483,7 @@ dependencies = [ "error-chain 0.1.9", "hyper 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/rustup-cli/download_tracker.rs b/src/rustup-cli/download_tracker.rs index 3b726ded88..0c1cc5264a 100644 --- a/src/rustup-cli/download_tracker.rs +++ b/src/rustup-cli/download_tracker.rs @@ -5,7 +5,7 @@ use time::precise_time_s; use rustup::Notification; use rustup_dist::Notification as In; use rustup_utils::Notification as Un; -use tty; +use rustup_utils::tty; /// Keep track of this many past download amounts const DOWNLOAD_TRACK_COUNT: usize = 5; diff --git a/src/rustup-cli/main.rs b/src/rustup-cli/main.rs index 97c84ea1f4..87f29bfc9d 100644 --- a/src/rustup-cli/main.rs +++ b/src/rustup-cli/main.rs @@ -40,7 +40,6 @@ mod proxy_mode; mod setup_mode; mod rustup_mode; mod self_update; -mod tty; mod job; mod term2; mod errors; diff --git a/src/rustup-cli/term2.rs b/src/rustup-cli/term2.rs index 0a8d54f240..75bbada316 100644 --- a/src/rustup-cli/term2.rs +++ b/src/rustup-cli/term2.rs @@ -4,7 +4,7 @@ use std::io; use term; -use tty; +use rustup_utils::tty; pub use term::color; pub use term::Attr; diff --git a/src/rustup-utils/Cargo.toml b/src/rustup-utils/Cargo.toml index 0851477374..e3360f3d51 100644 --- a/src/rustup-utils/Cargo.toml +++ b/src/rustup-utils/Cargo.toml @@ -17,6 +17,7 @@ hyper = "0.7.0" rand = "0.3.11" scopeguard = "0.1.2" error-chain = { path = "../error-chain", version = "0.1.9" } +libc = "0.2.0" [target.x86_64-pc-windows-gnu.dependencies] winapi = "0.2.4" diff --git a/src/rustup-utils/src/lib.rs b/src/rustup-utils/src/lib.rs index 57a764c346..066cc43004 100644 --- a/src/rustup-utils/src/lib.rs +++ b/src/rustup-utils/src/lib.rs @@ -24,10 +24,14 @@ extern crate advapi32; #[cfg(windows)] extern crate userenv; +#[cfg(unix)] +extern crate libc; + pub mod notify; pub mod errors; pub mod notifications; pub mod raw; +pub mod tty; pub mod utils; pub use errors::*; diff --git a/src/rustup-cli/tty.rs b/src/rustup-utils/src/tty.rs similarity index 100% rename from src/rustup-cli/tty.rs rename to src/rustup-utils/src/tty.rs diff --git a/src/rustup/command.rs b/src/rustup/command.rs index 6be103a69f..4dddc652fa 100644 --- a/src/rustup/command.rs +++ b/src/rustup/command.rs @@ -33,10 +33,12 @@ fn telemetry_rustc>(mut cmd: Command, args: &[S], cfg: &Cfg) -> cmd.args(&args[1..]); - if stderr_isatty() && !(&args).iter().any(|e| { - let e = e.as_ref().to_str().unwrap_or(""); - e == "--color" - }) + let has_color_args = (&args).iter().any(|e| { + let e = e.as_ref().to_str().unwrap_or(""); + e.starts_with("--color") + }); + + if stderr_isatty() && !has_color_args { cmd.arg("--color"); cmd.arg("always");