From b57ea96b889ca77c30f5348994a7196f853b049c Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Mon, 6 Oct 2025 22:59:04 +0100 Subject: [PATCH] Factor out colour TTY detection --- src/options.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/options.rs b/src/options.rs index dca3b928c..d4f4c4317 100644 --- a/src/options.rs +++ b/src/options.rs @@ -998,16 +998,18 @@ fn detect_terminal_width() -> usize { pub(crate) fn should_use_color(color_output: ColorOutput) -> bool { match color_output { ColorOutput::Always => true, - ColorOutput::Auto => { - // Always enable colour if stdout is a TTY or if the git pager is active. - // TODO: consider following the env parsing logic in git_config_bool - // in config.c. - std::io::stdout().is_tty() || env::var("GIT_PAGER_IN_USE").is_ok() - } + ColorOutput::Auto => detect_color_support(), ColorOutput::Never => false, } } +/// Always enable colour if stdout is a TTY or if the git pager is active. +fn detect_color_support() -> bool { + // TODO: consider following the env parsing logic in git_config_bool + // in config.c. + std::io::stdout().is_tty() || env::var("GIT_PAGER_IN_USE").is_ok() +} + #[cfg(test)] mod tests { use super::*;