matryer / is

Professional lightweight testing mini-framework for Go.
MIT License
1.77k stars 58 forks source link

Use ANSI dim instead of hardcoding colour #50

Closed kse closed 1 year ago

kse commented 1 year ago

Instead of hardcoding the colour for file and types, use the dim escape code to let the terminal decide the colour. Specifically this makes it more readable if your terminal happens to be slightly gray.

Also includes some gofmt edits of package comment.

flowchartsman commented 1 year ago

image Kinda mixed for me, but adaptive is certainly better than not. I'd be inclined to take it a step further and integrate the xterm Operating System Commands OSC 10 ; ? BEL and/or OSC 11 ; ? BEL for color selection. Could be part of a larger effort since, AFAICT Windows terminal colors aren't handled (but I haven't tested).

Still, not a reason to kill the PR or anything, however I think I'd prefer the format changes be either all or none and keep gofmt stuff to a separate PR.

matryer commented 1 year ago

Thanks @flowchartsman

kse commented 1 year ago

Thanks for approving and sorry for not getting back to you before flowchartsman. :) Kids, sparetime and all.

matryer commented 1 year ago

thanks @kse - what do you think about his previous comment?

kse commented 1 year ago

I admittedly know nothing about the xterm OS commands. The only color set right now is (dark) red. I think this color is legible enough on both a black-ish or white-ish background to not be an issue. There are of course red-green color blind people, but I think the contrast is likely clear enough in any case.

An alternative to a color is of course bold, which is the only proper alternative IMO.

echo -e "\u001b[01m Hello world\u001b[00m in bold"

Based on the (rather excellent) wikipedia article, the ANSI codes should work on some (modern) Windows Terminal as well (though not Windows Console). But I suspect most developers would use Terminal or some Linux shell through WSL.

(I only have Linux to test on).

TL;DR

I think this is a good improvement and we don't need to dynamically figure out the colour of the comment.

flowchartsman commented 1 year ago

I'm not familiar with Windows these days, but if the ANSI codes work on Windows Terminal, I think that's good enough for me to cap it here and not to bother with anything fancier. I also agree that bold is a great option, and might be worth considering elsewhere or in place of dim. In any case, probably good as it is unless someone complains. Thanks for the work!