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:
parent
ea88f5eece
commit
c489f2a4f4
3
main.go
3
main.go
@ -289,7 +289,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
|||||||
settings := system.NewSettingsFromYAML(wtf.Config)
|
settings := system.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = system.NewWidget(app, date, version, settings)
|
widget = system.NewWidget(app, date, version, settings)
|
||||||
case "textfile":
|
case "textfile":
|
||||||
widget = textfile.NewWidget(app, pages)
|
settings := textfile.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = textfile.NewWidget(app, pages, settings)
|
||||||
case "todo":
|
case "todo":
|
||||||
cfg := todo.NewSettingsFromYAML(wtf.Config)
|
cfg := todo.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = todo.NewWidget(app, pages, cfg)
|
widget = todo.NewWidget(app, pages, cfg)
|
||||||
|
28
modules/textfile/settings.go
Normal file
28
modules/textfile/settings.go
Normal 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
|
||||||
|
}
|
@ -34,13 +34,17 @@ type Widget struct {
|
|||||||
wtf.HelpfulWidget
|
wtf.HelpfulWidget
|
||||||
wtf.MultiSourceWidget
|
wtf.MultiSourceWidget
|
||||||
wtf.TextWidget
|
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{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
MultiSourceWidget: wtf.NewMultiSourceWidget("textfile", "filePath", "filePaths"),
|
MultiSourceWidget: wtf.NewMultiSourceWidget("textfile", "filePath", "filePaths"),
|
||||||
TextWidget: wtf.NewTextWidget(app, "TextFile", "textfile", true),
|
TextWidget: wtf.NewTextWidget(app, "TextFile", "textfile", true),
|
||||||
|
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't use a timer for this widget, watch for filesystem changes instead
|
// 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"
|
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()
|
text = text + widget.formattedText()
|
||||||
} else {
|
} else {
|
||||||
text = text + widget.plainText()
|
text = text + widget.plainText()
|
||||||
}
|
}
|
||||||
|
|
||||||
//widget.View.Lock()
|
|
||||||
widget.View.SetTitle(title) // <- Writes to TextView's title
|
widget.View.SetTitle(title) // <- Writes to TextView's title
|
||||||
widget.View.SetText(text) // <- Writes to TextView's text
|
widget.View.SetText(text) // <- Writes to TextView's text
|
||||||
//widget.View.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) fileName() string {
|
func (widget *Widget) fileName() string {
|
||||||
@ -105,7 +107,7 @@ func (widget *Widget) formattedText() string {
|
|||||||
lexer = lexers.Fallback
|
lexer = lexers.Fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
style := styles.Get(wtf.Config.UString("wtf.mods.textfile.formatStyle", "vim"))
|
style := styles.Get(widget.settings.formatStyle)
|
||||||
if style == nil {
|
if style == nil {
|
||||||
style = styles.Fallback
|
style = styles.Fallback
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user