fern icon indicating copy to clipboard operation
fern copied to clipboard

Support colored terminal output on Windows

Open daboross opened this issue 6 years ago • 3 comments

Ideally, this would be a stdout-like color output stream which parsed ANSI color codes and transformed them into the correct output on both Windows and UNIX terminals.

Crates of note:

  • https://crates.io/crates/termcolor provides a platform-agnostic colored stdout writer. The downside is each color needs to be specified via a method, it can't parse ANSI color codes passed to it.
  • https://crates.io/crates/wincolor is the backend termcolor uses on windows (we might want to just depend on this if we don't need to do anything else on linux)

Ideas for implementation:

  • We can test the functionality in fern, but it would probably be good to separate out "stream which turns ANSI color codes into windows commands" into a separate crate.
  • If we find a simpler ANSI color code only crate, we might want to remove our dependency on https://crates.io/crates/colored. We don't use very much of its functionality right now, so we'd have a lighter footprint if we switched to something which only provided ANSI codes.

daboross avatar Jan 04 '18 05:01 daboross

I've marked this "help wanted"- that's mostly because I don't have time myself to do this.

Completing this will likely require parsing ANSI color codes, writing a separate crate, publishing it, and then modifying fern. If anyone does want to do this for fern's sake, but doesn't want to maintain an entire crate after publishing it, I can (if asked) take over subsequent maintenance.

daboross avatar Jan 04 '18 05:01 daboross

I don't think it's a very good idea to keep a separate Formatter and Output in the case of colored terminal output. For non-terminals, a Formatter that includes ANSI color codes doesn't seem very useful - so the formatter function could be limited to non-terminal outputs or uncolored stdout/stderr. Instead, what I'd propose is a separate "TermColor" Output that does both the formatting and the printing to the terminal. In that case there's no need to interpret ANSI control codes and the termcolor crate can be used directly.

EDIT: In fact, I guess this can already be done right now with a custom Output::call() function.

17dec avatar Mar 04 '19 07:03 17dec

This looks like a pretty old thread, so I'm not sure if I'm stepping back in time correctly, and I also don't have an easy way to test my hypothesis on a windows machine, but I think fern may now support colored terminal output on windows due to the changes made in mackwic/colored@ebcb9c96898b1497a5c0557938e761bde34ab05f

It's possible there are still other issues described in here that aren't addressed, but I figured it was worth pointing out

CosmicHorrorDev avatar Jun 26 '21 07:06 CosmicHorrorDev