mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Fixes #35: TextFile only opens files in ~/.wtf/
This commit is contained in:
parent
89b1b0f517
commit
8e46547d1c
@ -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. <br />
|
||||
Values: `true`, `false`.
|
||||
|
||||
`filename` <br />
|
||||
The name of the file to be displayed in the widget. <br />
|
||||
*Note:* Currently this file *must* reside in the `~/.wtf/` directory.
|
||||
This is a <a href="https://github.com/senorprogrammer/wtf/issues/35">known bug</a>.
|
||||
`filePath` <br />
|
||||
The path to the file to be displayed in the widget. <br />
|
||||
|
||||
`position` <br />
|
||||
Defines where in the grid this module's widget will be displayed. <br />
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user