mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-22 08:04:18 +02:00
Minor comments and cleanup in the TUI
This commit is contained in:
parent
3d5d203217
commit
c55bb23744
3 changed files with 17 additions and 21 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
16
ui/stash.go
16
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 (
|
||||
|
|
|
|||
20
ui/ui.go
20
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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue