colored-rs/colored

Enable Colors on Mac Terminal

joshzeldin opened this issue · 7 comments

I'm struggling to get colors working on Mac OS (Catalina) when running through Terminal. I can get other CLIs with colors to display (e.g. ls, git, etc.), but colors coming from the colored package don't show up.

image

If I run the same thing through VS Code's terminal, the colors do show up.

image

Are you aware of any settings I need play with to get this working or limitations of the default terminal? I have tried these with no luck:

  • CLICOLOR
  • CLICOLOR_FORCE
  • NO_COLOR

I'm using the following:

[dependencies]
colored = "2.0.0"

Thanks and I'm really enjoying the crate!

Also running MacOS Catalina, is working smoothly for me in terminal. Is it possible that your terminal profile has the ANSI colour setting turned off?

Same issue on Windows, any luck so far?

@Dot32IsCool ANSI color is enabled under preferences. Thanks for the tip though.
@grtcdr Unfortunately no luck.

Thanks for the update @joshzeldin

Hi everyone,

Using this stackoverflow answer, I want what does the following script print ?

curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/ | bash

For me, the "s".truecolor() methods do not work as expected on macOS Terminal, but the color-specific methods (e.g., "s".green()) work perfectly. As has been mentioned, in the VSCode terminal, everything works across the board as far as I can tell.

I seem to be in the same situation as usefulmove.

Here is the output for that colors script:
Screen Shot 2022-09-13 at 3 25 54 PM

And here is a demonstration of this crate's output for my terminal:
Screen Shot 2022-09-13 at 3 25 10 PM

Code for the above:

use colored::*;

fn main() {
    println!("{}", "black".black());
    println!("{}", "bright_black".bright_black());
    println!("{}", "red".red());
    println!("{}", "bright_red".bright_red());
    println!("{}", "green".green());
    println!("{}", "bright_green".bright_green());
    println!("{}", "yellow".yellow());
    println!("{}", "bright_yellow".bright_yellow());
    println!("{}", "truecolor_247,246,28".truecolor(247, 246, 28));
    println!("{}", "blue".blue());
    println!("{}", "bright_blue".bright_blue());
    println!("{}", "magenta".magenta());
    println!("{}", "bright_magenta".bright_magenta());
    println!("{}", "truecolor_255,76,255".truecolor(255, 76, 255));
    println!("{}", "purple".purple());
    println!("{}", "bright_purple".bright_purple());
    println!("{}", "cyan".cyan());
    println!("{}", "bright_cyan".bright_cyan());
    println!("{}", "white".white());
    println!("{}", "bright_white".bright_white());
    println!("{}", "truecolor_255,255,255".truecolor(255, 255, 255));
}

It looks like the 38;2;r;g;b syntax doesn't work for Terminal because it uses xterm-256color, i.e. it doesn't support truecolor. For reference, this script appears to work.