mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add help modal to TextFile module
This commit is contained in:
parent
72f9543e75
commit
1baa884ce9
@ -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)
|
||||
}
|
||||
|
@ -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":
|
||||
|
Loading…
x
Reference in New Issue
Block a user