Skip to content

Commit ce703bd

Browse files
committed
feat: implement animated spinner for starting, stopping and task states in server status
1 parent 08a85f3 commit ce703bd

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

go/tui/tui.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (m TuiModel) Init() tea.Cmd {
257257
// ─────────────────────────────────────────────
258258

259259
func tickCmd() tea.Cmd {
260-
return tea.Tick(500*time.Millisecond, func(t time.Time) tea.Msg {
260+
return tea.Tick(150*time.Millisecond, func(t time.Time) tea.Msg {
261261
return tickMsg(t)
262262
})
263263
}
@@ -306,14 +306,18 @@ func (m TuiModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
306306
return m, nil
307307

308308
case tickMsg:
309-
m.blink = !m.blink
310309
m.tickCount++
310+
if m.tickCount%4 == 0 {
311+
m.blink = !m.blink
312+
}
311313

312-
// Sample Nuxt process memory stats
313-
mb := getNuxtMemoryMB()
314-
m.memHistory = append(m.memHistory, mb)
315-
if len(m.memHistory) > 30 {
316-
m.memHistory = m.memHistory[1:]
314+
if m.tickCount%10 == 0 {
315+
// Sample Nuxt process memory stats
316+
mb := getNuxtMemoryMB()
317+
m.memHistory = append(m.memHistory, mb)
318+
if len(m.memHistory) > 30 {
319+
m.memHistory = m.memHistory[1:]
320+
}
317321
}
318322

319323
return m, tickCmd()
@@ -1420,7 +1424,17 @@ func (m TuiModel) renderClientPanel(w, h int) string {
14201424

14211425
// Server status line
14221426
var statusLine string
1423-
if m.serverRunning {
1427+
if m.taskActive && strings.Contains(strings.ToLower(m.statusMsg), "stopping") {
1428+
spinnerFrames := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
1429+
frame := spinnerFrames[m.tickCount%len(spinnerFrames)]
1430+
dot := lipgloss.NewStyle().Foreground(colorWarn).Bold(true).Render(frame)
1431+
statusLine = dot + " " + boldStyle.Render("STOPPING") + " " + mutedStyle.Render("http://localhost:3000")
1432+
} else if m.taskActive && strings.Contains(strings.ToLower(m.statusMsg), "starting") {
1433+
spinnerFrames := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
1434+
frame := spinnerFrames[m.tickCount%len(spinnerFrames)]
1435+
dot := lipgloss.NewStyle().Foreground(colorCyan).Bold(true).Render(frame)
1436+
statusLine = dot + " " + boldStyle.Render("STARTING") + " " + mutedStyle.Render("http://localhost:3000")
1437+
} else if m.serverRunning {
14241438
dot := accentStyle.Render("●")
14251439
if m.blink {
14261440
dot = lipgloss.NewStyle().Foreground(lipgloss.Color("#2ea043")).Bold(true).Render("●")
@@ -1431,7 +1445,9 @@ func (m TuiModel) renderClientPanel(w, h int) string {
14311445
_ = m.ctx
14321446
}
14331447
} else if m.taskActive {
1434-
dot := warnStyle.Render("…")
1448+
spinnerFrames := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
1449+
frame := spinnerFrames[m.tickCount%len(spinnerFrames)]
1450+
dot := lipgloss.NewStyle().Foreground(colorWarn).Bold(true).Render(frame)
14351451
statusLine = dot + " " + boldStyle.Render("STARTING") + " " + mutedStyle.Render("http://localhost:3000")
14361452
} else {
14371453
dot := errStyle.Render("○")

0 commit comments

Comments
 (0)