diff --git a/main.go b/main.go index 69e17ea9..870113d2 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/modules/textfile/settings.go b/modules/textfile/settings.go new file mode 100644 index 00000000..b0681aa1 --- /dev/null +++ b/modules/textfile/settings.go @@ -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 +} diff --git a/modules/textfile/widget.go b/modules/textfile/widget.go index 6125681b..8ead3508 100644 --- a/modules/textfile/widget.go +++ b/modules/textfile/widget.go @@ -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 }