mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Move common nav controls into MultiSourceWidget
This commit is contained in:
parent
e760561027
commit
ad431ee3a7
@ -36,11 +36,12 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
MultiSourceWidget: wtf.NewMultiSourceWidget(),
|
MultiSourceWidget: wtf.NewMultiSourceWidget("textfile", "filePath", "filePaths"),
|
||||||
TextWidget: wtf.NewTextWidget("TextFile", "textfile", true),
|
TextWidget: wtf.NewTextWidget("TextFile", "textfile", true),
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.LoadSources("textfile", "filePath", "filePaths")
|
widget.LoadSources()
|
||||||
|
widget.SetDisplayFunction(widget.display)
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
|
|
||||||
@ -53,24 +54,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
|||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Next() {
|
// Refresh is called on the interval and refreshes the data
|
||||||
widget.Idx = widget.Idx + 1
|
|
||||||
if widget.Idx == len(widget.Sources) {
|
|
||||||
widget.Idx = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.display()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) Prev() {
|
|
||||||
widget.Idx = widget.Idx - 1
|
|
||||||
if widget.Idx < 0 {
|
|
||||||
widget.Idx = len(widget.Sources) - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.display()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.UpdateRefreshedAt()
|
widget.UpdateRefreshedAt()
|
||||||
widget.display()
|
widget.display()
|
||||||
|
@ -35,13 +35,15 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
MultiSourceWidget: wtf.NewMultiSourceWidget(),
|
MultiSourceWidget: wtf.NewMultiSourceWidget("twitter", "screenName", "screenNames"),
|
||||||
TextWidget: wtf.NewTextWidget("Twitter", "twitter", true),
|
TextWidget: wtf.NewTextWidget("Twitter", "twitter", true),
|
||||||
|
|
||||||
idx: 0,
|
idx: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.LoadSources("twitter", "screenName", "screenNames")
|
widget.LoadSources()
|
||||||
|
widget.SetDisplayFunction(widget.display)
|
||||||
|
|
||||||
widget.client = NewClient()
|
widget.client = NewClient()
|
||||||
|
|
||||||
widget.View.SetBorderPadding(1, 1, 1, 1)
|
widget.View.SetBorderPadding(1, 1, 1, 1)
|
||||||
@ -54,24 +56,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
|||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Next() {
|
// Refresh is called on the interval and refreshes the data
|
||||||
widget.Idx = widget.Idx + 1
|
|
||||||
if widget.Idx == len(widget.Sources) {
|
|
||||||
widget.Idx = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.display()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) Prev() {
|
|
||||||
widget.Idx = widget.Idx - 1
|
|
||||||
if widget.Idx < 0 {
|
|
||||||
widget.Idx = len(widget.Sources) - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.display()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.UpdateRefreshedAt()
|
widget.UpdateRefreshedAt()
|
||||||
widget.display()
|
widget.display()
|
||||||
|
@ -5,12 +5,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MultiSourceWidget struct {
|
type MultiSourceWidget struct {
|
||||||
|
module string
|
||||||
|
singular string
|
||||||
|
plural string
|
||||||
|
|
||||||
|
DisplayFunction func()
|
||||||
Idx int
|
Idx int
|
||||||
Sources []string
|
Sources []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMultiSourceWidget() MultiSourceWidget {
|
func NewMultiSourceWidget(module, singular, plural string) MultiSourceWidget {
|
||||||
return MultiSourceWidget{}
|
return MultiSourceWidget{
|
||||||
|
module: module,
|
||||||
|
singular: singular,
|
||||||
|
plural: plural,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
@ -23,11 +32,11 @@ func (widget *MultiSourceWidget) CurrentSource() string {
|
|||||||
return widget.Sources[widget.Idx]
|
return widget.Sources[widget.Idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *MultiSourceWidget) LoadSources(module, singular, plural string) {
|
func (widget *MultiSourceWidget) LoadSources() {
|
||||||
var empty []interface{}
|
var empty []interface{}
|
||||||
|
|
||||||
s := fmt.Sprintf("wtf.mods.%s.%s", module, singular)
|
s := fmt.Sprintf("wtf.mods.%s.%s", widget.module, widget.singular)
|
||||||
p := fmt.Sprintf("wtf.mods.%s.%s", module, plural)
|
p := fmt.Sprintf("wtf.mods.%s.%s", widget.module, widget.plural)
|
||||||
|
|
||||||
single := Config.UString(s, "")
|
single := Config.UString(s, "")
|
||||||
multiple := Config.UList(p, empty)
|
multiple := Config.UList(p, empty)
|
||||||
@ -40,3 +49,29 @@ func (widget *MultiSourceWidget) LoadSources(module, singular, plural string) {
|
|||||||
|
|
||||||
widget.Sources = asStrs
|
widget.Sources = asStrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (widget *MultiSourceWidget) Next() {
|
||||||
|
widget.Idx = widget.Idx + 1
|
||||||
|
if widget.Idx == len(widget.Sources) {
|
||||||
|
widget.Idx = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if widget.DisplayFunction != nil {
|
||||||
|
widget.DisplayFunction()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *MultiSourceWidget) Prev() {
|
||||||
|
widget.Idx = widget.Idx - 1
|
||||||
|
if widget.Idx < 0 {
|
||||||
|
widget.Idx = len(widget.Sources) - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if widget.DisplayFunction != nil {
|
||||||
|
widget.DisplayFunction()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *MultiSourceWidget) SetDisplayFunction(displayFunc func()) {
|
||||||
|
widget.DisplayFunction = displayFunc
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user