mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
added highlighting and opening of pull requests
This commit is contained in:
parent
c3a54de181
commit
55937c4c40
@ -2,6 +2,8 @@ package github
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"net/url"
|
||||
|
||||
"github.com/google/go-github/v26/github"
|
||||
)
|
||||
@ -36,20 +38,31 @@ func (widget *Widget) content() (string, string, bool) {
|
||||
func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string {
|
||||
prs := repo.myPullRequests(username, widget.settings.enableStatus)
|
||||
|
||||
u, _ := url.Parse(*repo.RemoteRepo.HTMLURL + "/pull/")
|
||||
numSelections := widget.GetSelected()
|
||||
|
||||
if len(prs) == 0 {
|
||||
return " [grey]none[white]\n"
|
||||
}
|
||||
|
||||
str := ""
|
||||
for _, pr := range prs {
|
||||
str += fmt.Sprintf(" %s[green]%4d[white] %s\n", widget.mergeString(pr), *pr.Number, *pr.Title)
|
||||
// str += fmt.Sprintf(` %s[green]%4d[white] %s\n`, widget.mergeString(pr), *pr.Number, *pr.Title)
|
||||
str += fmt.Sprintf(`["%d"]%s[""]`, numSelections, u.String() + strconv.Itoa(*pr.Number))
|
||||
str += "\n"
|
||||
numSelections++
|
||||
}
|
||||
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPage int) string {
|
||||
res := repo.customIssueQuery(filter, perPage)
|
||||
|
||||
u, _ := url.Parse(*repo.RemoteRepo.HTMLURL + "/pull/")
|
||||
numSelections := widget.GetSelected()
|
||||
|
||||
if res == nil {
|
||||
return " [grey]Invalid Query[white]\n"
|
||||
}
|
||||
@ -60,8 +73,14 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag
|
||||
|
||||
str := ""
|
||||
for _, issue := range res.Issues {
|
||||
str += fmt.Sprintf(" [green]%4d[white] %s\n", *issue.Number, *issue.Title)
|
||||
// str += fmt.Sprintf(" [green]%4d[white] %s\n", *issue.Number, *issue.Title)
|
||||
str += fmt.Sprintf(`["%d"]%s[""]`, numSelections, u.String() + strconv.Itoa(*issue.Number))
|
||||
str += "\n"
|
||||
numSelections++
|
||||
}
|
||||
|
||||
widget.SetItemCount(numSelections)
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,9 @@ func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("h", widget.PrevSource, "Select previous source")
|
||||
widget.SetKeyboardChar("o", widget.openRepo, "Open item in browser")
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.Next, "Select next source")
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.Prev, "Select next source")
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next source")
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous source")
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openRepo, "Open item in browser")
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openPr, "Open item in browser")
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ package github
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"strconv"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/utils"
|
||||
"github.com/wtfutil/wtf/view"
|
||||
)
|
||||
|
||||
@ -15,6 +17,8 @@ type Widget struct {
|
||||
GithubRepos []*GithubRepo
|
||||
|
||||
settings *Settings
|
||||
Selected int
|
||||
maxItems int
|
||||
}
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
@ -27,11 +31,14 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
}
|
||||
|
||||
widget.GithubRepos = widget.buildRepoCollection(widget.settings.repositories)
|
||||
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetRegions(true)
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
|
||||
widget.Unselect()
|
||||
|
||||
widget.Sources = widget.settings.repositories
|
||||
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
@ -40,6 +47,39 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
}
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
func (widget *Widget) SetItemCount(items int) {
|
||||
widget.maxItems = items
|
||||
}
|
||||
|
||||
func (widget *Widget) GetSelected() int {
|
||||
if widget.Selected < 0 {
|
||||
return 0
|
||||
}
|
||||
return widget.Selected
|
||||
}
|
||||
|
||||
func (widget *Widget) Next() {
|
||||
widget.Selected++
|
||||
if widget.Selected >= widget.maxItems {
|
||||
widget.Selected = 0
|
||||
}
|
||||
widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight()
|
||||
}
|
||||
|
||||
func (widget *Widget) Prev() {
|
||||
widget.Selected--
|
||||
if widget.Selected < 0 {
|
||||
widget.Selected = widget.maxItems - 1
|
||||
}
|
||||
widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight()
|
||||
}
|
||||
|
||||
func (widget *Widget) Unselect() {
|
||||
widget.Selected = -1
|
||||
if widget.DisplayFunction != nil {
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
for _, repo := range widget.GithubRepos {
|
||||
@ -87,6 +127,13 @@ func (widget *Widget) currentGithubRepo() *GithubRepo {
|
||||
return widget.GithubRepos[widget.Idx]
|
||||
}
|
||||
|
||||
func (widget *Widget) openPr() {
|
||||
currentSelection := widget.View.GetHighlights()
|
||||
if widget.Selected >= 0 && currentSelection[0] != "" {
|
||||
utils.OpenFile(widget.View.GetRegionText(currentSelection[0]))
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) openRepo() {
|
||||
repo := widget.currentGithubRepo()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user