Skip to content

Commit 970d6b4

Browse files
author
Andrei
committed
Add colors
1 parent cf4c717 commit 970d6b4

File tree

8 files changed

+50
-13
lines changed

8 files changed

+50
-13
lines changed

cmd/link.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77

8+
"github.com/fatih/color"
89
"github.com/spf13/cobra"
910
"github.com/itzcodex24/git-guardian/internal/state"
1011
)
@@ -35,7 +36,7 @@ var linkCmd = &cobra.Command{
3536
return fmt.Errorf("failed to link folder: %w", err)
3637
}
3738

38-
fmt.Println("Linked folder:", absPath)
39+
color.Green("✓ Linked folder: %s", absPath)
3940
return nil
4041
},
4142
}

cmd/listeners.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/fatih/color"
78
"github.com/spf13/cobra"
89
"github.com/itzcodex24/git-guardian/internal/supervisor"
910
)
@@ -13,20 +14,36 @@ var listenersCmd = &cobra.Command{
1314
Short: "List all configured watchers",
1415
RunE: func(cmd *cobra.Command, args []string) error {
1516
list := supervisor.List()
16-
fmt.Printf("\n%-8s %-15s %-38s %-10s %-25s\n", "ID", "Mode", "Folder", "Status", "LastRun")
17-
fmt.Println(strings.Repeat("-", 110))
17+
18+
cyan := color.New(color.FgCyan, color.Bold)
19+
fmt.Println()
20+
cyan.Printf("%-8s %-15s %-38s %-10s %-25s\n", "ID", "Mode", "Folder", "Status", "LastRun")
21+
color.Cyan(strings.Repeat("─", 110))
22+
1823
for _, w := range list {
19-
status := "paused"
24+
statusColor := color.New(color.FgYellow)
25+
statusText := "paused"
2026
if !w.Paused {
21-
status = "running"
27+
statusColor = color.New(color.FgGreen)
28+
statusText = "running"
2229
}
30+
2331
mode := w.Mode
32+
modeColor := color.New(color.FgWhite)
2433
if w.Mode == "interval" && w.Interval != "" {
2534
mode = fmt.Sprintf("interval (%s)", w.Interval)
35+
modeColor = color.New(color.FgMagenta)
2636
} else if w.Mode == "watch" && w.Debounce != "" {
2737
mode = fmt.Sprintf("watch (%s)", w.Debounce)
38+
modeColor = color.New(color.FgBlue)
2839
}
29-
fmt.Printf("%-8s %-15s %-38s %-10s %-25s\n", w.ID, mode, w.Folder, status, w.LastRun)
40+
41+
idColor := color.New(color.FgHiWhite, color.Bold)
42+
idColor.Printf("%-8s ", w.ID)
43+
modeColor.Printf("%-15s ", mode)
44+
fmt.Printf("%-38s ", w.Folder)
45+
statusColor.Printf("%-10s ", statusText)
46+
color.New(color.FgHiBlack).Printf("%-25s\n", w.LastRun)
3047
}
3148
return nil
3249
},

cmd/pause.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55

6+
"github.com/fatih/color"
67
"github.com/spf13/cobra"
78
"github.com/itzcodex24/git-guardian/internal/supervisor"
89
)
@@ -16,7 +17,7 @@ var pauseCmd = &cobra.Command{
1617
if err := supervisor.Pause(id); err != nil {
1718
return fmt.Errorf("pause failed: %w", err)
1819
}
19-
fmt.Println("Paused:", id)
20+
color.Yellow("⏸ Paused: %s", id)
2021
return nil
2122
},
2223
}

cmd/remove.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55

6+
"github.com/fatih/color"
67
"github.com/spf13/cobra"
78
"github.com/itzcodex24/git-guardian/internal/supervisor"
89
)
@@ -16,7 +17,7 @@ var removeCmd = &cobra.Command{
1617
if err := supervisor.Remove(id); err != nil {
1718
return fmt.Errorf("remove failed: %w", err)
1819
}
19-
fmt.Println("Removed:", id)
20+
color.Red("✗ Removed: %s", id)
2021
return nil
2122
},
2223
}

cmd/resume.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55

6+
"github.com/fatih/color"
67
"github.com/spf13/cobra"
78
"github.com/itzcodex24/git-guardian/internal/supervisor"
89
)
@@ -16,7 +17,7 @@ var resumeCmd = &cobra.Command{
1617
if err := supervisor.Resume(id); err != nil {
1718
return fmt.Errorf("resume failed: %w", err)
1819
}
19-
fmt.Println("Resumed:", id)
20+
color.Green("▶ Resumed: %s", id)
2021
return nil
2122
},
2223
}

cmd/start.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"path/filepath"
66

7+
"github.com/fatih/color"
78
"github.com/spf13/cobra"
89
"github.com/itzcodex24/git-guardian/internal/state"
910
)
@@ -40,7 +41,7 @@ var startCmd = &cobra.Command{
4041
}
4142
list[i].Paused = false
4243
state.Update(list)
43-
fmt.Println("Watcher activated for:", absPath)
44+
color.Green("✓ Watcher activated for: %s", absPath)
4445
return nil
4546
}
4647
}

go.mod

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ require (
1111
)
1212

1313
require (
14-
github.com/inconshreveable/mousetrap v1.1.0
15-
github.com/spf13/pflag v1.0.10
16-
golang.org/x/sys v0.38.0
14+
github.com/inconshreveable/mousetrap v1.1.0
15+
github.com/spf13/pflag v1.0.10
16+
golang.org/x/sys v0.38.0
17+
)
18+
19+
require (
20+
github.com/fatih/color v1.18.0 // indirect
21+
github.com/mattn/go-colorable v0.1.13 // indirect
22+
github.com/mattn/go-isatty v0.0.20 // indirect
1723
)

go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
22
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
3+
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
4+
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
35
github.com/fsnotify/fsnotify v1.5.2/go.mod h1:VKyWoa5earkjWzuYFJOy3s0DLrlWgSh5nf5hjFuJcAw=
46
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
57
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
@@ -8,6 +10,11 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
810
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
911
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
1012
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
13+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
14+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
15+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
16+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
17+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
1118
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
1219
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
1320
github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s=
@@ -18,6 +25,8 @@ github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
1825
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
1926
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
2027
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
28+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
29+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2130
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
2231
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2332
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=

0 commit comments

Comments
 (0)