From c55bb237441b7fa08fcd56f8c7f5a3646bafc8e5 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 13 Aug 2020 15:37:53 -0400 Subject: [PATCH] Minor comments and cleanup in the TUI --- ui/pager.go | 2 +- ui/stash.go | 16 +++++++--------- ui/ui.go | 20 +++++++++----------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/ui/pager.go b/ui/pager.go index 6e5366c..4aa518e 100644 --- a/ui/pager.go +++ b/ui/pager.go @@ -85,7 +85,7 @@ type pagerModel struct { showHelp bool // Current document being rendered, sans-glamour rendering. We cache - // this here so we can re-render it on resize. + // it here so we can re-render it on resize. currentDocument *markdown } diff --git a/ui/stash.go b/ui/stash.go index 87dba57..f27b571 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -101,9 +101,7 @@ const ( ) func (s loadedState) done() bool { - return s&loadedStash != 0 && - s&loadedNews != 0 && - s&loadedLocalFiles != 0 + return s&loadedStash != 0 && s&loadedNews != 0 && s&loadedLocalFiles != 0 } type stashState int @@ -176,7 +174,7 @@ func (m stashModel) selectedMarkdown() *markdown { return m.markdowns[i] } -// addDocuments adds markdown documents to the model +// adds markdown documents to the model func (m *stashModel) addMarkdowns(mds ...*markdown) { if len(mds) > 0 { m.markdowns = append(m.markdowns, mds...) @@ -185,6 +183,7 @@ func (m *stashModel) addMarkdowns(mds ...*markdown) { } } +// return the number of markdown documents of a given type func (m stashModel) countMarkdowns(t markdownType) (found int) { if len(m.markdowns) == 0 { return @@ -363,6 +362,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { m.state = stashStatePromptDelete } + // Show errors case "!": if m.err != nil && m.state == stashStateReady { m.state = stashStateShowingError @@ -484,9 +484,6 @@ func stashView(m stashModel) string { case stashStateLoadingDocument: s += " " + spinner.View(m.spinner) + " Loading document..." case stashStateReady, stashStateSettingNote, stashStatePromptDelete: - var ( - header string - ) loadingIndicator := "" if !m.loaded.done() || m.loadingFromNetwork { @@ -501,6 +498,7 @@ func stashView(m stashModel) string { blankLines = strings.Repeat("\n", numBlankLines) } + var header string switch m.state { case stashStatePromptDelete: header = redFg("Delete this item? ") + faintRedFg("(y/N)") @@ -652,8 +650,8 @@ func stashHelpView(m stashModel) string { return stashHelpViewBuilder(m.terminalWidth, h...) } -// stashHelpViewBuilder builds the help view text, truncating it if it would -// otherwise wrap to two lines. +// builds the help view from various sections pieces, truncating it if the view +// would otherwise wrap to two lines. func stashHelpViewBuilder(windowWidth int, sections ...string) string { const truncationWidth = 1 // width of "…" var ( diff --git a/ui/ui.go b/ui/ui.go index e17bf75..7d20d8b 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -16,11 +16,14 @@ import ( te "github.com/muesli/termenv" ) -const ( - noteCharacterLimit = 256 // should match server +const noteCharacterLimit = 256 // should match server + +var ( + config Config + glowLogoTextColor = common.Color("#ECFD65") ) -// Config contains configuration specified to the TUI +// Config contains configuration specified to the TUI. type Config struct { IdentityFile string @@ -30,12 +33,7 @@ type Config struct { GlamourEnabled bool `env:"GLOW_UI_ENABLE_GLAMOUR" default:"true"` } -var ( - config Config - glowLogoTextColor = common.Color("#ECFD65") -) - -// NewProgram returns a new Tea program +// NewProgram returns a new Tea program. func NewProgram(style string, cfg Config) *tea.Program { if cfg.Logfile != "" { log.Println("-- Starting Glow ----------------") @@ -423,7 +421,7 @@ func loadStash(m stashModel) tea.Cmd { return func() tea.Msg { stash, err := m.cc.GetStash(m.page) if err != nil { - return stashLoadErrMsg{err: err} + return stashLoadErrMsg{err} } return gotStashMsg(stash) } @@ -433,7 +431,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 newsLoadErrMsg{err: err} + return newsLoadErrMsg{err} } return gotNewsMsg(news) }