From 683d2c0cf6af2eea74de218228f5d69c02a45240 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 10 Dec 2020 20:35:00 -0500 Subject: [PATCH] Move TUI config into its own file --- ui/config.go | 30 ++++++++++++++++++++++++++++++ ui/ui.go | 45 ++++++++++----------------------------------- 2 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 ui/config.go diff --git a/ui/config.go b/ui/config.go new file mode 100644 index 0000000..8fafec5 --- /dev/null +++ b/ui/config.go @@ -0,0 +1,30 @@ +package ui + +// Config contains TUI-specific configuration. +type Config struct { + ShowAllFiles bool + Gopath string `env:"GOPATH"` + HomeDir string `env:"HOME"` + GlamourMaxWidth uint + GlamourStyle string + + // Which document types shall we show? We work though this with bitmasking. + DocumentTypes DocTypeSet + + // For debugging the UI + Logfile string `env:"GLOW_LOGFILE"` + HighPerformancePager bool `env:"GLOW_HIGH_PERFORMANCE_PAGER" default:"true"` + GlamourEnabled bool `env:"GLOW_ENABLE_GLAMOUR" default:"true"` +} + +func (c Config) showLocalFiles() bool { + return c.DocumentTypes.Contains(LocalDoc) +} + +func (c Config) localOnly() bool { + return c.DocumentTypes.Equals(NewDocTypeSet(LocalDoc)) +} + +func (c Config) stashedOnly() bool { + return c.DocumentTypes.Contains(StashedDoc) && !c.DocumentTypes.Contains(LocalDoc) +} diff --git a/ui/ui.go b/ui/ui.go index 038c4a2..3fb71c6 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -30,40 +30,14 @@ const ( var ( config Config glowLogoTextColor = common.Color("#ECFD65") - debug = false // true if we're logging to a file, in which case we'll log more stuff + // True if we're logging to a file, in which case we'll log more stuff. + debug = false + + // Types of documents we allow the user to stash. stashableDocTypes = NewDocTypeSet(LocalDoc, NewsDoc) ) -// Config contains TUI-specific configuration. -type Config struct { - ShowAllFiles bool - Gopath string `env:"GOPATH"` - HomeDir string `env:"HOME"` - GlamourMaxWidth uint - GlamourStyle string - - // Which document types shall we show? We work though this with bitmasking. - DocumentTypes DocTypeSet - - // For debugging the UI - Logfile string `env:"GLOW_LOGFILE"` - HighPerformancePager bool `env:"GLOW_HIGH_PERFORMANCE_PAGER" default:"true"` - GlamourEnabled bool `env:"GLOW_ENABLE_GLAMOUR" default:"true"` -} - -func (c Config) showLocalFiles() bool { - return c.DocumentTypes.Contains(LocalDoc) -} - -func (c Config) localOnly() bool { - return c.DocumentTypes.Equals(NewDocTypeSet(LocalDoc)) -} - -func (c Config) stashedOnly() bool { - return c.DocumentTypes.Contains(StashedDoc) && !c.DocumentTypes.Contains(LocalDoc) -} - // NewProgram returns a new Tea program. func NewProgram(cfg Config) *tea.Program { if cfg.Logfile != "" { @@ -102,8 +76,8 @@ type stashFailMsg struct { markdown markdown } -// Which part of the application something appies to. Occasionally used as an -// argument to commands and messages. +// applicationContext indicates the area of the application something appies +// to. Occasionally used as an argument to commands and messages. type applicationContext int const ( @@ -111,6 +85,7 @@ const ( pagerContext ) +// state is the top-level application state. type state int const ( @@ -119,9 +94,9 @@ const ( ) func (s state) String() string { - return [...]string{ - "showing stash", - "showing document", + return map[state]string{ + stateShowStash: "showing file listing", + stateShowDocument: "showing document", }[s] }