Skip to content

Commit 632f7a2

Browse files
committed
update
1 parent eb98658 commit 632f7a2

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

cmd/goprompt/main.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8+
"github.com/fatih/color"
89
"github.com/spf13/cobra"
910
"io"
1011
"os"
12+
"strconv"
1113
"strings"
1214
"sync"
1315
"time"
16+
17+
_ "github.com/fatih/color"
1418
)
1519

1620
var bgctx = context.Background()
@@ -58,15 +62,35 @@ func cmdRenderRun(cmd *cobra.Command, args []string) error {
5862
}
5963

6064
lines := strings.Split(string(out), "\n")
61-
vals := make(map[string]string)
65+
p := make(map[string]string)
6266
for _, line := range lines {
6367
key, value, ok := strings.Cut(line, "\t")
6468
if ok {
65-
vals[key] = value
69+
p[key] = value
70+
}
71+
}
72+
73+
var partsTop []string
74+
if p["vcs"] == "git" {
75+
gitMark := color.GreenString("git")
76+
77+
dirtyMarks := ""
78+
if p["vcs_dirty"] != "" && p["vcs_dirty"] != "0" {
79+
dirtyMarks = ":&"
80+
gitMark = color.RedString("git")
6681
}
82+
83+
distanceMarks := ""
84+
distanceAhead := strInt(p["vcs_log_ahead"])
85+
distanceBehind := strInt(p["vcs_log_ahead"])
86+
if distanceAhead > 0 || distanceBehind > 0 {
87+
distanceMarks = fmt.Sprintf(":[+%v:-%v]", distanceAhead, distanceBehind)
88+
}
89+
90+
partsTop = append(partsTop, fmt.Sprintf("{%v:%v%v%v}", gitMark, p["vcs_br"], dirtyMarks, distanceMarks))
6791
}
6892

69-
fmt.Printf("%#v\n", vals)
93+
fmt.Println("::", strings.Join(partsTop, " "))
7094
fmt.Printf(">")
7195
return nil
7296
}
@@ -291,3 +315,8 @@ func intMin(a, b int) int {
291315
func trim(s string) string {
292316
return strings.Trim(s, "\n\t ")
293317
}
318+
319+
func strInt(s string) int {
320+
r, _ := strconv.Atoi(s)
321+
return r
322+
}

0 commit comments

Comments
 (0)