Minor comments and cleanup in the TUI

This commit is contained in:
Christian Rocha 2020-08-13 15:37:53 -04:00 committed by Christian Muehlhaeuser
commit c55bb23744
3 changed files with 17 additions and 21 deletions

View file

@ -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
}

View file

@ -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 (

View file

@ -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)
}