0

I have a script that writes colored output to the terminal via a custom module like here: Colorized Ruby output

I would like to also save this output to a file in color similar to how aha works here: A library to convert ANSI escapes (terminal formatting/color codes) to HTML

How can I use Ruby to both output to the terminal in color and save to a file in color in html or some other markup that's easily read by non-developers.

HarlemSquirrel
  • 8,966
  • 5
  • 34
  • 34
  • You could use [`tee`](https://en.wikipedia.org/wiki/Tee_(command)) to write the script's output to both, stdout and a file and convert the file afterwards as needed (e.g. via `aha`) – Stefan Sep 11 '17 at 16:08
  • I was thinking about this but how could `tee` retain the colors? – HarlemSquirrel Sep 11 '17 at 17:51
  • Those colors are just sequences of character that are interpreted by your terminal. Just like `"\n"` – it is interpreted as a newline, but can nonetheless be written to a file. – Stefan Sep 12 '17 at 07:18

0 Answers0