1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-400 Textfile extracted to new config format

This commit is contained in:
Chris Cummer 2019-04-16 09:30:32 -07:00
parent ea88f5eece
commit c489f2a4f4
3 changed files with 37 additions and 6 deletions

View File

@ -289,7 +289,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
settings := system.NewSettingsFromYAML(wtf.Config)
widget = system.NewWidget(app, date, version, settings)
case "textfile":
widget = textfile.NewWidget(app, pages)
settings := textfile.NewSettingsFromYAML(wtf.Config)
widget = textfile.NewWidget(app, pages, settings)
case "todo":
cfg := todo.NewSettingsFromYAML(wtf.Config)
widget = todo.NewWidget(app, pages, cfg)

View File

@ -0,0 +1,28 @@
package textfile
import (
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
)
type Settings struct {
common *cfg.Common
filePaths []interface{}
format bool
formatStyle string
}
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
localConfig, _ := ymlConfig.Get("wtf.mods.textfile")
settings := Settings{
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
filePaths: localConfig.UList("filePaths"),
format: localConfig.UBool("format", false),
formatStyle: localConfig.UString("formatStyle", "vim"),
}
return &settings
}

View File

@ -34,13 +34,17 @@ type Widget struct {
wtf.HelpfulWidget
wtf.MultiSourceWidget
wtf.TextWidget
settings *Settings
}
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
widget := Widget{
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
MultiSourceWidget: wtf.NewMultiSourceWidget("textfile", "filePath", "filePaths"),
TextWidget: wtf.NewTextWidget(app, "TextFile", "textfile", true),
settings: settings,
}
// Don't use a timer for this widget, watch for filesystem changes instead
@ -76,16 +80,14 @@ func (widget *Widget) display() {
text := wtf.SigilStr(len(widget.Sources), widget.Idx, widget.View) + "\n"
if wtf.Config.UBool("wtf.mods.textfile.format", false) {
if widget.settings.format {
text = text + widget.formattedText()
} else {
text = text + widget.plainText()
}
//widget.View.Lock()
widget.View.SetTitle(title) // <- Writes to TextView's title
widget.View.SetText(text) // <- Writes to TextView's text
//widget.View.Unlock()
}
func (widget *Widget) fileName() string {
@ -105,7 +107,7 @@ func (widget *Widget) formattedText() string {
lexer = lexers.Fallback
}
style := styles.Get(wtf.Config.UString("wtf.mods.textfile.formatStyle", "vim"))
style := styles.Get(widget.settings.formatStyle)
if style == nil {
style = styles.Fallback
}