feat: support NO_COLOR when PrettyPrinter is used (#2098)
This commit is contained in:
@@ -358,10 +358,17 @@ fn print_tool_header(call: &ToolCall) {
|
|||||||
println!("{}", tool_header);
|
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) {
|
fn print_markdown(content: &str, theme: Theme) {
|
||||||
bat::PrettyPrinter::new()
|
bat::PrettyPrinter::new()
|
||||||
.input(bat::Input::from_bytes(content.as_bytes()))
|
.input(bat::Input::from_bytes(content.as_bytes()))
|
||||||
.theme(theme.as_str())
|
.theme(theme.as_str())
|
||||||
|
.colored_output(env_no_color())
|
||||||
.language("Markdown")
|
.language("Markdown")
|
||||||
.wrapping_mode(WrappingMode::NoWrapping(true))
|
.wrapping_mode(WrappingMode::NoWrapping(true))
|
||||||
.print()
|
.print()
|
||||||
|
|||||||
Reference in New Issue
Block a user