-
Notifications
You must be signed in to change notification settings - Fork 18
/
ui_commit_committing.go
131 lines (114 loc) · 3.56 KB
/
ui_commit_committing.go
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"time"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var (
committingStyle = lipgloss.NewStyle().
Padding(1, 1, 1, 2)
committingTypeStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"}).
Background(lipgloss.AdaptiveColor{Light: "#5B44FF", Dark: "#7653FF"})
committingScopeStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"}).
Background(lipgloss.AdaptiveColor{Light: "#1FD314", Dark: "#2AD67F"})
committingSubjectStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"}).
Background(lipgloss.AdaptiveColor{Light: "#E11C9C", Dark: "#EE6FF8"})
committingBodyStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.AdaptiveColor{Light: "#25A065", Dark: "#2AD67F"})
committingFooterStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.AdaptiveColor{Light: "#25A065", Dark: "#2AD67F"})
committingSuccessStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.AdaptiveColor{Light: "#25A065", Dark: "#2AD67F"})
committingFailedStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.AdaptiveColor{Light: "#D63B3A", Dark: "#D63B3A"})
)
type committingModel struct {
err error
done bool
msg commitMsg
spinner spinner.Model
}
func newCommittingModel() committingModel {
s := spinner.NewModel()
s.Spinner = spinner.Spinner{
Frames: []string{
"(● ) C",
"( ● ) Co",
"( ● ) Com",
"( ● ) Comm",
"( ●) Commi",
"( ●) Commit",
"( ● ) Committ",
"( ● ) Committi",
"( ● ) Committin",
"(● ) Committing",
"( ● ) Committing.",
"( ● ) Committing..",
"( ● ) Committing...",
"( ●) Committing...",
"( ● ) Committing...",
"( ● ) Committing...",
"( ● ) Committing...",
"(● ) Committing...",
},
FPS: time.Second / 15,
}
s.Style = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#25A065", Dark: "#19F896"}).Bold(true)
return committingModel{spinner: s}
}
func (m committingModel) Init() tea.Cmd {
return nil
}
func (m committingModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "esc":
return m, tea.Quit
default:
return m, nil
}
case commitMsg:
m.msg = msg
return m, func() tea.Msg {
time.Sleep(time.Second)
return commit(msg)
}
case error:
m.done = true
m.err = msg
return m, tea.Quit
case nil:
m.done = true
return m, tea.Quit
default:
var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg)
return m, cmd
}
}
func (m committingModel) View() string {
header := committingTypeStyle.Render(m.msg.Type) + committingScopeStyle.Render("("+m.msg.Scope+")") + committingSubjectStyle.Render(": "+m.msg.Subject) + "\n"
body := committingBodyStyle.Render(m.msg.Body)
footer := committingFooterStyle.Render(m.msg.Footer+"\n"+m.msg.SOB) + "\n"
msg := m.spinner.View()
if m.done {
if m.err != nil {
msg = committingFailedStyle.Render("( ●●● ) Commit Failed: \n" + m.err.Error())
} else {
msg = committingSuccessStyle.Render("◉◉◉◉ Always code as if the guy who ends up maintaining your \n◉◉◉◉ code will be a violent psychopath who knows where you live...")
}
}
return committingStyle.Render(lipgloss.JoinVertical(lipgloss.Left, header, body, footer, msg))
}