@@ -15,7 +15,7 @@ import (
15
15
)
16
16
17
17
var (
18
- focusedStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("#6FD0FB " )).Bold (true )
18
+ focusedStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("#DA8BFF " )).Bold (true )
19
19
blurredStyle = lipgloss .NewStyle ().Foreground (lipgloss .Color ("240" ))
20
20
cursorStyle = focusedStyle .Copy ()
21
21
noStyle = lipgloss .NewStyle ()
@@ -37,7 +37,7 @@ func main() {
37
37
if ! isGitRepo {
38
38
log .Fatal ("Not a git repository" )
39
39
}
40
- p := tea .NewProgram (initialModel ())
40
+ p := tea .NewProgram (initialModel (), tea . WithAltScreen () )
41
41
if _ , err := p .Run (); err != nil {
42
42
log .Fatal (err )
43
43
}
@@ -57,12 +57,6 @@ func initialModel() model {
57
57
58
58
result := strings .Split (branch , "/" )
59
59
60
- // get first and second result into separate variables
61
- // check if result has more than 2 items
62
- //if len(result) <= 2 {
63
- // log.Fatal("Branch name should be in the format of <type>/<task-id>/short-message")
64
- //}
65
-
66
60
var branchType string
67
61
var ticketId string
68
62
@@ -87,7 +81,12 @@ func initialModel() model {
87
81
88
82
switch i {
89
83
case 0 :
90
- t .SetValue (fmt .Sprintf ("[%s] [%s] " , branchType , ticketId ))
84
+ if branchType != "" {
85
+ t .SetValue (fmt .Sprintf ("[%s] " , branchType ))
86
+ }
87
+ if ticketId != "" {
88
+ t .SetValue (t .Value () + fmt .Sprintf ("[%s] " , ticketId ))
89
+ }
91
90
t .Focus ()
92
91
t .PromptStyle = focusedStyle
93
92
t .TextStyle = focusedStyle
@@ -193,46 +192,44 @@ func (m *model) updateInputs(msg tea.Msg) tea.Cmd {
193
192
}
194
193
195
194
func (m model ) View () string {
196
- var b strings.Builder
195
+ s := ""
196
+
197
+ stagedFilesView := ""
198
+ stagedFilesView += lipgloss .JoinVertical (lipgloss .Top , "Staged files:" )
199
+ stagedFilesView += "\n "
200
+ for index , elem := range m .stagedFiles {
201
+ stagedFilesView += lipgloss .JoinVertical (lipgloss .Top , stagedFilesStyle .Render (fmt .Sprintf ("• %s" , elem )))
202
+ if index != len (m .stagedFiles )- 1 {
203
+ stagedFilesView += "\n "
204
+ }
205
+ }
197
206
198
207
currentBranch := lipgloss .NewStyle ().Foreground (lipgloss .Color ("#fcbda1" )).SetString (fmt .Sprintf ("Branch: %s" , m .branch ))
199
208
200
- b .WriteString (currentBranch .Render ())
201
- b .WriteRune ('\n' )
202
- b .WriteRune ('\n' )
203
-
204
- currentCommitCommand := lipgloss .NewStyle ().Foreground (lipgloss .Color ("#a1e0fc" )).SetString (fmt .Sprintf ("git commit -m \" %s\" %s" , m .inputs [0 ].Value (), m .inputs [1 ].Value ()))
209
+ s += lipgloss .JoinVertical (lipgloss .Top , currentBranch .Render ())
210
+ s += "\n \n "
205
211
206
- b .WriteString (currentCommitCommand .Render ())
207
- b .WriteRune ('\n' )
208
- b .WriteRune ('\n' )
209
-
210
- inputLabels := []string {"Commit message " , "Commit flags " }
212
+ inputLabels := []string {"Commit message:" , "Commit flags (optional):" }
211
213
212
214
for i := range m .inputs {
213
- if i == m .focusInputIndex {
214
- b .WriteString (lipgloss .NewStyle ().Foreground (lipgloss .Color ("#6FD0FB" )).Bold (true ).SetString (inputLabels [i ]).Render ())
215
- } else {
216
- b .WriteString (inputLabels [i ])
217
- }
218
- b .WriteString (m .inputs [i ].View ())
219
- b .WriteRune ('\n' )
215
+ s += lipgloss .JoinVertical (1 , inputLabels [i ])
216
+ s += "\n "
217
+ s += lipgloss .JoinVertical (0.5 , m .inputs [i ].View ())
220
218
if i < len (m .inputs )- 1 {
221
- b . WriteRune ( '\n' )
219
+ s += " \n "
222
220
}
223
221
}
224
222
225
223
button := & blurredButton
226
224
if m .focusInputIndex == len (m .inputs ) {
227
225
button = & focusedButton
228
226
}
229
- fmt .Fprintf (& b , "\n \n %s\n \n " , * button )
227
+ s += "\n \n "
228
+ s += lipgloss .JoinVertical (1 , * button )
230
229
231
- b .WriteString ("Staged changes: " )
232
- b .WriteRune ('\n' )
233
- b .WriteString (stagedFilesStyle .Render (strings .Join (m .stagedFiles , "\n " )))
230
+ stagedFilesStyle := lipgloss .NewStyle ().MarginLeft (8 ).Border (lipgloss .NormalBorder ()).Padding (0 , 1 )
234
231
235
- b . WriteRune ( '\n' )
232
+ f := lipgloss . JoinHorizontal ( lipgloss . Left , s , stagedFilesStyle . Render ( stagedFilesView ) )
236
233
237
- return b . String ()
234
+ return f
238
235
}
0 commit comments