mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Simplify the view loading for the keyboard widget
Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
parent
4a820dd0e5
commit
f9a06540f1
@ -40,8 +40,6 @@ func main() {
|
||||
|
||||
generateWidgetFile(data)
|
||||
generateSettingsFile(data)
|
||||
|
||||
fmt.Println("Done")
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
@ -23,7 +23,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetScrollable(true)
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
|
||||
widget.Unselect()
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
widget.client = cdsclient.New(cdsclient.Config{
|
||||
Host: settings.apiURL,
|
||||
|
@ -42,8 +42,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.Unselect()
|
||||
widget.filters = []string{sdk.StatusWaiting, sdk.StatusBuilding}
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
widget.client = cdsclient.New(cdsclient.Config{
|
||||
Host: settings.apiURL,
|
||||
BuitinConsumerAuthenticationToken: settings.token,
|
||||
|
@ -42,8 +42,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.Unselect()
|
||||
widget.filters = []string{sdk.StatusWaiting, sdk.StatusBuilding}
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
widget.client = cdsclient.New(cdsclient.Config{
|
||||
Host: settings.apiURL,
|
||||
BuitinConsumerAuthenticationToken: settings.token,
|
||||
|
@ -27,8 +27,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.View.SetScrollable(true)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.View.SetScrollable(true)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
widget.SetRenderFunction(widget.display)
|
||||
|
||||
widget.createClient()
|
||||
|
@ -75,8 +75,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
widget.unselect()
|
||||
|
||||
return &widget
|
||||
|
@ -42,8 +42,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.GithubRepos = widget.buildRepoCollection(widget.settings.repositories)
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.View.SetRegions(true)
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
|
||||
@ -41,8 +42,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.Sources = widget.settings.repositories
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.Unselect()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Refresh)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetRegions(true)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -35,8 +35,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.View.SetScrollable(true)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -37,8 +37,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.SetDisplayFunction(widget.Refresh)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.View.SetWordWrap(true)
|
||||
widget.View.SetWrap(settings.wrapText)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.View.SetScrollable(true)
|
||||
widget.View.SetRegions(true)
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.Selected = -1
|
||||
widget.SetItemCount(0)
|
||||
|
@ -28,8 +28,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,6 @@ func firewallStateWindows() string {
|
||||
|
||||
fwStat := utils.ExecuteCommand(cmd)
|
||||
fwStat = strings.TrimSpace(fwStat) // Always sanitize PowerShell output: "3\r\n"
|
||||
//fmt.Printf("%d %q\n", len(fwStat), fwStat)
|
||||
|
||||
switch fwStat {
|
||||
case "3":
|
||||
|
@ -36,8 +36,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetWordWrap(true)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -126,8 +126,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetWordWrap(true)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return widget
|
||||
|
||||
}
|
||||
|
@ -46,8 +46,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.View.SetWordWrap(true)
|
||||
widget.View.SetWrap(settings.wrapText)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
go widget.watchForFileChanges()
|
||||
|
||||
return &widget
|
||||
|
@ -50,7 +50,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.View.SetRegions(true)
|
||||
widget.View.SetScrollable(true)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
widget.SetRenderFunction(widget.display)
|
||||
|
||||
return &widget
|
||||
|
@ -35,8 +35,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.initializeKeyboardControls()
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.display)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
go buildClient(&widget)
|
||||
|
||||
return &widget
|
||||
|
@ -27,8 +27,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
@ -39,8 +39,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetWordWrap(true)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.SetRenderFunction(widget.Render)
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ type BarGraph struct {
|
||||
maxStars int
|
||||
starChar string
|
||||
|
||||
Base
|
||||
KeyboardWidget
|
||||
*Base
|
||||
*KeyboardWidget
|
||||
|
||||
View *tview.TextView
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ type Base struct {
|
||||
|
||||
// NewBase creates and returns an instance of the Base module, the lowest-level
|
||||
// primitive module from which all others are derived
|
||||
func NewBase(app *tview.Application, commonSettings *cfg.Common) Base {
|
||||
base := Base{
|
||||
func NewBase(app *tview.Application, commonSettings *cfg.Common) *Base {
|
||||
base := &Base{
|
||||
commonSettings: commonSettings,
|
||||
|
||||
app: app,
|
||||
|
@ -32,8 +32,8 @@ type KeyboardWidget struct {
|
||||
}
|
||||
|
||||
// NewKeyboardWidget creates and returns a new instance of KeyboardWidget
|
||||
func NewKeyboardWidget(app *tview.Application, pages *tview.Pages, settings *cfg.Common) KeyboardWidget {
|
||||
keyWidget := KeyboardWidget{
|
||||
func NewKeyboardWidget(app *tview.Application, pages *tview.Pages, settings *cfg.Common) *KeyboardWidget {
|
||||
keyWidget := &KeyboardWidget{
|
||||
app: app,
|
||||
pages: pages,
|
||||
settings: settings,
|
||||
@ -50,6 +50,17 @@ func NewKeyboardWidget(app *tview.Application, pages *tview.Pages, settings *cfg
|
||||
|
||||
/* -------------------- Exported Functions --------------------- */
|
||||
|
||||
// AssignedChars returns a list of all the text characters assigned to an operation
|
||||
func (widget *KeyboardWidget) AssignedChars() []string {
|
||||
chars := []string{}
|
||||
|
||||
for char := range widget.charMap {
|
||||
chars = append(chars, char)
|
||||
}
|
||||
|
||||
return chars
|
||||
}
|
||||
|
||||
// HelpText returns the help text and keyboard command info for this widget
|
||||
func (widget *KeyboardWidget) HelpText() string {
|
||||
str := " [green::b]Keyboard commands for " + strings.Title(widget.settings.Module.Type) + "[white]\n\n"
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
|
||||
func test() {}
|
||||
|
||||
func testKeyboardWidget() KeyboardWidget {
|
||||
func testKeyboardWidget() *KeyboardWidget {
|
||||
keyWid := NewKeyboardWidget(
|
||||
tview.NewApplication(),
|
||||
tview.NewPages(),
|
||||
@ -118,25 +118,25 @@ func Test_SetKeyboardKey(t *testing.T) {
|
||||
func Test_InputCapture(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
before func(keyWid KeyboardWidget) KeyboardWidget
|
||||
before func(keyWid *KeyboardWidget) *KeyboardWidget
|
||||
event *tcell.EventKey
|
||||
expected *tcell.EventKey
|
||||
}{
|
||||
{
|
||||
name: "with nil event",
|
||||
before: func(keyWid KeyboardWidget) KeyboardWidget { return keyWid },
|
||||
before: func(keyWid *KeyboardWidget) *KeyboardWidget { return keyWid },
|
||||
event: nil,
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
name: "with undefined event",
|
||||
before: func(keyWid KeyboardWidget) KeyboardWidget { return keyWid },
|
||||
before: func(keyWid *KeyboardWidget) *KeyboardWidget { return keyWid },
|
||||
event: tcell.NewEventKey(tcell.KeyRune, 'a', tcell.ModNone),
|
||||
expected: tcell.NewEventKey(tcell.KeyRune, 'a', tcell.ModNone),
|
||||
},
|
||||
{
|
||||
name: "with defined event and char handler",
|
||||
before: func(keyWid KeyboardWidget) KeyboardWidget {
|
||||
before: func(keyWid *KeyboardWidget) *KeyboardWidget {
|
||||
keyWid.SetKeyboardChar("a", test, "help")
|
||||
return keyWid
|
||||
},
|
||||
@ -145,7 +145,7 @@ func Test_InputCapture(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "with defined event and key handler",
|
||||
before: func(keyWid KeyboardWidget) KeyboardWidget {
|
||||
before: func(keyWid *KeyboardWidget) *KeyboardWidget {
|
||||
keyWid.SetKeyboardKey(tcell.KeyRune, test, "help")
|
||||
return keyWid
|
||||
},
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
|
||||
// TextWidget defines the data necessary to make a text widget
|
||||
type TextWidget struct {
|
||||
Base
|
||||
KeyboardWidget
|
||||
*Base
|
||||
*KeyboardWidget
|
||||
|
||||
View *tview.TextView
|
||||
}
|
||||
@ -24,7 +24,9 @@ func NewTextWidget(app *tview.Application, pages *tview.Pages, commonSettings *c
|
||||
}
|
||||
|
||||
widget.View = widget.createView(widget.bordered)
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
widget.View.SetInputCapture(widget.KeyboardWidget.InputCapture)
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return widget
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user