Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can force color output even not in console #124

Open
HR1025 opened this issue Sep 24, 2024 · 0 comments
Open

Can force color output even not in console #124

HR1025 opened this issue Sep 24, 2024 · 0 comments

Comments

@HR1025
Copy link

HR1025 commented Sep 24, 2024

Hi, tabulate is a very useful tool, and I really like the feature of tabulate that supports colored output.

I noticed a phenomenon with the following test code:

int main() {
  Table movies;
  movies.add_row({"S/N", "Movie Name", "Director", "Estimated Budget", "Release Date"});
  movies.add_row({"tt1979376", "Toy Story 4", "Josh Cooley", "$200,000,000", "21 June 2019"});
  movies.add_row({"tt3263904", "Sully", "Clint Eastwood", "$60,000,000", "9 September 2016"});
  movies.add_row({"tt1535109", "Captain Phillips", "Paul Greengrass", "$55,000,000", " 11 October 2013"});

  // center align 'Director' column
  movies.column(2).format()
    .font_align(FontAlign::center);

  // right align 'Estimated Budget' column
  movies.column(3).format()
    .font_align(FontAlign::right);

  // right align 'Release Date' column
  movies.column(4).format()
    .font_align(FontAlign::right);

  // center-align and color header cells
  for (size_t i = 0; i < 5; ++i) {
    movies[0][i].format()
      .font_color(Color::yellow)
      .font_align(FontAlign::center)
      .font_style({FontStyle::bold});
  }

  std::cout << movies.str() << std::endl;
  std::cout << movies << std::endl;
}

The first print is without color, and the second print is with color.

After checking the code, it seems to be related to the is_colorized interface, which enables colored printing only when outputting to the console.

I understand the intention behind this design, but could add a user option to control this behavior separately? There are scenarios where we might want to retain colored printing even when not outputting to the console. For example, in my case:
I plan to use tabulate to create a remote shell, where the remote print information is transmitted to the local machine via a socket and then printed locally. So, I use .str() to get the text data, but the color information is lost when printing locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant