humanlogio/humanlog

Humanlog colors not configurable, and assume dark background

samv opened this issue · 3 comments

samv commented

The default colors don't work for me:

screen shot 2016-08-03 at 4 30 08 pm

Due to the way that the underlying rgbterm works, I can't just send a quick \033[40m to set the background color to dark; it only works for the first colored block printed, and then a SGR reset kills that.

It's possible to set the default background color, but it's very terminal dependent, and so my wrapper function for Scanner is getting really ugly:

func ScannerDarkly(src io.Reader, dst io.Writer, opts *humanlog.HandlerOptions) {
    var setBgColorCode string
    if strings.Contains(os.Getenv("TERM_PROGRAM"), "iTerm") {
        // iTerm...
        setBgColorCode = "\033]Ph%.2x%.2x%.2x\033\\"
    } else if strings.Contains(os.Getenv("TERM"), "256") || strings.Contains(os.Getenv("TERM"), "xterm") {
        setBgColorCode = "\033]6;rgb:%.2x/%.2x/%.2x\a"
    }
    if setBgColorCode != "" {
        dst.Write([]byte(fmt.Sprintf(setBgColorCode, bgColor[0], bgColor[1], bgColor[2])))
    }
    humanlog.Scanner(src, dst, opts)
}

I'm not cleaning up the color change, either, so when my program quits it leaves the background dark. Do you think it would be possible to make the code accept some kind of color palette configuration or something (perhaps with regular ANSI code fallbacks), instead of all of the hardcoded color codes?

You're right! If you have an idea of an implementation that would address this, I'll be happy to check it!

Looks bad on my dark background:

screen_2017-10-18-21 08 38

What do you think about using the 16-color palette instead of RGB? Terminal themes usually coordinate the colors to look good on the background, RGB just skips the theme.

@myfreeweb sounds like a good idea, i'd merge such a PR :)