1
0
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:
Chris Cummer
2018-05-11 12:28:01 -07:00
parent 89b1b0f517
commit 8e46547d1c
3 changed files with 13 additions and 9 deletions

View File

@@ -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))
}
}