diff --git a/ui/cmd/greeting/model.go b/ui/cmd/greeting/model.go index 59d375f..b0e6065 100644 --- a/ui/cmd/greeting/model.go +++ b/ui/cmd/greeting/model.go @@ -78,6 +78,7 @@ type Model struct { conversation []*Message user *spotify.PrivateUser spotifyClient *spotify.Client + err error } func NewModel() *Model { diff --git a/ui/cmd/greeting/update.go b/ui/cmd/greeting/update.go index bc5838c..d1efb23 100644 --- a/ui/cmd/greeting/update.go +++ b/ui/cmd/greeting/update.go @@ -2,7 +2,6 @@ package greeting import ( "errors" - "log" "github.com/JunNishimura/Chatify/auth" "github.com/JunNishimura/Chatify/config" @@ -60,7 +59,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case deviceMsg: m.phase = completePhase case errMsg: - log.Println(msg.err) + m.err = msg.err } m.textInput, inputCmd = m.textInput.Update(msg) diff --git a/ui/cmd/greeting/view.go b/ui/cmd/greeting/view.go index b94b457..67475dd 100644 --- a/ui/cmd/greeting/view.go +++ b/ui/cmd/greeting/view.go @@ -8,6 +8,9 @@ import ( ) func (m *Model) View() string { + if m.err != nil { + return style.ErrorView(m.window.Width, m.window.Height) + } return lipgloss.Place(m.window.Width, m.window.Height, lipgloss.Center, lipgloss.Center, lipgloss.JoinVertical( lipgloss.Center, diff --git a/ui/cmd/hey/model.go b/ui/cmd/hey/model.go index 880d998..142995b 100644 --- a/ui/cmd/hey/model.go +++ b/ui/cmd/hey/model.go @@ -77,6 +77,7 @@ type Model struct { functions []openai.FunctionDefinition availableGenres []string recommendItems []list.Item + err error } func NewModel() *Model { diff --git a/ui/cmd/hey/update.go b/ui/cmd/hey/update.go index 131962a..a423b75 100644 --- a/ui/cmd/hey/update.go +++ b/ui/cmd/hey/update.go @@ -3,7 +3,6 @@ package hey import ( "encoding/json" "fmt" - "log" "strings" "github.com/JunNishimura/Chatify/ai/functions" @@ -119,7 +118,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.recommendItems = msg.items m.list = newListModel(m.recommendItems, m.getViewWidth(), m.getViewHeight()) case errMsg: - log.Println(msg.err) + m.err = msg.err } m.textInput, inputCmd = m.textInput.Update(msg) diff --git a/ui/cmd/hey/view.go b/ui/cmd/hey/view.go index f1317ca..4d8da29 100644 --- a/ui/cmd/hey/view.go +++ b/ui/cmd/hey/view.go @@ -6,9 +6,11 @@ import ( ) func (m *Model) View() string { - var s string + if m.err != nil { + return style.ErrorView(m.window.Width, m.window.Height) + } - // window size adjustmen + var s string if m.state == chatView { s += lipgloss.Place(m.window.Width, m.window.Height, lipgloss.Center, lipgloss.Center, lipgloss.JoinHorizontal( diff --git a/ui/style/style.go b/ui/style/style.go index b9fceeb..0ec0f5f 100644 --- a/ui/style/style.go +++ b/ui/style/style.go @@ -8,6 +8,7 @@ import ( const ( White = "#ffffff" Gray = "#777777" + Red = "#ff4444" HighlightColor = "#1DB954" SemiHighlightColor = "#146542" BgColor = "#191414" @@ -95,3 +96,22 @@ func AsciiArt() lipgloss.Style { return lipgloss.NewStyle(). Foreground(lipgloss.Color(HighlightColor)) } + +const errorMessage = "unexpected error happens.\n\nplease report at\n\nhttps://github.com/JunNishimura/Chatify/issues" + +func ErrorView(windowWidth, windowHeight int) string { + return lipgloss.Place(windowWidth, windowHeight, lipgloss.Center, lipgloss.Center, + lipgloss.NewStyle(). + Width(60). + Height(10). + BorderStyle(lipgloss.ThickBorder()). + BorderForeground(lipgloss.Color(HighlightColor)). + Background(lipgloss.AdaptiveColor{Dark: BgColor, Light: BgColor}). + Render(lipgloss.Place(50, 10, lipgloss.Center, lipgloss.Center, + lipgloss.NewStyle(). + Width(50). + Align(lipgloss.Center). + Foreground(lipgloss.Color(Red)). + Background(lipgloss.Color(BgColor)). + Render(errorMessage)))) +}