diff --git a/Cargo.lock b/Cargo.lock index f5b429293..41d73ca17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -528,6 +528,7 @@ dependencies = [ name = "jujutsu" version = "0.2.0" dependencies = [ + "atty", "blake2", "bytes", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 187d90934..2ac5095c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ path = "src/main.rs" members = ["lib"] [dependencies] +atty = "0.2.14" blake2 = "0.9.2" bytes = "1.1.0" chrono = "0.4.19" diff --git a/src/ui.rs b/src/ui.rs index 09757dcb0..49a8d7af0 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -17,6 +17,7 @@ use std::path::{Component, Path, PathBuf}; use std::sync::{Mutex, MutexGuard}; use std::{fmt, io}; +use atty::Stream; use jujutsu_lib::commit::Commit; use jujutsu_lib::repo::RepoRef; use jujutsu_lib::repo_path::{RepoPath, RepoPathComponent, RepoPathJoin}; @@ -48,10 +49,9 @@ impl<'stdout> Ui<'stdout> { pub fn new( cwd: PathBuf, stdout: Box, - is_atty: bool, + color: bool, settings: UserSettings, ) -> Ui<'stdout> { - let color = is_atty; let formatter = Mutex::new(new_formatter(&settings, color, stdout)); Ui { cwd, @@ -64,7 +64,16 @@ impl<'stdout> Ui<'stdout> { pub fn for_terminal(settings: UserSettings) -> Ui<'static> { let cwd = std::env::current_dir().unwrap(); let stdout: Box = Box::new(io::stdout()); - Ui::new(cwd, stdout, true, settings) + let color_setting = settings + .config() + .get_str("ui.color") + .unwrap_or_else(|_| "auto".to_string()); + let color = match color_setting.as_str() { + "always" => true, + "never" => false, + _ => atty::is(Stream::Stdout), + }; + Ui::new(cwd, stdout, color, settings) } pub fn cwd(&self) -> &Path {