mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
There is already default handling of title. Remove instances where people are unknowingly overriding it For instances where we want to set special things, make sure to use CommonSettings.Title, so people can still override
77 lines
1.6 KiB
Smarty
77 lines
1.6 KiB
Smarty
// Package {{(Lower .Name)}}
|
|
package {{(Lower .Name)}}
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gdamore/tcell"
|
|
"github.com/rivo/tview"
|
|
"github.com/wtfutil/wtf/wtf"
|
|
)
|
|
|
|
const HelpText = `
|
|
Keyboard commands for {{(Title .Name)}}:
|
|
`
|
|
|
|
type Widget struct {
|
|
wtf.HelpfulWidget
|
|
wtf.TextWidget
|
|
|
|
app *tview.Application
|
|
settings *Settings
|
|
}
|
|
|
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
|
widget := Widget{
|
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
|
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
|
|
|
app: app,
|
|
settings: settings,
|
|
}
|
|
|
|
widget.HelpfulWidget.SetView(widget.View)
|
|
widget.unselect()
|
|
|
|
widget.View.SetScrollable(true)
|
|
widget.View.SetRegions(true)
|
|
widget.View.SetInputCapture(widget.keyboardIntercept)
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
|
|
// The last call should always be to the display function
|
|
widget.app.QueueUpdateDraw(func() {
|
|
widget.display()
|
|
})
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) display() {
|
|
widget.View.SetWrap(false)
|
|
|
|
widget.View.Clear()
|
|
widget.View.SetText("Some Text")
|
|
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
|
|
}
|
|
|
|
func (widget *Widget) unselect() {
|
|
widget.selected = -1
|
|
widget.display()
|
|
}
|
|
|
|
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
|
// This switch statement could handle alphanumeric keys
|
|
switch string(event.Rune()) {
|
|
}
|
|
|
|
// This switch statement could handle events like the "enter" key
|
|
switch event.Key() {
|
|
}
|
|
}
|