mirror of
https://github.com/charmbracelet/glow
synced 2024-09-28 20:23:45 +00:00
Move TUI config into its own file
This commit is contained in:
parent
8a6c6ef85d
commit
683d2c0cf6
30
ui/config.go
Normal file
30
ui/config.go
Normal file
|
@ -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)
|
||||
}
|
45
ui/ui.go
45
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]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue