fmt::print(fg(fmt::color::blue), "Test") doesn't print colored text

91 Views Asked by At

OS: ubuntu 22.04

output of "echo $TERM": xterm-256color

fmt version: 10.2.1

The following code can print colored text:

std::cout << "\033[1;31mbold red text\033[0m" << std::endl
1

There are 1 best solutions below

0
vitaut On

fmt::color requires RGB color support which is not available on some terminals. You can use fmt::terminal_color instead which is more widely supported:

#include <fmt/color.h>

int main() {
  fmt::print(fg(fmt::terminal_color::blue), "Test");
}

Godbolt: https://www.godbolt.org/z/e1qj5K8Ys.