mroth / scmpuff

:1234: Numeric file shortcuts for common git commands
https://mroth.github.io/scmpuff/
MIT License
384 stars 23 forks source link

scmpuff status: migrate hardcoded ANSI color codes to a cross-platform color library #28

Open mroth opened 7 years ago

mroth commented 7 years ago

This will improve cross-platform support for future shells, and also hopefully allow the code to become more clean and understandable. As @stereokai showed in #14, currently Windows in PowerShell does not properly render the ANSI escape codes as color.

There is likely a strong chance to refactor and clean up the UI formatting code with this too, which is worth being opportunistic with if it presents itself.

Some of the color libraries seem to have the built in ability to disable color output entirely in a convenient way without branching all the UI code (fatih/color), which could be a nice command line switch to add to scmpuff status if easy enough to do cleanly.

stereokai commented 7 years ago

I actually used something really simple for the FPrint() methods: https://github.com/mattn/go-colorable

It only took changing from os.Stdout to NewColorableStdout() for example, and that made scmpuff status work in both CMD and Powershell.

mrcljx commented 7 years ago

Maybe we could just use git's internals for this? Would allow configuration as well (we'd have to provide default colors though which we probably have to pull out of the git codebase):

git config --get-color color.status.added 'red'

From man:

       --get-colorbool name [stdout-is-tty]
           Find the color setting for name (e.g.  color.diff) and output "true" or "false".  stdout-is-tty should be either "true" or
           "false", and is taken into account when configuration says "auto". If stdout-is-tty is missing, then checks the standard
           output of the command itself, and exits with status 0 if color is to be used, or exits with status 1 otherwise. When the color
           setting for name is undefined, the command uses color.ui as fallback.

       --get-color name [default]
           List all variables set in config file, along with their values.

Would probably also fix #9