@@ -5,12 +5,16 @@ import (
5
5
"context"
6
6
"encoding/json"
7
7
"fmt"
8
+ "github.com/fatih/color"
8
9
"github.com/spf13/cobra"
9
10
"io"
10
11
"os"
12
+ "strconv"
11
13
"strings"
12
14
"sync"
13
15
"time"
16
+
17
+ _ "github.com/fatih/color"
14
18
)
15
19
16
20
var bgctx = context .Background ()
@@ -58,15 +62,35 @@ func cmdRenderRun(cmd *cobra.Command, args []string) error {
58
62
}
59
63
60
64
lines := strings .Split (string (out ), "\n " )
61
- vals := make (map [string ]string )
65
+ p := make (map [string ]string )
62
66
for _ , line := range lines {
63
67
key , value , ok := strings .Cut (line , "\t " )
64
68
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" )
66
81
}
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 ))
67
91
}
68
92
69
- fmt .Printf ( "%#v \n " , vals )
93
+ fmt .Println ( ":: " , strings . Join ( partsTop , " " ) )
70
94
fmt .Printf (">" )
71
95
return nil
72
96
}
@@ -291,3 +315,8 @@ func intMin(a, b int) int {
291
315
func trim (s string ) string {
292
316
return strings .Trim (s , "\n \t " )
293
317
}
318
+
319
+ func strInt (s string ) int {
320
+ r , _ := strconv .Atoi (s )
321
+ return r
322
+ }
0 commit comments