-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_change.go
More file actions
70 lines (64 loc) · 1.38 KB
/
git_change.go
File metadata and controls
70 lines (64 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"os"
"path"
)
type GitChange_t string
const (
Add GitChange_t = "#99FF33"
Modify GitChange_t = "#FFFF66"
Delete GitChange_t = "#FF0000"
)
type GitStatusItem struct {
staged bool
change GitChange_t
file string
}
func (gsi GitStatusItem) Drawio(id, x, y int) string {
staged := ""
if gsi.staged {
staged = "arcSize=50;"
}
return fmt.Sprintf(`
<mxCell id="%d" value="%s" style="rounded=1;whiteSpace=wrap;html=1;strokeColor=%s;%s" parent="1" vertex="1">
<mxGeometry x="%d" y="%d" width="120" height="60" as="geometry"/>
</mxCell>
`, id, path.Base(gsi.file), gsi.change, staged, x, y)
}
func GitStatusItem_New(s string) GitStatusItem {
file := s[3:]
if s[0] == '?' {
return GitStatusItem{false, Add, file}
}
var staged bool
var change GitChange_t
if s[0] == ' ' {
staged = false
switch s[1] {
case 'M':
change = Modify
case 'D':
change = Delete
default:
fmt.Println("Unrecognized git change:")
fmt.Println(s)
os.Exit(1)
}
} else {
staged = true
switch s[0] {
case 'A':
change = Add
case 'M':
change = Modify
case 'D':
change = Delete
default:
fmt.Println("Unrecognized git change:")
fmt.Println(s)
os.Exit(1)
}
}
return GitStatusItem{staged, change, file}
}