Skip to content

Commit

Permalink
feat: change color enabled to color disabled (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesmithgh authored Mar 22, 2024
1 parent 42d280f commit 03b7aff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
14 changes: 7 additions & 7 deletions integration/gps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func TestGPS(t *testing.T) {
{"bisect", []string{"--config=NONE"}, "\x1b[34m \ue0a0 main|BISECTING ↓[1]\x1b[0m", nil},

// formatting
{"clean", []string{"--config=NONE", "--color-enabled=false"}, " \ue0a0 main", nil},
{"clean", []string{"--config=NONE", "--color-enabled=false", "--prompt-prefix= start "}, " start main", nil},
{"clean", []string{"--config=NONE", "--color-enabled=false", "--prompt-suffix= stop"}, " \ue0a0 main stop", nil},
{"conflict_ahead", []string{"--config=NONE", "--color-enabled=false", "--ahead-format=ahead by %d"}, " \ue0a0 main ahead by 1", nil},
{"conflict_behind", []string{"--config=NONE", "--color-enabled=false", "--behind-format=behind by %d"}, " \ue0a0 main behind by 1", nil},
{"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},
{"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},
{"clean", []string{"--config=NONE", "--color-disabled"}, " \ue0a0 main", nil},
{"clean", []string{"--config=NONE", "--color-disabled", "--prompt-prefix= start "}, " start main", nil},
{"clean", []string{"--config=NONE", "--color-disabled", "--prompt-suffix= stop"}, " \ue0a0 main stop", nil},
{"conflict_ahead", []string{"--config=NONE", "--color-disabled", "--ahead-format=ahead by %d"}, " \ue0a0 main ahead by 1", nil},
{"conflict_behind", []string{"--config=NONE", "--color-disabled", "--behind-format=behind by %d"}, " \ue0a0 main behind by 1", nil},
{"conflict_diverged", []string{"--config=NONE", "--color-disabled", "--diverged-format=ahead by %d behind by %d"}, " \ue0a0 main ahead by 1 behind by 1", nil},
{"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},

// color overrides
{"clean", []string{"--config=../configs/color_overrides.toml"}, "\x1b[38;2;230;238;4m \ue0a0 main\x1b[0m", nil},
Expand Down
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path"
"runtime"
"strconv"
"strings"

"github.com/mikesmithgh/git-prompt-string/pkg/color"
Expand All @@ -26,7 +27,7 @@ var (
behindFormat = flag.String("behind-format", "↓[%d]", "")
divergedFormat = flag.String("diverged-format", "↕ ↑[%d] ↓[%d]", "")
noUpstreamRemoteFormat = flag.String("no-upstream-remote-format", " → %s/%s", "")
colorEnabled = flag.Bool("color-enabled", true, "")
colorDisabled = flag.Bool("color-disabled", false, "disable all color in prompt string")
colorClean = flag.String("color-clean", "green", "")
colorConflict = flag.String("color-conflict", "yellow", "")
colorDirty = flag.String("color-dirty", "red", "")
Expand All @@ -44,7 +45,7 @@ func main() {
BehindFormat: *behindFormat,
DivergedFormat: *divergedFormat,
NoUpstreamRemoteFormat: *noUpstreamRemoteFormat,
ColorEnabled: *colorEnabled,
ColorDisabled: *colorDisabled,
ColorClean: *colorClean,
ColorConflict: *colorConflict,
ColorDirty: *colorDirty,
Expand Down Expand Up @@ -108,8 +109,12 @@ func main() {
cfg.DivergedFormat = f.Value.String()
case "no-upstream-remote-format":
cfg.NoUpstreamRemoteFormat = f.Value.String()
case "color-enabled":
cfg.ColorEnabled = f.Value.String() == f.DefValue
case "color-disabled":
colorDisabled, err := strconv.ParseBool(f.Value.String())
if err != nil {
util.ErrMsg("parse color disabled", err, 0)
}
cfg.ColorDisabled = colorDisabled
case "color-clean":
cfg.ColorClean = f.Value.String()
case "color-conflict":
Expand All @@ -125,7 +130,7 @@ func main() {
}
})

if !cfg.ColorEnabled {
if cfg.ColorDisabled {
color.Disable()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type GPSConfig struct {
BehindFormat string `toml:"behind_format"`
DivergedFormat string `toml:"diverged_format"`
NoUpstreamRemoteFormat string `toml:"no_upstream_remote_format"`
ColorEnabled bool `toml:"color_enabled"`
ColorDisabled bool `toml:"color_disabled"`
ColorClean string `toml:"color_clean"`
ColorConflict string `toml:"color_conflict"`
ColorDirty string `toml:"color_dirty"`
Expand Down

0 comments on commit 03b7aff

Please sign in to comment.