Skip to content

Commit 03b7aff

Browse files
authored
feat: change color enabled to color disabled (#38)
1 parent 42d280f commit 03b7aff

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

integration/gps_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ func TestGPS(t *testing.T) {
5858
{"bisect", []string{"--config=NONE"}, "\x1b[34m \ue0a0 main|BISECTING ↓[1]\x1b[0m", nil},
5959

6060
// formatting
61-
{"clean", []string{"--config=NONE", "--color-enabled=false"}, " \ue0a0 main", nil},
62-
{"clean", []string{"--config=NONE", "--color-enabled=false", "--prompt-prefix= start "}, " start main", nil},
63-
{"clean", []string{"--config=NONE", "--color-enabled=false", "--prompt-suffix= stop"}, " \ue0a0 main stop", nil},
64-
{"conflict_ahead", []string{"--config=NONE", "--color-enabled=false", "--ahead-format=ahead by %d"}, " \ue0a0 main ahead by 1", nil},
65-
{"conflict_behind", []string{"--config=NONE", "--color-enabled=false", "--behind-format=behind by %d"}, " \ue0a0 main behind by 1", nil},
66-
{"conflict_diverged", []string{"--config=NONE", "--color-enabled=false", "--diverged-format=ahead by %d behind by %d"}, " \ue0a0 main ahead by 1 behind by 1", nil},
67-
{"no_upstream_remote", []string{"--config=NONE", "--color-enabled=false", "--no-upstream-remote-format= upstream=[repo: %s branch: %s]"}, " \ue0a0 main upstream=[repo: mikesmithgh/test branch: main]", nil},
61+
{"clean", []string{"--config=NONE", "--color-disabled"}, " \ue0a0 main", nil},
62+
{"clean", []string{"--config=NONE", "--color-disabled", "--prompt-prefix= start "}, " start main", nil},
63+
{"clean", []string{"--config=NONE", "--color-disabled", "--prompt-suffix= stop"}, " \ue0a0 main stop", nil},
64+
{"conflict_ahead", []string{"--config=NONE", "--color-disabled", "--ahead-format=ahead by %d"}, " \ue0a0 main ahead by 1", nil},
65+
{"conflict_behind", []string{"--config=NONE", "--color-disabled", "--behind-format=behind by %d"}, " \ue0a0 main behind by 1", nil},
66+
{"conflict_diverged", []string{"--config=NONE", "--color-disabled", "--diverged-format=ahead by %d behind by %d"}, " \ue0a0 main ahead by 1 behind by 1", nil},
67+
{"no_upstream_remote", []string{"--config=NONE", "--color-disabled", "--no-upstream-remote-format= upstream=[repo: %s branch: %s]"}, " \ue0a0 main upstream=[repo: mikesmithgh/test branch: main]", nil},
6868

6969
// color overrides
7070
{"clean", []string{"--config=../configs/color_overrides.toml"}, "\x1b[38;2;230;238;4m \ue0a0 main\x1b[0m", nil},

main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"path"
88
"runtime"
9+
"strconv"
910
"strings"
1011

1112
"github.com/mikesmithgh/git-prompt-string/pkg/color"
@@ -26,7 +27,7 @@ var (
2627
behindFormat = flag.String("behind-format", "↓[%d]", "")
2728
divergedFormat = flag.String("diverged-format", "↕ ↑[%d] ↓[%d]", "")
2829
noUpstreamRemoteFormat = flag.String("no-upstream-remote-format", " → %s/%s", "")
29-
colorEnabled = flag.Bool("color-enabled", true, "")
30+
colorDisabled = flag.Bool("color-disabled", false, "disable all color in prompt string")
3031
colorClean = flag.String("color-clean", "green", "")
3132
colorConflict = flag.String("color-conflict", "yellow", "")
3233
colorDirty = flag.String("color-dirty", "red", "")
@@ -44,7 +45,7 @@ func main() {
4445
BehindFormat: *behindFormat,
4546
DivergedFormat: *divergedFormat,
4647
NoUpstreamRemoteFormat: *noUpstreamRemoteFormat,
47-
ColorEnabled: *colorEnabled,
48+
ColorDisabled: *colorDisabled,
4849
ColorClean: *colorClean,
4950
ColorConflict: *colorConflict,
5051
ColorDirty: *colorDirty,
@@ -108,8 +109,12 @@ func main() {
108109
cfg.DivergedFormat = f.Value.String()
109110
case "no-upstream-remote-format":
110111
cfg.NoUpstreamRemoteFormat = f.Value.String()
111-
case "color-enabled":
112-
cfg.ColorEnabled = f.Value.String() == f.DefValue
112+
case "color-disabled":
113+
colorDisabled, err := strconv.ParseBool(f.Value.String())
114+
if err != nil {
115+
util.ErrMsg("parse color disabled", err, 0)
116+
}
117+
cfg.ColorDisabled = colorDisabled
113118
case "color-clean":
114119
cfg.ColorClean = f.Value.String()
115120
case "color-conflict":
@@ -125,7 +130,7 @@ func main() {
125130
}
126131
})
127132

128-
if !cfg.ColorEnabled {
133+
if cfg.ColorDisabled {
129134
color.Disable()
130135
}
131136

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type GPSConfig struct {
77
BehindFormat string `toml:"behind_format"`
88
DivergedFormat string `toml:"diverged_format"`
99
NoUpstreamRemoteFormat string `toml:"no_upstream_remote_format"`
10-
ColorEnabled bool `toml:"color_enabled"`
10+
ColorDisabled bool `toml:"color_disabled"`
1111
ColorClean string `toml:"color_clean"`
1212
ColorConflict string `toml:"color_conflict"`
1313
ColorDirty string `toml:"color_dirty"`

0 commit comments

Comments
 (0)