mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Todo and TextFile have keyboard short-cut to open file in OS
This commit is contained in:
parent
42559c396d
commit
ed52835650
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gdamore/tcell"
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
@ -26,6 +27,8 @@ func NewWidget() *Widget {
|
|||||||
widget.View.SetWrap(true)
|
widget.View.SetWrap(true)
|
||||||
widget.View.SetWordWrap(true)
|
widget.View.SetWordWrap(true)
|
||||||
|
|
||||||
|
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,3 +52,14 @@ func (widget *Widget) Refresh() {
|
|||||||
fmt.Fprintf(widget.View, "%s", fileData)
|
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
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@ package todo
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
//"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
@ -82,6 +83,11 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
case "n":
|
case "n":
|
||||||
// Add a new item
|
// Add a new item
|
||||||
return nil
|
return nil
|
||||||
|
case "o":
|
||||||
|
// Open the file
|
||||||
|
//widget.openFile()
|
||||||
|
wtf.OpenFile(widget.FilePath)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch event.Key() {
|
switch event.Key() {
|
||||||
@ -133,6 +139,14 @@ func (widget *Widget) load() {
|
|||||||
yaml.Unmarshal(fileData, &widget.list)
|
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
|
// persist writes the todo list to Yaml file
|
||||||
func (widget *Widget) persist() {
|
func (widget *Widget) persist() {
|
||||||
confDir, _ := wtf.ConfigDir()
|
confDir, _ := wtf.ConfigDir()
|
||||||
|
@ -61,6 +61,14 @@ func NamesFromEmails(emails []string) []string {
|
|||||||
return names
|
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.
|
// 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
|
// 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)
|
// way to do this, but I haven't yet found it)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user