From 2430fe9f56ec7545d24a0705f5e1b45a910ff206 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Mon, 23 Nov 2020 21:55:10 -0800 Subject: [PATCH] Opening docs in browser is working, but only for keyboard modules This needs to work for all modules, which means effectively every module just became a keyboard module, if it is focusable. That's an interesting development. Signed-off-by: Chris Cummer --- view/keyboard_widget.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/view/keyboard_widget.go b/view/keyboard_widget.go index 270c7706..a516eb26 100644 --- a/view/keyboard_widget.go +++ b/view/keyboard_widget.go @@ -7,6 +7,7 @@ import ( "github.com/gdamore/tcell" "github.com/rivo/tview" "github.com/wtfutil/wtf/cfg" + "github.com/wtfutil/wtf/utils" ) type helpItem struct { @@ -80,6 +81,7 @@ func (widget *KeyboardWidget) SetKeyboardKey(key tcell.Key, fn func(), helpText // all widgets that accept keyboard input func (widget *KeyboardWidget) InitializeCommonControls(refreshFunc func()) { widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt") + widget.SetKeyboardChar("\\", widget.OpenDocs, "Open the docs in a browser") if refreshFunc != nil { widget.SetKeyboardChar("r", refreshFunc, "Refresh widget") @@ -127,10 +129,18 @@ func (widget *KeyboardWidget) HelpText() string { return str } +// OpenDocs opens the module docs in a browser +func (widget *KeyboardWidget) OpenDocs() { + url := "https://wtfutil.com/modules/" + widget.settings.Name + utils.OpenFile(url) +} + +// SetView assigns the passed-in tview.TextView view to this widget func (widget *KeyboardWidget) SetView(view *tview.TextView) { widget.view = view } +// ShowHelp displays the modal help dialog for a module func (widget *KeyboardWidget) ShowHelp() { closeFunc := func() { widget.pages.RemovePage("help")