mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Make github a multisource widget
Note, that this is a backwards incompatible change Previous config: ``` repositories: wtf: "wtfutil" ``` New Config: ``` repositories: - "wtfutil/wtf" ```
This commit is contained in:
parent
cbb147f41e
commit
c35034d587
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
"github.com/wtfutil/wtf/cfg"
|
"github.com/wtfutil/wtf/cfg"
|
||||||
|
"github.com/wtfutil/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultTitle = "GitHub"
|
const defaultTitle = "GitHub"
|
||||||
@ -15,7 +16,7 @@ type Settings struct {
|
|||||||
apiKey string
|
apiKey string
|
||||||
baseURL string
|
baseURL string
|
||||||
enableStatus bool
|
enableStatus bool
|
||||||
repositories map[string]interface{}
|
repositories []string
|
||||||
uploadURL string
|
uploadURL string
|
||||||
username string
|
username string
|
||||||
}
|
}
|
||||||
@ -28,7 +29,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
|||||||
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_GITHUB_TOKEN")),
|
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_GITHUB_TOKEN")),
|
||||||
baseURL: ymlConfig.UString("baseURL", os.Getenv("WTF_GITHUB_BASE_URL")),
|
baseURL: ymlConfig.UString("baseURL", os.Getenv("WTF_GITHUB_BASE_URL")),
|
||||||
enableStatus: ymlConfig.UBool("enableStatus", false),
|
enableStatus: ymlConfig.UBool("enableStatus", false),
|
||||||
repositories: ymlConfig.UMap("repositories"),
|
repositories: wtf.ToStrs(ymlConfig.UList("repositories")),
|
||||||
uploadURL: ymlConfig.UString("uploadURL", os.Getenv("WTF_GITHUB_UPLOAD_URL")),
|
uploadURL: ymlConfig.UString("uploadURL", os.Getenv("WTF_GITHUB_UPLOAD_URL")),
|
||||||
username: ymlConfig.UString("username"),
|
username: ymlConfig.UString("username"),
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
package github
|
package github
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
|
wtf.MultiSourceWidget
|
||||||
wtf.KeyboardWidget
|
wtf.KeyboardWidget
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
GithubRepos []*GithubRepo
|
GithubRepos []*GithubRepo
|
||||||
Idx int
|
|
||||||
|
|
||||||
app *tview.Application
|
app *tview.Application
|
||||||
settings *Settings
|
settings *Settings
|
||||||
@ -19,10 +21,9 @@ type Widget struct {
|
|||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
|
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
|
||||||
|
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "repository", "repositories"),
|
||||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||||
|
|
||||||
Idx: 0,
|
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
}
|
}
|
||||||
@ -31,6 +32,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
|
|
||||||
widget.initializeKeyboardControls()
|
widget.initializeKeyboardControls()
|
||||||
widget.View.SetInputCapture(widget.InputCapture)
|
widget.View.SetInputCapture(widget.InputCapture)
|
||||||
|
widget.SetDisplayFunction(widget.display)
|
||||||
|
|
||||||
widget.KeyboardWidget.SetView(widget.View)
|
widget.KeyboardWidget.SetView(widget.View)
|
||||||
|
|
||||||
@ -44,26 +46,6 @@ func (widget *Widget) Refresh() {
|
|||||||
repo.Refresh()
|
repo.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.app.QueueUpdateDraw(func() {
|
|
||||||
widget.display()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) Next() {
|
|
||||||
widget.Idx = widget.Idx + 1
|
|
||||||
if widget.Idx == len(widget.GithubRepos) {
|
|
||||||
widget.Idx = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.display()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) Prev() {
|
|
||||||
widget.Idx = widget.Idx - 1
|
|
||||||
if widget.Idx < 0 {
|
|
||||||
widget.Idx = len(widget.GithubRepos) - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.display()
|
widget.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,13 +55,15 @@ func (widget *Widget) HelpText() string {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) buildRepoCollection(repoData map[string]interface{}) []*GithubRepo {
|
func (widget *Widget) buildRepoCollection(repoData []string) []*GithubRepo {
|
||||||
githubRepos := []*GithubRepo{}
|
githubRepos := []*GithubRepo{}
|
||||||
|
|
||||||
for name, owner := range repoData {
|
for _, repo := range repoData {
|
||||||
|
split := strings.Split(repo, "/")
|
||||||
|
owner, name := split[0], split[1]
|
||||||
repo := NewGithubRepo(
|
repo := NewGithubRepo(
|
||||||
name,
|
name,
|
||||||
owner.(string),
|
owner,
|
||||||
widget.settings.apiKey,
|
widget.settings.apiKey,
|
||||||
widget.settings.baseURL,
|
widget.settings.baseURL,
|
||||||
widget.settings.uploadURL,
|
widget.settings.uploadURL,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user