diff --git a/textfile/widget.go b/textfile/widget.go index b4df86e5..4041b0f9 100644 --- a/textfile/widget.go +++ b/textfile/widget.go @@ -6,22 +6,35 @@ import ( "github.com/gdamore/tcell" "github.com/olebedev/config" + "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) // Config is a pointer to the global config object var Config *config.Config +const helpText = ` + Keyboard commands for Textfile: + + h: Show/hide this help window + o: Open the text file in the operating system +` + type Widget struct { wtf.TextWidget - FilePath string + app *tview.Application + filePath string + pages *tview.Pages } -func NewWidget() *Widget { +func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(" 📄 Text File ", "textfile", true), - FilePath: Config.UString("wtf.mods.textfile.filename"), + + app: app, + filePath: Config.UString("wtf.mods.textfile.filename"), + pages: pages, } widget.View.SetWrap(true) @@ -39,12 +52,12 @@ func (widget *Widget) Refresh() { return } - widget.View.SetTitle(fmt.Sprintf(" 📄 %s ", widget.FilePath)) + widget.View.SetTitle(fmt.Sprintf(" 📄 %s ", widget.filePath)) widget.RefreshedAt = time.Now() widget.View.Clear() - fileData, err := wtf.ReadFile(widget.FilePath) + fileData, err := wtf.ReadFile(widget.filePath) if err != nil { fmt.Fprintf(widget.View, "%s", err) @@ -54,12 +67,29 @@ func (widget *Widget) Refresh() { } /* -------------------- Unexported Functions -------------------- */ + func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { switch string(event.Rune()) { + case "h": + widget.showHelp() + return nil case "o": - wtf.OpenFile(widget.FilePath) + wtf.OpenFile(widget.filePath) return nil } return event } + +func (widget *Widget) showHelp() { + closeFunc := func() { + widget.pages.RemovePage("help") + widget.app.SetFocus(widget.View) + widget.Refresh() + } + + modal := wtf.NewBillboardModal(helpText, closeFunc) + + widget.pages.AddPage("help", modal, false, true) + widget.app.SetFocus(modal) +} diff --git a/todo/widget.go b/todo/widget.go index 2231ec7e..53fdedeb 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -18,7 +18,7 @@ var Config *config.Config const helpText = ` Keyboard commands for Todo: - h: Displays the help text + h: Show/hide this help window j: Select the next item in the list k: Select the previous item in the list n: Create a new list item @@ -27,7 +27,7 @@ const helpText = ` arrow down: Select the next item in the list arrow up: Select the previous item in the list - ctrl-d: delete selected item + ctrl-d: Delete the selected item esc: Unselect the todo list return: Edit selected item @@ -38,9 +38,9 @@ type Widget struct { wtf.TextWidget app *tview.Application - pages *tview.Pages filePath string list *List + pages *tview.Pages } func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { @@ -48,9 +48,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { TextWidget: wtf.NewTextWidget(" 📝 Todo ", "todo", true), app: app, - pages: pages, filePath: Config.UString("wtf.mods.todo.filename"), list: &List{selected: -1}, + pages: pages, } widget.init() @@ -111,7 +111,6 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { widget.display() return nil case "h": - // Show help menu widget.showHelp() return nil case "j": diff --git a/wtf.go b/wtf.go index d663b29d..0d6ab348 100644 --- a/wtf.go +++ b/wtf.go @@ -194,7 +194,7 @@ func main() { security.NewWidget(), status.NewWidget(), system.NewWidget(builtat, version), - textfile.NewWidget(), + textfile.NewWidget(app, pages), todo.NewWidget(app, pages), weather.NewWidget(), }