mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-1031 WIP
Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
parent
58318212f8
commit
aae98e40e3
57
app/app_manager.go
Normal file
57
app/app_manager.go
Normal file
@ -0,0 +1,57 @@
|
||||
package app
|
||||
|
||||
import "errors"
|
||||
|
||||
// WtfAppManager handles the instances of WtfApp, ensuring that they're displayed as requested
|
||||
type WtfAppManager struct {
|
||||
WtfApps []*WtfApp
|
||||
|
||||
selected int
|
||||
}
|
||||
|
||||
// NewAppManager creates and returns an instance of AppManager
|
||||
func NewAppManager() WtfAppManager {
|
||||
appMan := WtfAppManager{
|
||||
selected: 0,
|
||||
}
|
||||
|
||||
return appMan
|
||||
}
|
||||
|
||||
// AddApp adds a WtfApp to the collection of apps that the AppManager manages.
|
||||
// This app is then available for display onscreen.
|
||||
func (appMan *WtfAppManager) AddApp(wtfApp *WtfApp) error {
|
||||
appMan.WtfApps = append(appMan.WtfApps, wtfApp)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Current returns the currently-displaying instance of WtfApp
|
||||
func (appMan *WtfAppManager) Current() (*WtfApp, error) {
|
||||
if appMan.selected < 0 || appMan.selected > (len(appMan.WtfApps)-1) {
|
||||
return nil, errors.New("invalid app index selected")
|
||||
}
|
||||
|
||||
return appMan.WtfApps[appMan.selected], nil
|
||||
}
|
||||
|
||||
// Next cycles the WtfApps forward by one, making the next one in the list
|
||||
// the current one. If there are none after the current one, it wraps around.
|
||||
func (appMan *WtfAppManager) Next() (*WtfApp, error) {
|
||||
appMan.selected++
|
||||
if appMan.selected >= len(appMan.WtfApps) {
|
||||
appMan.selected = 0
|
||||
}
|
||||
|
||||
return appMan.Current()
|
||||
}
|
||||
|
||||
// Prev cycles the WtfApps backwards by one, making the previous one in the
|
||||
// list the current one. If there are none before the current one, it wraps around.
|
||||
func (appMan *WtfAppManager) Prev() (*WtfApp, error) {
|
||||
appMan.selected--
|
||||
if appMan.selected < 0 {
|
||||
appMan.selected = len(appMan.WtfApps) - 1
|
||||
}
|
||||
|
||||
return appMan.Current()
|
||||
}
|
@ -51,12 +51,11 @@ func NewWtfApp(tviewApp *tview.Application, config *config.Config, configFilePat
|
||||
wtfApp.widgets = MakeWidgets(wtfApp.TViewApp, wtfApp.pages, wtfApp.config)
|
||||
wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config)
|
||||
wtfApp.focusTracker = NewFocusTracker(wtfApp.TViewApp, wtfApp.widgets, wtfApp.config)
|
||||
wtfApp.validator = NewModuleValidator()
|
||||
|
||||
githubAPIKey := readGitHubAPIKey(wtfApp.config)
|
||||
wtfApp.ghUser = support.NewGitHubUser(githubAPIKey)
|
||||
|
||||
wtfApp.validator = NewModuleValidator()
|
||||
|
||||
wtfApp.pages.AddPage("grid", wtfApp.display.Grid, true, true)
|
||||
|
||||
wtfApp.validator.Validate(wtfApp.widgets)
|
||||
@ -116,6 +115,11 @@ func (wtfApp *WtfApp) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
case tcell.KeyCtrlR:
|
||||
wtfApp.refreshAllWidgets()
|
||||
return nil
|
||||
case tcell.KeyCtrlSpace:
|
||||
// FIXME: This can't reside in the app, the app doesn't know about
|
||||
// the AppManager. The AppManager needs to catch this one
|
||||
fmt.Println("Next app")
|
||||
return nil
|
||||
case tcell.KeyTab:
|
||||
wtfApp.focusTracker.Next()
|
||||
case tcell.KeyBacktab:
|
||||
|
16
main.go
16
main.go
@ -72,10 +72,18 @@ func main() {
|
||||
openURLUtil := utils.ToStrs(config.UList("wtf.openUrlUtil", []interface{}{}))
|
||||
utils.Init(openFileUtil, openURLUtil)
|
||||
|
||||
apps := []app.WtfApp{}
|
||||
app := makeWtfApp(config, flags.Config)
|
||||
apps = append(apps, app)
|
||||
/* Initialize the App Manager */
|
||||
|
||||
wtfApp := makeWtfApp(config, flags.Config)
|
||||
|
||||
appMan := app.NewAppManager()
|
||||
appMan.AddApp(&wtfApp)
|
||||
|
||||
currentApp, err := appMan.Current()
|
||||
if err != nil {
|
||||
fmt.Printf("\n%s %v\n", aurora.Red("ERROR"), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
currentApp := apps[0]
|
||||
currentApp.Run()
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package gitlabtodo
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help widget")
|
||||
widget.SetKeyboardChar("r", widget.Refresh, "Refresh widget")
|
||||
widget.InitializeRefreshKeyboardControl(widget.Refresh)
|
||||
|
||||
widget.SetKeyboardChar("j", widget.Next, "Select next item")
|
||||
widget.SetKeyboardChar("k", widget.Prev, "Select previous item")
|
||||
widget.SetKeyboardChar("o", widget.openTodo, "Open todo in browser")
|
||||
|
@ -1,6 +1,5 @@
|
||||
package uptimerobot
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help widget")
|
||||
widget.SetKeyboardChar("r", widget.Refresh, "Refresh widget")
|
||||
widget.InitializeRefreshKeyboardControl(widget.Refresh)
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ type TextWidget struct {
|
||||
*KeyboardWidget
|
||||
|
||||
View *tview.TextView
|
||||
|
||||
tviewApp *tview.Application
|
||||
}
|
||||
|
||||
// NewTextWidget creates and returns an instance of TextWidget
|
||||
@ -21,6 +23,8 @@ func NewTextWidget(tviewApp *tview.Application, pages *tview.Pages, commonSettin
|
||||
widget := TextWidget{
|
||||
Base: NewBase(commonSettings),
|
||||
KeyboardWidget: NewKeyboardWidget(tviewApp, pages, commonSettings),
|
||||
|
||||
tviewApp: tviewApp,
|
||||
}
|
||||
|
||||
widget.View = widget.createView(widget.bordered)
|
||||
@ -39,6 +43,7 @@ func (widget *TextWidget) TextView() *tview.TextView {
|
||||
}
|
||||
|
||||
func (widget *TextWidget) Redraw(data func() (string, string, bool)) {
|
||||
// FIXME: This is coming from KeyboardWidget, which seems wrong
|
||||
widget.tviewApp.QueueUpdateDraw(func() {
|
||||
title, content, wrap := data()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user