AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.08k stars 351 forks source link

Y/n is not visible on terminal with white background #258

Open prabhu43 opened 4 years ago

prabhu43 commented 4 years ago
Screenshot 2019-10-31 at 12 52 39 PM

The white text of Y/n makes it difficult to read on a white background.

AlecAivazis commented 4 years ago

Hey @prabhu43!

Yea that's true. But darker text would have the same problem on a white terminal, right? Do you have a proposed solution? I don't know what we could do unless you know of some magic way to detect the background color on a terminal that works in all of the environments survey support.

AlecAivazis commented 4 years ago

I'm going to close this since you haven't replied in a few months @prabhu43. Feel free to comment here if you have a proposal

chris-morgan commented 1 year ago

This is still a bug. In the terminal colour scheme I’ve made and use (and which there is nothing wrong with), the text is completely invisible (#fff on #fff).

Unless you have actively checked the exact terminal colours (which you can only sometimes do, and which is I think generally inadvisable anyway), never pair colours 0, 7, 8 or 15 (black, white, bright black, bright white) with the default foreground or background colour, because they can all be any contrast, from maximum possible down to zero. (11, 14 and 4 are also unsuitable for general use, and 10 and 12 are dubious, and https://github.com/PowerShell/PowerShell/issues/4266 even makes 5 catastrophic in one now-rare scenario. Seriously, compatible defaults should stick to only modifying foregrounds and only using the default foreground colour and colours 1, 2, 3, 5 and 6.)

For this case: the solution is to stop applying a colour to the “(Y/n)” thing; let it be the default colour. You could try SGR 2 (faint), but I wouldn’t bother. (And just in case my previous paragraph gave you any ideas about setting background colours so as to ensure sufficient contrast: don’t do that either, it’s bad manners at best and generally a terrible idea.)

mislav commented 1 year ago

I'm going to reopen since we had to work around this in GitHub CLI:

import surveyCore "github.com/AlecAivazis/survey/v2/core"
import "github.com/mgutz/ansi"

// override survey's poor choice of color
surveyCore.TemplateFuncsWithColor["color"] = func(style string) string {
    switch style {
    case "white":
        if colorSupport256() {
            return fmt.Sprintf("\x1b[%d;5;%dm", 38, 242)
        }
        return ansi.ColorCode("default")
    default:
        return ansi.ColorCode(style)
    }
}