From 55937c4c409267eedfd3e933291fb0ab1a320c3c Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 14:42:49 +0100 Subject: [PATCH 01/13] added highlighting and opening of pull requests --- modules/github/display.go | 23 ++++++++++++++++-- modules/github/keyboard.go | 4 +++- modules/github/widget.go | 49 +++++++++++++++++++++++++++++++++++++- 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index 2f890c3a..e4bdd46b 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -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 } diff --git a/modules/github/keyboard.go b/modules/github/keyboard.go index d3f39bec..d39a2c17 100644 --- a/modules/github/keyboard.go +++ b/modules/github/keyboard.go @@ -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") } diff --git a/modules/github/widget.go b/modules/github/widget.go index 8e3003fb..f7e3bdd2 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -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() From ccaca4f1c05aceebcccc9f68ee89f4eb1c84405c Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 15:04:34 +0100 Subject: [PATCH 02/13] using just the pr/issue number as highlighted --- modules/github/display.go | 21 +++++++++++---------- modules/github/keyboard.go | 7 +++++-- modules/github/widget.go | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index e4bdd46b..ae65398c 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -2,8 +2,6 @@ package github import ( "fmt" - "strconv" - "net/url" "github.com/google/go-github/v26/github" ) @@ -38,7 +36,6 @@ 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 { @@ -47,12 +44,12 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s str := "" for _, pr := range prs { - // 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 += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, numSelections, *pr.Number, *pr.Title) str += "\n" numSelections++ } + widget.SetItemCount(numSelections) return str } @@ -60,7 +57,6 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s 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 { @@ -73,8 +69,7 @@ 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(`["%d"]%s[""]`, numSelections, u.String() + strconv.Itoa(*issue.Number)) + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, numSelections, *issue.Number, *issue.Title) str += "\n" numSelections++ } @@ -84,18 +79,24 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag return str } -func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string { +func (widget *Widget) displayMyReviewRequests(repo*GithubRepo, username string) string { prs := repo.myReviewRequests(username) + numSelections := widget.GetSelected() + if len(prs) == 0 { return " [grey]none[white]\n" } str := "" for _, pr := range prs { - str += fmt.Sprintf(" [green]%4d[white] %s\n", *pr.Number, *pr.Title) + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, numSelections, *pr.Number, *pr.Title) + str += "\n" + numSelections++ } + widget.SetItemCount(numSelections) + return str } diff --git a/modules/github/keyboard.go b/modules/github/keyboard.go index d39a2c17..e0ce5046 100644 --- a/modules/github/keyboard.go +++ b/modules/github/keyboard.go @@ -7,13 +7,16 @@ import ( func (widget *Widget) initializeKeyboardControls() { widget.InitializeCommonControls(widget.Refresh) + widget.SetKeyboardChar("j", widget.Next, "Select next item") + widget.SetKeyboardChar("k", widget.Prev, "Select previous item") widget.SetKeyboardChar("l", widget.NextSource, "Select next source") 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.KeyDown, widget.Next, "Select next item") + widget.SetKeyboardKey(tcell.KeyUp, widget.Prev, "Select previous item") widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next source") widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous source") widget.SetKeyboardKey(tcell.KeyEnter, widget.openPr, "Open item in browser") + widget.SetKeyboardKey(tcell.KeyBackspace, widget.openRepo, "Open item in browser") } diff --git a/modules/github/widget.go b/modules/github/widget.go index f7e3bdd2..4d8dbb73 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -130,7 +130,8 @@ func (widget *Widget) currentGithubRepo() *GithubRepo { func (widget *Widget) openPr() { currentSelection := widget.View.GetHighlights() if widget.Selected >= 0 && currentSelection[0] != "" { - utils.OpenFile(widget.View.GetRegionText(currentSelection[0])) + url := (*widget.currentGithubRepo().RemoteRepo.HTMLURL + "/pull/" + widget.View.GetRegionText(currentSelection[0])) + utils.OpenFile(url) } } From d0308142a3f4407170f6b195ce3f2199bbaa4ed8 Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 15:34:35 +0100 Subject: [PATCH 03/13] changing keybind --- modules/github/keyboard.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/github/keyboard.go b/modules/github/keyboard.go index e0ce5046..f8650566 100644 --- a/modules/github/keyboard.go +++ b/modules/github/keyboard.go @@ -18,5 +18,5 @@ func (widget *Widget) initializeKeyboardControls() { widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next source") widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous source") widget.SetKeyboardKey(tcell.KeyEnter, widget.openPr, "Open item in browser") - widget.SetKeyboardKey(tcell.KeyBackspace, widget.openRepo, "Open item in browser") + widget.SetKeyboardKey(tcell.KeyInsert, widget.openRepo, "Open item in browser") } From d212037ff5677380688b6bbeeb74fadb15cff8bf Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 16:04:37 +0100 Subject: [PATCH 04/13] cleaning up --- modules/github/display.go | 2 +- modules/github/keyboard.go | 2 +- modules/github/widget.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index ae65398c..e3241d61 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -79,7 +79,7 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag return str } -func (widget *Widget) displayMyReviewRequests(repo*GithubRepo, username string) string { +func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string { prs := repo.myReviewRequests(username) numSelections := widget.GetSelected() diff --git a/modules/github/keyboard.go b/modules/github/keyboard.go index f8650566..60229f58 100644 --- a/modules/github/keyboard.go +++ b/modules/github/keyboard.go @@ -17,6 +17,6 @@ func (widget *Widget) initializeKeyboardControls() { widget.SetKeyboardKey(tcell.KeyUp, widget.Prev, "Select previous item") widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next source") widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous source") - widget.SetKeyboardKey(tcell.KeyEnter, widget.openPr, "Open item in browser") + widget.SetKeyboardKey(tcell.KeyEnter, widget.openPr, "Open PR in browser") widget.SetKeyboardKey(tcell.KeyInsert, widget.openRepo, "Open item in browser") } diff --git a/modules/github/widget.go b/modules/github/widget.go index 4d8dbb73..dce52c3a 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -31,7 +31,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.View.SetInputCapture(widget.InputCapture) From 70c5e02ca98c5844aaae481415cc87577f8bbffd Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 16:39:33 +0100 Subject: [PATCH 05/13] fixing an issue where after a refresh the maxItems would be greater than the actual amount --- modules/github/display.go | 2 ++ modules/github/widget.go | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index e3241d61..d896f51c 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -12,6 +12,8 @@ func (widget *Widget) display() { func (widget *Widget) content() (string, string, bool) { repo := widget.currentGithubRepo() + widget.Unselect() + title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo)) if repo == nil { return title, " GitHub repo data is unavailable ", false diff --git a/modules/github/widget.go b/modules/github/widget.go index dce52c3a..8a2f6403 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -76,9 +76,6 @@ func (widget *Widget) Prev() { func (widget *Widget) Unselect() { widget.Selected = -1 - if widget.DisplayFunction != nil { - widget.SetDisplayFunction(widget.display) - } } func (widget *Widget) Refresh() { From 10f020405f12e5e3ed828f6eef3136dc1b588c64 Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 17:08:27 +0100 Subject: [PATCH 06/13] instead of resetting the selected each refresh now setting the max each refresh --- modules/github/display.go | 34 ++++++++++++++-------------------- modules/github/keyboard.go | 1 + modules/github/widget.go | 6 ++++++ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index d896f51c..45e38ac0 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -12,7 +12,6 @@ func (widget *Widget) display() { func (widget *Widget) content() (string, string, bool) { repo := widget.currentGithubRepo() - widget.Unselect() title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo)) if repo == nil { @@ -38,20 +37,17 @@ func (widget *Widget) content() (string, string, bool) { func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string { prs := repo.myPullRequests(username, widget.settings.enableStatus) - numSelections := widget.GetSelected() - if len(prs) == 0 { return " [grey]none[white]\n" } - str := "" - for _, pr := range prs { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, numSelections, *pr.Number, *pr.Title) - str += "\n" - numSelections++ - } + widget.SetItemCount(len(prs)) - widget.SetItemCount(numSelections) + str := "" + for idx, pr := range prs { + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, idx, *pr.Number, *pr.Title) + str += "\n" + } return str } @@ -59,7 +55,7 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPage int) string { res := repo.customIssueQuery(filter, perPage) - numSelections := widget.GetSelected() + maxItems := widget.GetItemCount() if res == nil { return " [grey]Invalid Query[white]\n" @@ -70,13 +66,12 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag } str := "" - for _, issue := range res.Issues { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, numSelections, *issue.Number, *issue.Title) + for idx, issue := range res.Issues { + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx, *issue.Number, *issue.Title) str += "\n" - numSelections++ } - widget.SetItemCount(numSelections) + widget.SetItemCount(maxItems + len(res.Issues)) return str } @@ -84,20 +79,19 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string { prs := repo.myReviewRequests(username) - numSelections := widget.GetSelected() + maxItems := widget.GetItemCount() if len(prs) == 0 { return " [grey]none[white]\n" } str := "" - for _, pr := range prs { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, numSelections, *pr.Number, *pr.Title) + for idx, pr := range prs { + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx, *pr.Number, *pr.Title) str += "\n" - numSelections++ } - widget.SetItemCount(numSelections) + widget.SetItemCount(maxItems + len(prs)) return str } diff --git a/modules/github/keyboard.go b/modules/github/keyboard.go index 60229f58..ce3d2ace 100644 --- a/modules/github/keyboard.go +++ b/modules/github/keyboard.go @@ -19,4 +19,5 @@ func (widget *Widget) initializeKeyboardControls() { widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous source") widget.SetKeyboardKey(tcell.KeyEnter, widget.openPr, "Open PR in browser") widget.SetKeyboardKey(tcell.KeyInsert, widget.openRepo, "Open item in browser") + widget.SetKeyboardKey(tcell.KeyEsc, widget.Unselect, "Clear selection") } diff --git a/modules/github/widget.go b/modules/github/widget.go index 8a2f6403..380b07b6 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -51,6 +51,10 @@ func (widget *Widget) SetItemCount(items int) { widget.maxItems = items } +func (widget *Widget) GetItemCount() int { + return widget.maxItems +} + func (widget *Widget) GetSelected() int { if widget.Selected < 0 { return 0 @@ -76,6 +80,7 @@ func (widget *Widget) Prev() { func (widget *Widget) Unselect() { widget.Selected = -1 + widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight() } func (widget *Widget) Refresh() { @@ -83,6 +88,7 @@ func (widget *Widget) Refresh() { repo.Refresh() } + widget.SetItemCount(0) widget.display() } From 925930f76f7d2a91b09b1251296ce3d1beeb5ee6 Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 17:24:13 +0100 Subject: [PATCH 07/13] addressing performance --- modules/github/display.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index 45e38ac0..53b3fd00 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -36,12 +36,14 @@ func (widget *Widget) content() (string, string, bool) { func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string { prs := repo.myPullRequests(username, widget.settings.enableStatus) + + prLength := len(prs) - if len(prs) == 0 { + if prLength == 0 { return " [grey]none[white]\n" } - widget.SetItemCount(len(prs)) + widget.SetItemCount(prLength) str := "" for idx, pr := range prs { @@ -55,23 +57,25 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPage int) string { res := repo.customIssueQuery(filter, perPage) - maxItems := widget.GetItemCount() - if res == nil { return " [grey]Invalid Query[white]\n" } - if len(res.Issues) == 0 { + issuesLength := len(res.Issues) + + if issuesLength == 0 { return " [grey]none[white]\n" } + + maxItems := widget.GetItemCount() str := "" for idx, issue := range res.Issues { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx, *issue.Number, *issue.Title) + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx , *issue.Number, *issue.Title) str += "\n" } - widget.SetItemCount(maxItems + len(res.Issues)) + widget.SetItemCount(maxItems + issuesLength) return str } @@ -79,19 +83,21 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string { prs := repo.myReviewRequests(username) - maxItems := widget.GetItemCount() + prLength := len(prs) - if len(prs) == 0 { + if prLength == 0 { return " [grey]none[white]\n" } + maxItems := widget.GetItemCount() + str := "" for idx, pr := range prs { str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx, *pr.Number, *pr.Title) str += "\n" } - widget.SetItemCount(maxItems + len(prs)) + widget.SetItemCount(maxItems + prLength) return str } From 5740b689be38082577d0a9edd14afdd951b1f5f0 Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 17:27:49 +0100 Subject: [PATCH 08/13] adding back mergedString --- modules/github/display.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index 53b3fd00..b75dfc90 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -12,7 +12,6 @@ func (widget *Widget) display() { func (widget *Widget) content() (string, string, bool) { repo := widget.currentGithubRepo() - title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo)) if repo == nil { return title, " GitHub repo data is unavailable ", false @@ -47,7 +46,7 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s str := "" for idx, pr := range prs { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, idx, *pr.Number, *pr.Title) + str += fmt.Sprintf(`%s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), idx, *pr.Number, *pr.Title) str += "\n" } From 74d2fbe833cdc930ecdf01c36d38547e9821421d Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 18:58:25 +0100 Subject: [PATCH 09/13] using the correct order and maintaining scroll position when changing source --- modules/github/display.go | 27 ++++++++++++++++----------- modules/github/widget.go | 1 - 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index b75dfc90..8ea0fb0a 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -12,6 +12,15 @@ func (widget *Widget) display() { func (widget *Widget) content() (string, string, bool) { repo := widget.currentGithubRepo() + + if len(widget.View.GetHighlights()) > 0 { + widget.View.ScrollToHighlight() + } else { + widget.View.ScrollToBeginning() + } + + widget.SetItemCount(len(repo.myReviewRequests((widget.settings.username)))) + title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo)) if repo == nil { return title, " GitHub repo data is unavailable ", false @@ -35,21 +44,23 @@ func (widget *Widget) content() (string, string, bool) { func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string { prs := repo.myPullRequests(username, widget.settings.enableStatus) - + prLength := len(prs) if prLength == 0 { return " [grey]none[white]\n" } - widget.SetItemCount(prLength) + maxItems := widget.GetItemCount() str := "" for idx, pr := range prs { - str += fmt.Sprintf(`%s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), idx, *pr.Number, *pr.Title) + str += fmt.Sprintf(`%s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), maxItems + idx, *pr.Number, *pr.Title) str += "\n" } + widget.SetItemCount(maxItems + prLength) + return str } @@ -82,22 +93,16 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) string { prs := repo.myReviewRequests(username) - prLength := len(prs) - - if prLength == 0 { + if len(prs) == 0 { return " [grey]none[white]\n" } - maxItems := widget.GetItemCount() - str := "" for idx, pr := range prs { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx, *pr.Number, *pr.Title) + str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, idx, *pr.Number, *pr.Title) str += "\n" } - widget.SetItemCount(maxItems + prLength) - return str } diff --git a/modules/github/widget.go b/modules/github/widget.go index 380b07b6..e8de805a 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -88,7 +88,6 @@ func (widget *Widget) Refresh() { repo.Refresh() } - widget.SetItemCount(0) widget.display() } From b98ce54750b4ca949ee8aa355ce46addac14c0f0 Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 19:01:29 +0100 Subject: [PATCH 10/13] scroll to top when unselecting --- modules/github/widget.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/github/widget.go b/modules/github/widget.go index e8de805a..5550827d 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -80,7 +80,7 @@ func (widget *Widget) Prev() { func (widget *Widget) Unselect() { widget.Selected = -1 - widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight() + widget.View.ScrollToBeginning() } func (widget *Widget) Refresh() { From cbae7449b0f6fc6cfafa43a28ec0f55bfdb4a299 Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Sat, 31 Aug 2019 19:24:24 +0100 Subject: [PATCH 11/13] adding back padding --- modules/github/display.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/github/display.go b/modules/github/display.go index 8ea0fb0a..2c9a5f02 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -12,15 +12,18 @@ func (widget *Widget) display() { func (widget *Widget) content() (string, string, bool) { repo := widget.currentGithubRepo() + username := widget.settings.username + // Choses the correct place to scroll to when changing sources if len(widget.View.GetHighlights()) > 0 { widget.View.ScrollToHighlight() } else { widget.View.ScrollToBeginning() } - - widget.SetItemCount(len(repo.myReviewRequests((widget.settings.username)))) - + + // initial maxItems count + widget.SetItemCount(len(repo.myReviewRequests((username)))) + title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo)) if repo == nil { return title, " GitHub repo data is unavailable ", false @@ -31,9 +34,9 @@ func (widget *Widget) content() (string, string, bool) { str += " [red]Stats[white]\n" str += widget.displayStats(repo) str += "\n [red]Open Review Requests[white]\n" - str += widget.displayMyReviewRequests(repo, widget.settings.username) + str += widget.displayMyReviewRequests(repo, username) str += "\n [red]My Pull Requests[white]\n" - str += widget.displayMyPullRequests(repo, widget.settings.username) + str += widget.displayMyPullRequests(repo, username) for _, customQuery := range widget.settings.customQueries { str += fmt.Sprintf("\n [red]%s[white]\n", customQuery.title) str += widget.displayCustomQuery(repo, customQuery.filter, customQuery.perPage) @@ -55,7 +58,7 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s str := "" for idx, pr := range prs { - str += fmt.Sprintf(`%s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), maxItems + idx, *pr.Number, *pr.Title) + str += fmt.Sprintf(` %s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), maxItems + idx, *pr.Number, *pr.Title) str += "\n" } @@ -81,7 +84,7 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag str := "" for idx, issue := range res.Issues { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, maxItems + idx , *issue.Number, *issue.Title) + str += fmt.Sprintf(` [green]["%d"]%4d[""][white] %s`, maxItems + idx , *issue.Number, *issue.Title) str += "\n" } @@ -99,7 +102,7 @@ func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) str := "" for idx, pr := range prs { - str += fmt.Sprintf(`[green]["%d"]%4d[""][white] %s`, idx, *pr.Number, *pr.Title) + str += fmt.Sprintf(` [green]["%d"]%4d[""][white] %s`, idx, *pr.Number, *pr.Title) str += "\n" } From c21b7c32a838f339b806ff886a20a35af8c07230 Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Wed, 4 Sep 2019 17:14:24 +0100 Subject: [PATCH 12/13] appending to a slice and referencing items within that using the currently selected --- modules/github/display.go | 4 ++++ modules/github/widget.go | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/github/display.go b/modules/github/display.go index 2c9a5f02..c0895cb7 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -22,6 +22,7 @@ func (widget *Widget) content() (string, string, bool) { } // initial maxItems count + widget.Items = make([]int, 0) widget.SetItemCount(len(repo.myReviewRequests((username)))) title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo)) @@ -60,6 +61,7 @@ func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) s for idx, pr := range prs { str += fmt.Sprintf(` %s[green]["%d"]%4d[""][white] %s`, widget.mergeString(pr), maxItems + idx, *pr.Number, *pr.Title) str += "\n" + widget.Items = append(widget.Items, *pr.Number) } widget.SetItemCount(maxItems + prLength) @@ -86,6 +88,7 @@ func (widget *Widget) displayCustomQuery(repo *GithubRepo, filter string, perPag for idx, issue := range res.Issues { str += fmt.Sprintf(` [green]["%d"]%4d[""][white] %s`, maxItems + idx , *issue.Number, *issue.Title) str += "\n" + widget.Items = append(widget.Items, *issue.Number) } widget.SetItemCount(maxItems + issuesLength) @@ -104,6 +107,7 @@ func (widget *Widget) displayMyReviewRequests(repo *GithubRepo, username string) for idx, pr := range prs { str += fmt.Sprintf(` [green]["%d"]%4d[""][white] %s`, idx, *pr.Number, *pr.Title) str += "\n" + widget.Items = append(widget.Items, *pr.Number) } return str diff --git a/modules/github/widget.go b/modules/github/widget.go index 5550827d..55a17b8b 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -19,6 +19,7 @@ type Widget struct { settings *Settings Selected int maxItems int + Items []int } func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { @@ -132,7 +133,7 @@ func (widget *Widget) currentGithubRepo() *GithubRepo { func (widget *Widget) openPr() { currentSelection := widget.View.GetHighlights() if widget.Selected >= 0 && currentSelection[0] != "" { - url := (*widget.currentGithubRepo().RemoteRepo.HTMLURL + "/pull/" + widget.View.GetRegionText(currentSelection[0])) + url := (*widget.currentGithubRepo().RemoteRepo.HTMLURL + "/pull/" + strconv.Itoa(widget.Items[widget.Selected])) utils.OpenFile(url) } } From bd2f73aea5f76835061edfeb3a3470ac0fbbff9b Mon Sep 17 00:00:00 2001 From: Joel Valentine Date: Wed, 4 Sep 2019 18:39:23 +0100 Subject: [PATCH 13/13] unselecting correctly --- modules/github/widget.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/github/widget.go b/modules/github/widget.go index 55a17b8b..008f3ea4 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -81,6 +81,7 @@ func (widget *Widget) Prev() { func (widget *Widget) Unselect() { widget.Selected = -1 + widget.View.Highlight() widget.View.ScrollToBeginning() }