-
Notifications
You must be signed in to change notification settings - Fork 18
/
ui_push.go
132 lines (116 loc) · 2.98 KB
/
ui_push.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
132
package main
import (
"time"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var (
pushLayout = lipgloss.NewStyle().
Padding(1, 1, 1, 2)
pushSuccessTextStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.AdaptiveColor{Light: "#25BD7E", Dark: "#57FFBA"})
pushSuccessMsgStyle = lipgloss.NewStyle().
Bold(true).
Width(75).
Foreground(lipgloss.AdaptiveColor{Light: "#2BAAD5", Dark: "#2FD0FF"})
pushFailedTextStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.AdaptiveColor{Light: "#5B44FF", Dark: "#7653FF"})
pushFailedErrStyle = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.AdaptiveColor{Light: "#FF2117", Dark: "#FF6037"})
)
type pushModel struct {
done bool
msg string
err error
spinner spinner.Model
}
type pushMsg struct {
err error
msg string
}
func newPushModel() pushModel {
s := spinner.NewModel()
s.Spinner = spinner.Spinner{
Frames: []string{
"●∙∙∙ P",
"∙●∙∙ Pu",
"∙∙●∙ Pus",
"∙∙∙● Push",
"∙∙●∙ Pushi",
"∙●∙∙ Pushin",
"●∙∙∙ Pushing",
"∙●∙∙ Pushing, p",
"∙∙●∙ Pushing, pl",
"∙∙∙● Pushing, ple",
"∙∙●∙ Pushing, plea",
"∙●∙∙ Pushing, pleas",
"●∙∙∙ Pushing, please w",
"∙●∙∙ Pushing, please wa",
"∙∙●∙ Pushing, please wai",
"∙∙∙● Pushing, please wait",
"∙∙●∙ Pushing, please wait.",
"∙●∙∙ Pushing, please wait..",
"●∙∙∙ Pushing, please wait...",
},
FPS: time.Second / 15,
}
s.Style = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#25A065", Dark: "#19F896"}).Bold(true)
return pushModel{
spinner: s,
}
}
func (m pushModel) Init() tea.Cmd {
return tea.Batch(spinner.Tick, func() tea.Msg { return "running" })
}
func (m pushModel) 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
}
case string:
return m, func() tea.Msg {
time.Sleep(1500 * time.Millisecond)
var ps pushMsg
ps.msg, ps.err = push()
return ps
}
case pushMsg:
m.msg, m.err = msg.msg, msg.err
m.done = true
return m, tea.Quit
default:
var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg)
return m, cmd
}
return m, nil
}
func (m pushModel) View() string {
view := pushLayout.Render(m.spinner.View())
if m.done {
if m.err == nil {
view = pushLayout.Render(
lipgloss.JoinVertical(
lipgloss.Left,
pushSuccessTextStyle.Render("( ̄▽ ̄)ノ The code has been pushed successfully.\n"),
pushSuccessMsgStyle.Render(m.msg),
),
)
} else {
view = pushLayout.Render(
lipgloss.JoinVertical(
lipgloss.Left,
pushFailedTextStyle.Render("(。•́︿•̀。) Something went wrong while pushing:\n"),
pushFailedErrStyle.Render(m.err.Error()),
),
)
}
}
return view
}