Skip to content

Commit 4d60bf5

Browse files
authored
feat: report in color with env var CI and FORCE_COLOR (#16)
closes oxc-project/oxc#9790
1 parent 5b6003b commit 4d60bf5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/handlers/theme.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io::IsTerminal;
1+
use std::{env, io::IsTerminal};
22

33
use owo_colors::Style;
44

@@ -21,8 +21,16 @@ pub struct GraphicalTheme {
2121
pub styles: ThemeStyles,
2222
}
2323

24+
fn force_color() -> bool {
25+
// Assume CI can always print colors.
26+
env::var("CI").is_ok() || env::var("FORCE_COLOR").is_ok_and(|env| env != "0")
27+
}
28+
2429
impl Default for GraphicalTheme {
2530
fn default() -> Self {
31+
if force_color() {
32+
return Self::unicode();
33+
}
2634
match std::env::var("NO_COLOR") {
2735
_ if !std::io::stdout().is_terminal() || !std::io::stderr().is_terminal() => {
2836
Self::none()
@@ -35,6 +43,9 @@ impl Default for GraphicalTheme {
3543

3644
impl GraphicalTheme {
3745
pub fn new(is_terminal: bool) -> Self {
46+
if force_color() {
47+
return Self::unicode();
48+
}
3849
match std::env::var("NO_COLOR") {
3950
_ if !is_terminal => Self::none(),
4051
Ok(string) if string != "0" => Self::unicode_nocolor(),

0 commit comments

Comments
 (0)