diff --git a/_site/content/posts/modules/textfile.md b/_site/content/posts/modules/textfile.md index 3be1eeda..088022e0 100644 --- a/_site/content/posts/modules/textfile.md +++ b/_site/content/posts/modules/textfile.md @@ -33,7 +33,7 @@ None. ```yaml textfile: enabled: true - filename: "notes.md" + filePath: "~/Desktop/notes.md" position: top: 5 left: 4 @@ -48,10 +48,8 @@ textfile: Determines whether or not this module is executed and if its data displayed onscreen.
Values: `true`, `false`. -`filename`
-The name of the file to be displayed in the widget.
-*Note:* Currently this file *must* reside in the `~/.wtf/` directory. -This is a known bug. +`filePath`
+The path to the file to be displayed in the widget.
`position`
Defines where in the grid this module's widget will be displayed.
diff --git a/textfile/widget.go b/textfile/widget.go index ed86e27e..4ecfc0e7 100644 --- a/textfile/widget.go +++ b/textfile/widget.go @@ -2,6 +2,7 @@ package textfile import ( "fmt" + "io/ioutil" "time" "github.com/gdamore/tcell" @@ -33,7 +34,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { TextWidget: wtf.NewTextWidget(" 📄 Text File ", "textfile", true), app: app, - filePath: Config.UString("wtf.mods.textfile.filename"), + filePath: Config.UString("wtf.mods.textfile.filePath"), pages: pages, } @@ -57,12 +58,17 @@ func (widget *Widget) Refresh() { widget.View.Clear() - fileData, err := wtf.ReadFile(widget.filePath) + filePath, _ := wtf.ExpandHomeDir(widget.filePath) + + fileData, err := ioutil.ReadFile(filePath) + if err != nil { + fileData = []byte{} + } if err != nil { fmt.Fprintf(widget.View, "%s", err) } else { - fmt.Fprintf(widget.View, "%s", fileData) + fmt.Fprintf(widget.View, "%s", string(fileData)) } } diff --git a/wtf/config_files.go b/wtf/config_files.go index c19fb861..5674a89b 100644 --- a/wtf/config_files.go +++ b/wtf/config_files.go @@ -72,7 +72,7 @@ func LoadConfigFile(filePath string) *config.Config { return cfg } -func ReadFile(fileName string) (string, error) { +func ReadConfigFile(fileName string) (string, error) { configDir, err := ConfigDir() if err != nil { return "", err