diff --git a/Gopkg.toml b/Gopkg.toml index 7cd20a5e..5d0dae04 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -86,8 +86,8 @@ branch = "master" [[constraint]] - branch = "master" name = "github.com/darkSasori/todoist" + branch = "master" [prune] go-tests = true diff --git a/_sample_configs/complex_config.yml b/_sample_configs/complex_config.yml index db0e11b0..7937761b 100644 --- a/_sample_configs/complex_config.yml +++ b/_sample_configs/complex_config.yml @@ -208,6 +208,7 @@ wtf: cityids: - 3370352 - 1283240 + WTF_OWM_API_KEY: [YOUR API KEY] colors: current: "lightblue" enabled: true diff --git a/_site/content/posts/modules/jira.md b/_site/content/posts/modules/jira.md index 3daf62b7..081f4a31 100644 --- a/_site/content/posts/modules/jira.md +++ b/_site/content/posts/modules/jira.md @@ -21,7 +21,20 @@ wtf/jira/ ## Keyboard Commands -None. +Key: `[return]`
+Action: Open the selected issue in the browser. + +Key: `j`
+Action: Select the next item in the list. + +Key: `k`
+Action: Select the previous item in the list. + +Key: `↓`
+Action: Select the next item in the list. + +Key: `↑`
+Action: Select the previous item in the list. ## Configuration diff --git a/docs/index.xml b/docs/index.xml index b2e1c6e1..8088fa69 100644 --- a/docs/index.xml +++ b/docs/index.xml @@ -310,9 +310,11 @@ Key: j Action: Select the next item in the list. https://wtfutil.com/posts/modules/jira/ Displays all Jira issues assigned to you for the specified project. Source Code wtf/jira/ Required ENV Variables Key: WTF_JIRA_API_KEY Value: Your Jira API key. -Keyboard Commands None. -Configuration Single Jira Project jira:colors:rows:even:"lightblue"odd:"white"domain:"https://umbrellacorp.atlassian.net"email:"chriscummer@me.com"enabled:truejql:"issueType = Story"position:top:4left:1height:1width:2project:"ProjectA"refreshInterval:900username:"chris.cummer"verifyServerCertificate:true Multiple Jira Projects If you want to monitor multiple Jira projects, use the following configuration (note the difference in project): -jira:colors:rows:even:"lightblue"odd:"white"domain:"https://umbrellacorp.atlassian.net"email:"chriscummer@me.com"enabled:truejql:"issueType = Story"position:top:4left:1height:1width:2project:["ProjectA","ProjectB"]refreshInterval:900username:"chris.cummer"verifyServerCertificate:true Attributes colors.rows.even Define the foreground color for even-numbered rows. Values: Any X11 color name. +Keyboard Commands Key: [return] Action: Open the selected issue in the browser. +Key: j Action: Select the next item in the list. +Key: k Action: Select the previous item in the list. +Key: ↓ Action: Select the next item in the list. +Key: ↑ Action: Select the previous item in the list. diff --git a/docs/posts/index.xml b/docs/posts/index.xml index 1ca92370..b3ca1a6f 100644 --- a/docs/posts/index.xml +++ b/docs/posts/index.xml @@ -310,9 +310,11 @@ Key: j Action: Select the next item in the list. https://wtfutil.com/posts/modules/jira/ Displays all Jira issues assigned to you for the specified project. Source Code wtf/jira/ Required ENV Variables Key: WTF_JIRA_API_KEY Value: Your Jira API key. -Keyboard Commands None. -Configuration Single Jira Project jira:colors:rows:even:"lightblue"odd:"white"domain:"https://umbrellacorp.atlassian.net"email:"chriscummer@me.com"enabled:truejql:"issueType = Story"position:top:4left:1height:1width:2project:"ProjectA"refreshInterval:900username:"chris.cummer"verifyServerCertificate:true Multiple Jira Projects If you want to monitor multiple Jira projects, use the following configuration (note the difference in project): -jira:colors:rows:even:"lightblue"odd:"white"domain:"https://umbrellacorp.atlassian.net"email:"chriscummer@me.com"enabled:truejql:"issueType = Story"position:top:4left:1height:1width:2project:["ProjectA","ProjectB"]refreshInterval:900username:"chris.cummer"verifyServerCertificate:true Attributes colors.rows.even Define the foreground color for even-numbered rows. Values: Any X11 color name. +Keyboard Commands Key: [return] Action: Open the selected issue in the browser. +Key: j Action: Select the next item in the list. +Key: k Action: Select the previous item in the list. +Key: ↓ Action: Select the next item in the list. +Key: ↑ Action: Select the previous item in the list. diff --git a/docs/posts/modules/jira/index.html b/docs/posts/modules/jira/index.html index edcfcad4..7e14006c 100644 --- a/docs/posts/modules/jira/index.html +++ b/docs/posts/modules/jira/index.html @@ -148,7 +148,20 @@ height="0" width="0" style="display:none;visibility:hidden">

Keyboard Commands

-

None.

+

Key: [return]
+Action: Open the selected issue in the browser.

+ +

Key: j
+Action: Select the next item in the list.

+ +

Key: k
+Action: Select the previous item in the list.

+ +

Key:
+Action: Select the next item in the list.

+ +

Key:
+Action: Select the previous item in the list.

Configuration

diff --git a/docs/posts/modules/todoist/index.html b/docs/posts/modules/todoist/index.html index f4404ac4..33b03592 100644 --- a/docs/posts/modules/todoist/index.html +++ b/docs/posts/modules/todoist/index.html @@ -156,7 +156,11 @@ height="0" width="0" style="display:none;visibility:hidden"> Action: Show the previous project.

Key:
+<<<<<<< HEAD Action: Show the previous project.

+======= +Action: Show the previous project.

+>>>>>>> baustinanki-make-jira-interactable

Key: l
Action: Show the next project.

diff --git a/jira/widget.go b/jira/widget.go index 9ca26540..f9ac3c1c 100644 --- a/jira/widget.go +++ b/jira/widget.go @@ -3,18 +3,24 @@ package jira import ( "fmt" + "github.com/gdamore/tcell" "github.com/senorprogrammer/wtf/wtf" ) type Widget struct { wtf.TextWidget + + result *SearchResult + selected int } func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Jira ", "jira", false), + TextWidget: wtf.NewTextWidget(" Jira ", "jira", true), } + widget.unselect() + widget.View.SetInputCapture(widget.keyboardIntercept) return &widget } @@ -29,38 +35,71 @@ func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() - var content string if err != nil { + widget.result = nil widget.View.SetWrap(true) widget.View.SetTitle(widget.Name) - content = err.Error() + widget.View.SetText(err.Error()) } else { - widget.View.SetWrap(false) - widget.View.SetTitle( - fmt.Sprintf( - "%s- [green]%s[white]", - widget.Name, - wtf.Config.UString("wtf.mods.jira.project"), - ), - ) - content = widget.contentFrom(searchResult) + widget.result = searchResult } - widget.View.SetText(content) + widget.display() } /* -------------------- Unexported Functions -------------------- */ +func (widget *Widget) display() { + if widget.result == nil { + return + } + widget.View.SetWrap(false) + widget.View.SetTitle( + fmt.Sprintf( + "%s- [green]%s[white]", + widget.Name, + wtf.Config.UString("wtf.mods.jira.project"), + ), + ) + widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(widget.result))) +} + +func (widget *Widget) next() { + widget.selected++ + if widget.result != nil && widget.selected >= len(widget.result.Issues) { + widget.selected = 0 + } +} + +func (widget *Widget) prev() { + widget.selected-- + if widget.selected < 0 && widget.result != nil { + widget.selected = len(widget.result.Issues) - 1 + } +} + +func (widget *Widget) openItem() { + sel := widget.selected + if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) { + issue := &widget.result.Issues[widget.selected] + wtf.OpenFile(wtf.Config.UString("wtf.mods.jira.domain") + "/browse/" + issue.Key) + } +} + +func (widget *Widget) unselect() { + widget.selected = -1 +} + func (widget *Widget) contentFrom(searchResult *SearchResult) string { str := " [red]Assigned Issues[white]\n" for idx, issue := range searchResult.Issues { str = str + fmt.Sprintf( - " [%s]%-6s[white] [green]%-10s[%s] %s\n", + " [%s]%-6s[white] [green]%-10s [%s]%s\n", widget.issueTypeColor(&issue), issue.IssueFields.IssueType.Name, issue.Key, - wtf.RowColor("jira", idx), + widget.rowColor(idx), issue.IssueFields.Summary, ) } @@ -68,6 +107,15 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string { return str } +func (widget *Widget) rowColor(idx int) string { + if widget.View.HasFocus() && (idx == widget.selected) { + foreColor := wtf.Config.UString("wtf.mods.jira.colors.highlight.fore", "black") + backColor := wtf.Config.UString("wtf.mods.jira.colors.highlight.back", "white") + return fmt.Sprintf("%s:%s", foreColor, backColor) + } + return wtf.RowColor("jira", idx) +} + func (widget *Widget) issueTypeColor(issue *Issue) string { switch issue.IssueFields.IssueType.Name { case "Bug": @@ -98,3 +146,42 @@ func getProjects() []string { } return ret } + +func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { + switch string(event.Rune()) { + case "j": + // Select the next item down + widget.next() + widget.display() + return nil + case "k": + // Select the next item up + widget.prev() + widget.display() + return nil + } + + switch event.Key() { + case tcell.KeyDown: + // Select the next item down + widget.next() + widget.display() + return nil + case tcell.KeyEnter: + widget.openItem() + return nil + case tcell.KeyEsc: + // Unselect the current row + widget.unselect() + widget.display() + return event + case tcell.KeyUp: + // Select the next item up + widget.prev() + widget.display() + return nil + default: + // Pass it along + return event + } +} diff --git a/weatherservices/weather/widget.go b/weatherservices/weather/widget.go index 9e0ed0e8..6416f0a2 100644 --- a/weatherservices/weather/widget.go +++ b/weatherservices/weather/widget.go @@ -48,7 +48,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { } if widget.APIKey == "" { - logger.Log("loading weather WTF_OWM_API_KEY key from config") + logger.Log("loading weather API key from config") widget.APIKey = wtf.Config.UString(fmt.Sprintf("wtf.mods.%s.apiKey", configKey), "") }