on main help sign in
fix(tui): show initialization mark errors in status footer (#2825)
a924ca1huaiyuWangh
internal/ui/model/onboarding.go+14−10
@@ -2,8 +2,8 @@ package model
2
2
3import (
3import (
4 "fmt"
4 "fmt"
5− "log/slog"
6 "strings"
5 "strings"
6+ "time"
7
7
8 "charm.land/bubbles/v2/key"
8 "charm.land/bubbles/v2/key"
9 tea "charm.land/bubbletea/v2"
9 tea "charm.land/bubbletea/v2"
@@ -14,14 +14,18 @@ import (
14 "github.com/charmbracelet/crush/internal/ui/util"
14 "github.com/charmbracelet/crush/internal/ui/util"
15)
15)
16
16
17−// markProjectInitialized marks the current project as initialized in the config.
17+// markProjectInitializedCmd marks the current project as initialized in the config.
18−func (m *UI) markProjectInitialized() tea.Msg {
18+func (m *UI) markProjectInitializedCmd() tea.Cmd {
19− // TODO: handle error so we show it in the tui footer
19+ return func() tea.Msg {
20− err := m.com.Workspace.MarkProjectInitialized()
20+ if err := m.com.Workspace.MarkProjectInitialized(); err != nil {
21− if err != nil {
21+ return util.InfoMsg{
22− slog.Error(err.Error())
22+ Type: util.InfoTypeError,
23+ Msg: fmt.Sprintf("Failed to mark project as initialized: %v", err),
24+ TTL: 15 * time.Second,
25+ }
26+ }
27+ return nil
23 }
28 }
24− return nil
25}
29}
26
30
27// updateInitializeView handles keyboard input for the project initialization prompt.
31// updateInitializeView handles keyboard input for the project initialization prompt.
@@ -61,7 +65,7 @@ func (m *UI) initializeProject() tea.Cmd {
61 return sendMessageMsg{Content: initPrompt}
65 return sendMessageMsg{Content: initPrompt}
62 }
66 }
63 // Mark the project as initialized
67 // Mark the project as initialized
64− cmds = append(cmds, initialize, m.markProjectInitialized)
68+ cmds = append(cmds, initialize, m.markProjectInitializedCmd())
65
69
66 return tea.Sequence(cmds...)
70 return tea.Sequence(cmds...)
67}
71}
@@ -71,7 +75,7 @@ func (m *UI) skipInitializeProject() tea.Cmd {
71 // TODO: initialize the project
75 // TODO: initialize the project
72 m.setState(uiLanding, uiFocusEditor)
76 m.setState(uiLanding, uiFocusEditor)
73 // mark the project as initialized
77 // mark the project as initialized
74− return m.markProjectInitialized
78+ return m.markProjectInitializedCmd()
75}
79}
76
80
77// initializeView renders the project initialization prompt with Yes/No buttons.
81// initializeView renders the project initialization prompt with Yes/No buttons.