X Tutup
Skip to content

Commit b2de27c

Browse files
committed
Fix Survey's presentation of default values
For default values for e.g. `Input` prompts, Survey uses the literal "white" color, which makes no sense on dark terminals and is literally invisible on light backgrounds. This overrides Survey to output a gray color for 256-color terminals and "default" for basic terminals.
1 parent 88aacc1 commit b2de27c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cmd/gh/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ func main() {
4646
stderr := cmdFactory.IOStreams.ErrOut
4747
if !cmdFactory.IOStreams.ColorEnabled() {
4848
surveyCore.DisableColor = true
49+
} else {
50+
// override survey's poor choice of color
51+
surveyCore.TemplateFuncsWithColor["color"] = func(style string) string {
52+
switch style {
53+
case "white":
54+
if cmdFactory.IOStreams.ColorSupport256() {
55+
return fmt.Sprintf("\x1b[%d;5;%dm", 38, 242)
56+
}
57+
return ansi.ColorCode("default")
58+
default:
59+
return ansi.ColorCode(style)
60+
}
61+
}
4962
}
5063

5164
rootCmd := root.NewCmdRoot(cmdFactory, command.Version, command.BuildDate)

0 commit comments

Comments
 (0)
X Tutup