Fix Windows ANSI detection and enhance color debugging output

This commit is contained in:
xxanqw committed 2025-11-30 00:36:35 +02:00
1 parent 28e212e0ac
commit d0350658ac
2 files changed
+17 -1

No files matched your search

+3
View File
@@ -520,6 +520,9 @@ pub fn detect_color_mode() -> ColorMode {
}
// Default fallback
#[cfg(windows)]
let mut mode = ColorMode::Ansi16;
#[cfg(not(windows))]
let mode = ColorMode::Ansi16;
// If running on Windows, try to enable ANSI (virtual terminal processing)
+14 -1
View File
@@ -167,7 +167,7 @@ pub fn parse_color_args(args: &Args) -> Result<ColorConfig, Box<dyn Error>> {
// Determine if ANSI is enabled (Windows toggle helper) — don't enable if --no-color
#[cfg(windows)]
let ansi_enabled = !args.no_color && enable_windows_ansi();
let ansi_enabled = !args.no_color && color::enable_windows_ansi();
#[cfg(not(windows))]
let ansi_enabled = false;
@@ -505,6 +505,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Parse color-related arguments
let mut color_config = parse_color_args(&args)?;
if color_config.debug {
println!("Detected color mode: {:?}", color_config.mode);
println!("ANSI enabled: {}", color_config.ansi_enabled);
println!("NO_COLOR: {:?}", std::env::var("NO_COLOR").ok());
println!("COLORTERM: {:?}", std::env::var("COLORTERM").ok());
println!("TERM: {:?}", std::env::var("TERM").ok());
#[cfg(windows)]
{
println!("Windows shell hint: {:?}", color::detect_windows_shell());
}
return Ok(());
}
// If color debug is requested, print information and exit
if args.color_debug {
eprintln!("Color Debug: mode={:?}, ansi_enabled={}, rainbow={}, saturation={}, brightness={}",