From 3b3bf684f9e0f48fb84bc2ba7308d1331a7e6d38 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 17 Jul 2020 12:25:40 -0400 Subject: Detect when stash and news loading fails (and update the UI accordingly) --- Makefile | 19 +++++++++++++++++++ ui/stash.go | 10 ++++++++++ ui/ui.go | 8 +++++--- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b93836d --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +# This Makefile is just for development purposes + +.PHONY: default clean glow run log + +default: glow + +clean: + rm -f ./glow + +glow: + go build + +run: clean glow + ./glow + +log: + GLOW_UI_LOGFILE=debug.log + > debug.log + tail -f debug.log diff --git a/ui/stash.go b/ui/stash.go index f96d4f2..ccfb169 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -219,6 +219,16 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { case errMsg: m.err = msg + case stashLoadErrMsg: + m.err = msg.err + m.loaded |= loadedStash // still done, albeit unsuccessfully + m.stashFullyLoaded = true + m.loadingFromNetwork = false + + case newsLoadErrMsg: + m.err = msg.err + m.loaded |= loadedNews // still done, albeit unsuccessfully + // We're finished searching for local files case localFileSearchFinished: m.loaded |= loadedLocalFiles diff --git a/ui/ui.go b/ui/ui.go index 6ca8c1f..4912ba5 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -37,7 +37,7 @@ func NewProgram(style string, cfg UIConfig) *tea.Program { if config.Logfile != "" { log.Println("-- Starting Glow ----------------") log.Printf("High performance pager: %v", cfg.HighPerformancePager) - log.Printf("Render with Glamour: %v", cfg.GlamourEnabled) + log.Printf("Glamour rendering: %v", cfg.GlamourEnabled) log.Println("Bubble Tea now initializing...") } return tea.NewProgram(initialize(style), update, view) @@ -57,7 +57,9 @@ type initLocalFileSearchMsg struct { type foundLocalFileMsg string type localFileSearchFinished struct{} type gotStashMsg []*charm.Markdown +type stashLoadErrMsg struct{ err error } type gotNewsMsg []*charm.Markdown +type newsLoadErrMsg struct{ err error } // MODEL @@ -398,7 +400,7 @@ func loadStash(m stashModel) tea.Cmd { return func() tea.Msg { stash, err := m.cc.GetStash(m.page) if err != nil { - return errMsg(err) + return stashLoadErrMsg{err: err} } return gotStashMsg(stash) } @@ -408,7 +410,7 @@ func loadNews(m stashModel) tea.Cmd { return func() tea.Msg { news, err := m.cc.GetNews(1) // just fetch the first page if err != nil { - return errMsg(err) + return newsLoadErrMsg{err: err} } return gotNewsMsg(news) } -- cgit v1.2.3