mandiant / capa

The FLARE team's open-source tool to identify capabilities in executable files.
https://mandiant.github.io/capa/
Apache License 2.0
4.13k stars 517 forks source link

dynamic: -vv API details hard to see (color) #1865

Open mr-tz opened 10 months ago

mr-tz commented 10 months ago

image

can we configure / use colors that are (always) good to see?

williballenthin commented 10 months ago

We color the output using the 16 named ANSI colors here: https://github.com/mandiant/capa/pull/1697/files#diff-fe1c2d3620e13ab3bc93755b55f86a8a561bbb45000da79a1b31de56fb40cde6R29

def bold(s: str) -> str:
    """draw attention to the given string"""
    return termcolor.colored(s, "cyan")

def bold2(s: str) -> str:
    """draw attention to the given string, within a `bold` section"""
    return termcolor.colored(s, "green")

def mute(s: str) -> str:
    """draw attention away from the given string"""
    return termcolor.colored(s, "dark_grey")

def warn(s: str) -> str:
    return termcolor.colored(s, "yellow")

So, we don't pick a specific RGB color (since this might conflict with a user's theme). Rather, we use these named colors so that themes can provide a reasonable set of values that work well together. When they don't, like above, there's not too much we can do.

Alternatives:

  1. use hardcoded RGB colors, which gives us perfect control over colors, but won't work well with background colors (which we can't query/inspect).
  2. override the background color so we have control, but will make output distinct from the rest of the terminal.
  3. don't use colors (unfortunate).
  4. use other named colors.

For (4) we could use, e.g., light_grey instead of dark_grey and see if that looks better. We'd have to sample a bunch of themes and configurations to see what worked most consistently. I think we would give the most weight to default terminal settings (like freshly installed Windows Terminal, Gnome Terminal, etc.).

I wonder if we can find any published resources on how to use terminal colors in a consistent and portable way. Like, "use ANSI yellow to do this, and ANSI grey to do that".

williballenthin commented 10 months ago

show color theme colors:

https://github.com/termcolor/termcolor/blob/main/src/termcolor/__main__.py

williballenthin commented 10 months ago

default gnome:

image

williballenthin commented 10 months ago

default gnome light: image

williballenthin commented 10 months ago

tango dark: image

williballenthin commented 10 months ago

solarized dark:

image

williballenthin commented 10 months ago

gnome black on light yellow: image

williballenthin commented 10 months ago

edit: in the surrounding analysis i was only changing the "Text and Background Color" which doesn't include the colors of the characters. So even this isn't correct, for example, here is Solarized on Solarized, and note how the "light" variants aren't even colored!

image

This also makes clear that Solarized maps "dark grey" to the same color as the background, so its totally invisible.

So, who knows?!?

Maybe normal red/green/yellow/magenta/cyan are most safe, with no good option for "mute".


(original content):

in summary:

image

my opinion for if we should use the following colors:

for the "ok" colors, generally prefer the "light" variants, because they "pop" more for highlights.

i don't see a great option for "mute". dark grey seems ok, but the original issue text shows a pretty bad case. mabye its a bug with that theme's implementation? what do you all think?

mr-tz commented 10 months ago

Wow, thanks, that's a good overview.

I agree that we can highlight things fairly reliably but muting isn't ideal. So maybe we don't mute for now / in the CLI.

And preferably, we use red/yellow only for warnings/errors.