feat: support NO_COLOR when PrettyPrinter is used (#2098)

This commit is contained in:
Kalvin C
2025-04-09 11:39:35 -07:00
committed by GitHub
parent 7575962f1f
commit a8cbd81c61

View File

@@ -358,10 +358,17 @@ fn print_tool_header(call: &ToolCall) {
println!("{}", tool_header);
}
// Respect NO_COLOR, as https://crates.io/crates/console already does
pub fn env_no_color() -> bool {
// if NO_COLOR is defined at all disable colors
std::env::var_os("NO_COLOR").is_none()
}
fn print_markdown(content: &str, theme: Theme) {
bat::PrettyPrinter::new()
.input(bat::Input::from_bytes(content.as_bytes()))
.theme(theme.as_str())
.colored_output(env_no_color())
.language("Markdown")
.wrapping_mode(WrappingMode::NoWrapping(true))
.print()