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
|
```yaml
|
||||||
textfile:
|
textfile:
|
||||||
enabled: true
|
enabled: true
|
||||||
filename: "notes.md"
|
filePath: "~/Desktop/notes.md"
|
||||||
position:
|
position:
|
||||||
top: 5
|
top: 5
|
||||||
left: 4
|
left: 4
|
||||||
@ -48,10 +48,8 @@ textfile:
|
|||||||
Determines whether or not this module is executed and if its data displayed onscreen. <br />
|
Determines whether or not this module is executed and if its data displayed onscreen. <br />
|
||||||
Values: `true`, `false`.
|
Values: `true`, `false`.
|
||||||
|
|
||||||
`filename` <br />
|
`filePath` <br />
|
||||||
The name of the file to be displayed in the widget. <br />
|
The path to 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>.
|
|
||||||
|
|
||||||
`position` <br />
|
`position` <br />
|
||||||
Defines where in the grid this module's widget will be displayed. <br />
|
Defines where in the grid this module's widget will be displayed. <br />
|
||||||
|
@ -2,6 +2,7 @@ package textfile
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
@ -33,7 +34,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
|||||||
TextWidget: wtf.NewTextWidget(" 📄 Text File ", "textfile", true),
|
TextWidget: wtf.NewTextWidget(" 📄 Text File ", "textfile", true),
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
filePath: Config.UString("wtf.mods.textfile.filename"),
|
filePath: Config.UString("wtf.mods.textfile.filePath"),
|
||||||
pages: pages,
|
pages: pages,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,12 +58,17 @@ func (widget *Widget) Refresh() {
|
|||||||
|
|
||||||
widget.View.Clear()
|
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 {
|
if err != nil {
|
||||||
fmt.Fprintf(widget.View, "%s", err)
|
fmt.Fprintf(widget.View, "%s", err)
|
||||||
} else {
|
} 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
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadFile(fileName string) (string, error) {
|
func ReadConfigFile(fileName string) (string, error) {
|
||||||
configDir, err := ConfigDir()
|
configDir, err := ConfigDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user