diff --git a/textfile/widget.go b/textfile/widget.go index 454a0642..430a59e9 100644 --- a/textfile/widget.go +++ b/textfile/widget.go @@ -4,6 +4,7 @@ import ( "fmt" "time" + "github.com/gdamore/tcell" "github.com/olebedev/config" "github.com/senorprogrammer/wtf/wtf" ) @@ -26,6 +27,8 @@ func NewWidget() *Widget { widget.View.SetWrap(true) widget.View.SetWordWrap(true) + widget.View.SetInputCapture(widget.keyboardIntercept) + return &widget } @@ -49,3 +52,14 @@ func (widget *Widget) Refresh() { fmt.Fprintf(widget.View, "%s", fileData) } } + +/* -------------------- Unexported Functions -------------------- */ +func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { + switch string(event.Rune()) { + case "o": + wtf.OpenFile(widget.FilePath) + return nil + } + + return event +} diff --git a/todo/widget.go b/todo/widget.go index 171f28ce..71174c1b 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -3,6 +3,7 @@ package todo import ( "fmt" "io/ioutil" + //"os/exec" "time" "github.com/gdamore/tcell" @@ -82,6 +83,11 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { case "n": // Add a new item return nil + case "o": + // Open the file + //widget.openFile() + wtf.OpenFile(widget.FilePath) + return nil } switch event.Key() { @@ -133,6 +139,14 @@ func (widget *Widget) load() { yaml.Unmarshal(fileData, &widget.list) } +//func (widget *Widget) openFile() { + //confDir, _ := wtf.ConfigDir() + //filePath := fmt.Sprintf("%s/%s", confDir, widget.FilePath) + + //cmd := exec.Command("open", filePath) + //wtf.ExecuteCommand(cmd) +//} + // persist writes the todo list to Yaml file func (widget *Widget) persist() { confDir, _ := wtf.ConfigDir() diff --git a/wtf/utils.go b/wtf/utils.go index 663fe5af..d35e563f 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -61,6 +61,14 @@ func NamesFromEmails(emails []string) []string { return names } +func OpenFile(path string) { + confDir, _ := ConfigDir() + filePath := fmt.Sprintf("%s/%s", confDir, path) + + cmd := exec.Command("open", filePath) + ExecuteCommand(cmd) +} + // PadRow returns a padding for a row to make it the full width of the containing widget. // Useful for ensurig row highlighting spans the full width (I suspect tcell has a better // way to do this, but I haven't yet found it)