mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge pull request #538 from Seanstoppable/fixhighlightrace
Fix a bunch of race conditions
This commit is contained in:
commit
67658e172c
@ -16,6 +16,7 @@ type Widget struct {
|
|||||||
view.TextWidget
|
view.TextWidget
|
||||||
|
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
items []Item
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
@ -37,28 +38,28 @@ func (widget *Widget) Refresh() {
|
|||||||
widget.settings.subdomain,
|
widget.settings.subdomain,
|
||||||
)
|
)
|
||||||
|
|
||||||
todayItems := client.Away(
|
widget.items = client.Away(
|
||||||
"timeOff",
|
"timeOff",
|
||||||
time.Now().Local().Format(wtf.DateFormat),
|
time.Now().Local().Format(wtf.DateFormat),
|
||||||
time.Now().Local().Format(wtf.DateFormat),
|
time.Now().Local().Format(wtf.DateFormat),
|
||||||
)
|
)
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(todayItems), false)
|
widget.RedrawFunc(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(items []Item) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
if len(items) == 0 {
|
|
||||||
return fmt.Sprintf("\n\n\n\n\n\n\n\n%s", utils.CenterText("[grey]no one[white]", 50))
|
|
||||||
}
|
|
||||||
|
|
||||||
str := ""
|
str := ""
|
||||||
for _, item := range items {
|
if len(widget.items) == 0 {
|
||||||
|
str = fmt.Sprintf("\n\n\n\n\n\n\n\n%s", utils.CenterText("[grey]no one[white]", 50))
|
||||||
|
} else {
|
||||||
|
for _, item := range widget.items {
|
||||||
str += widget.format(item)
|
str += widget.format(item)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return str
|
return widget.CommonSettings().Title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) format(item Item) string {
|
func (widget *Widget) format(item Item) string {
|
||||||
|
@ -32,28 +32,24 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
builds, err := widget.Client.BuildsFor()
|
widget.RedrawFunc(widget.content)
|
||||||
|
|
||||||
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
|
|
||||||
var content string
|
|
||||||
wrap := false
|
|
||||||
if err != nil {
|
|
||||||
wrap = true
|
|
||||||
content = err.Error()
|
|
||||||
} else {
|
|
||||||
content = widget.contentFrom(builds)
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.Redraw(title, content, wrap)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(builds []*Build) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
builds, err := widget.Client.BuildsFor()
|
||||||
|
|
||||||
|
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
|
||||||
var str string
|
var str string
|
||||||
|
wrap := false
|
||||||
|
if err != nil {
|
||||||
|
wrap = true
|
||||||
|
str = err.Error()
|
||||||
|
} else {
|
||||||
for idx, build := range builds {
|
for idx, build := range builds {
|
||||||
if idx > 10 {
|
if idx > 10 {
|
||||||
return str
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
str += fmt.Sprintf(
|
str += fmt.Sprintf(
|
||||||
@ -65,8 +61,9 @@ func (widget *Widget) contentFrom(builds []*Build) string {
|
|||||||
build.AuthorName,
|
build.AuthorName,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return str
|
return title, str, wrap
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildColor(build *Build) string {
|
func buildColor(build *Build) string {
|
||||||
|
@ -33,8 +33,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh executes the command and updates the view with the results
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
func (widget *Widget) Refresh() {
|
|
||||||
result := widget.execute()
|
result := widget.execute()
|
||||||
|
|
||||||
ansiTitle := tview.TranslateANSI(widget.CommonSettings().Title)
|
ansiTitle := tview.TranslateANSI(widget.CommonSettings().Title)
|
||||||
@ -43,7 +42,12 @@ func (widget *Widget) Refresh() {
|
|||||||
}
|
}
|
||||||
ansiResult := tview.TranslateANSI(result)
|
ansiResult := tview.TranslateANSI(result)
|
||||||
|
|
||||||
widget.Redraw(ansiTitle, ansiResult, false)
|
return ansiTitle, ansiResult, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh executes the command and updates the view with the results
|
||||||
|
func (widget *Widget) Refresh() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns the string representation of the widget
|
// String returns the string representation of the widget
|
||||||
|
@ -7,16 +7,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
if ok == false {
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, errorText, true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
summaryText := widget.summaryText(&widget.summaryList)
|
widget.RedrawFunc(widget.content)
|
||||||
widget.Redraw(widget.CommonSettings().Title, summaryText, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) summaryText(list *summaryList) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
if ok == false {
|
||||||
|
return widget.CommonSettings().Title, errorText, true
|
||||||
|
}
|
||||||
|
list := &widget.summaryList
|
||||||
str := ""
|
str := ""
|
||||||
|
|
||||||
for _, baseCurrency := range list.items {
|
for _, baseCurrency := range list.items {
|
||||||
@ -62,7 +61,7 @@ func (widget *Widget) summaryText(list *summaryList) string {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return widget.CommonSettings().Title, str, true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,19 +32,18 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
positions, err := Fetch(widget.device_token)
|
|
||||||
if err != nil {
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
content := widget.contentFrom(positions)
|
widget.RedrawFunc(widget.content)
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, content, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
func (widget *Widget) contentFrom(positions *AllPositionsResponse) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
positions, err := Fetch(widget.device_token)
|
||||||
|
title := widget.CommonSettings().Title
|
||||||
|
if err != nil {
|
||||||
|
return title, err.Error(), true
|
||||||
|
}
|
||||||
|
|
||||||
res := ""
|
res := ""
|
||||||
totalFiat := float32(0.0)
|
totalFiat := float32(0.0)
|
||||||
|
|
||||||
@ -86,7 +85,7 @@ func (widget *Widget) contentFrom(positions *AllPositionsResponse) string {
|
|||||||
res += fmt.Sprintf("\n[%s]Total value: $%.3fk", "green", totalFiat/1000)
|
res += fmt.Sprintf("\n[%s]Total value: $%.3fk", "green", totalFiat/1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return title, res, true
|
||||||
}
|
}
|
||||||
|
|
||||||
//always the same
|
//always the same
|
||||||
|
@ -46,15 +46,15 @@ func (widget *Widget) Refresh() {
|
|||||||
widget.toplistWidget.Refresh(&wg)
|
widget.toplistWidget.Refresh(&wg)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
widget.display()
|
widget.RedrawFunc(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
str := ""
|
str := ""
|
||||||
str += widget.priceWidget.Result
|
str += widget.priceWidget.Result
|
||||||
str += widget.toplistWidget.Result
|
str += widget.toplistWidget.Result
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, fmt.Sprintf("\n%s", str), false)
|
return widget.CommonSettings().Title, fmt.Sprintf("\n%s", str), false
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,7 @@ func (widget *Widget) Refresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
content := widget.contentFrom(widget.monitors)
|
widget.RedrawFunc(widget.content)
|
||||||
widget.Redraw(widget.CommonSettings().Title, content, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
@ -70,7 +69,8 @@ func (widget *Widget) HelpText() string {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
triggeredMonitors := widget.monitors
|
||||||
var str string
|
var str string
|
||||||
|
|
||||||
if len(triggeredMonitors) > 0 {
|
if len(triggeredMonitors) > 0 {
|
||||||
@ -93,7 +93,7 @@ func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return widget.CommonSettings().Title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) openItem() {
|
func (widget *Widget) openItem() {
|
||||||
|
@ -91,8 +91,7 @@ func (widget *Widget) Render() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
title := widget.CommonSettings().Title
|
widget.RedrawFunc(widget.content)
|
||||||
widget.Redraw(title, widget.contentFrom(widget.stories), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
@ -123,7 +122,9 @@ func (widget *Widget) fetchForFeed(feedURL string) ([]*FeedItem, error) {
|
|||||||
return feedItems, nil
|
return feedItems, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(data []*FeedItem) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
data := widget.stories
|
||||||
|
title := widget.CommonSettings().Title
|
||||||
var str string
|
var str string
|
||||||
|
|
||||||
for idx, feedItem := range data {
|
for idx, feedItem := range data {
|
||||||
@ -147,7 +148,7 @@ func (widget *Widget) contentFrom(data []*FeedItem) string {
|
|||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(feedItem.item.Title))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(feedItem.item.Title))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, str, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// feedItems are sorted by published date
|
// feedItems are sorted by published date
|
||||||
|
@ -25,16 +25,14 @@ func (widget *Widget) sortedEvents() ([]*CalEvent, []*CalEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
if widget.calEvents == nil || len(widget.calEvents) == 0 {
|
widget.RedrawFunc(widget.content)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.TextWidget.Redraw(widget.settings.common.Title, widget.contentFrom(widget.calEvents), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(calEvents []*CalEvent) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := widget.settings.common.Title
|
||||||
|
calEvents := widget.calEvents
|
||||||
if (calEvents == nil) || (len(calEvents) == 0) {
|
if (calEvents == nil) || (len(calEvents) == 0) {
|
||||||
return "No calendar events"
|
return title, "No calendar events", false
|
||||||
}
|
}
|
||||||
|
|
||||||
var str string
|
var str string
|
||||||
@ -76,7 +74,7 @@ func (widget *Widget) contentFrom(calEvents []*CalEvent) string {
|
|||||||
prevEvent = calEvent
|
prevEvent = calEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) dayDivider(event, prevEvent *CalEvent) string {
|
func (widget *Widget) dayDivider(event, prevEvent *CalEvent) string {
|
||||||
|
@ -5,11 +5,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
|
||||||
project := widget.currentGerritProject()
|
project := widget.currentGerritProject()
|
||||||
if project == nil {
|
if project == nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, "Gerrit project data is unavailable", true)
|
return widget.CommonSettings().Title, "Gerrit project data is unavailable", true
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
title := fmt.Sprintf("%s- %s", widget.CommonSettings().Title, widget.title(project))
|
title := fmt.Sprintf("%s- %s", widget.CommonSettings().Title, widget.title(project))
|
||||||
@ -25,7 +28,7 @@ func (widget *Widget) display() {
|
|||||||
str += " [red]My Outgoing Reviews[white]\n"
|
str += " [red]My Outgoing Reviews[white]\n"
|
||||||
str += widget.displayMyOutgoingReviews(project, widget.settings.username)
|
str += widget.displayMyOutgoingReviews(project, widget.settings.username)
|
||||||
|
|
||||||
widget.Redraw(title, str, false)
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) displayMyIncomingReviews(project *GerritProject, username string) string {
|
func (widget *Widget) displayMyIncomingReviews(project *GerritProject, username string) string {
|
||||||
|
@ -7,10 +7,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
repoData := widget.currentData()
|
repoData := widget.currentData()
|
||||||
if repoData == nil {
|
if repoData == nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, " Git repo data is unavailable ", false)
|
return widget.CommonSettings().Title, " Git repo data is unavailable ", false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings().Title, repoData.Repository)
|
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings().Title, repoData.Repository)
|
||||||
@ -24,7 +27,7 @@ func (widget *Widget) display() {
|
|||||||
str += "\n"
|
str += "\n"
|
||||||
str += widget.formatCommits(repoData.Commits)
|
str += widget.formatCommits(repoData.Commits)
|
||||||
|
|
||||||
widget.Redraw(title, str, false)
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) formatChanges(data []string) string {
|
func (widget *Widget) formatChanges(data []string) string {
|
||||||
|
@ -7,11 +7,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
|
widget.TextWidget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
repo := widget.currentGithubRepo()
|
repo := widget.currentGithubRepo()
|
||||||
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo))
|
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.title(repo))
|
||||||
if repo == nil {
|
if repo == nil {
|
||||||
widget.TextWidget.Redraw(title, " GitHub repo data is unavailable ", false)
|
return title, " GitHub repo data is unavailable ", false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, width, _ := widget.View.GetRect()
|
_, _, width, _ := widget.View.GetRect()
|
||||||
@ -27,7 +30,7 @@ func (widget *Widget) display() {
|
|||||||
str += widget.displayCustomQuery(repo, customQuery.filter, customQuery.perPage)
|
str += widget.displayCustomQuery(repo, customQuery.filter, customQuery.perPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.TextWidget.Redraw(title, str, false)
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string {
|
func (widget *Widget) displayMyPullRequests(repo *GithubRepo, username string) string {
|
||||||
|
@ -5,11 +5,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
|
||||||
project := widget.currentGitlabProject()
|
project := widget.currentGitlabProject()
|
||||||
if project == nil {
|
if project == nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, " Gitlab project data is unavailable ", true)
|
return widget.CommonSettings().Title, " Gitlab project data is unavailable ", true
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
title := fmt.Sprintf("%s- %s", widget.CommonSettings().Title, widget.title(project))
|
title := fmt.Sprintf("%s- %s", widget.CommonSettings().Title, widget.title(project))
|
||||||
@ -24,7 +27,8 @@ func (widget *Widget) display() {
|
|||||||
str += "\n"
|
str += "\n"
|
||||||
str += " [red]My Merge Requests[white]\n"
|
str += " [red]My Merge Requests[white]\n"
|
||||||
str += widget.displayMyMergeRequests(project, widget.settings.username)
|
str += widget.displayMyMergeRequests(project, widget.settings.username)
|
||||||
widget.Redraw(title, str, false)
|
|
||||||
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) displayMyMergeRequests(project *GitlabProject, username string) string {
|
func (widget *Widget) displayMyMergeRequests(project *GitlabProject, username string) string {
|
||||||
|
@ -72,18 +72,16 @@ func (widget *Widget) HelpText() string {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
if widget.messages == nil {
|
widget.RedrawFunc(widget.content)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.roomURI)
|
|
||||||
|
|
||||||
widget.Redraw(title, widget.contentFrom(widget.messages), true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(messages []Message) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.roomURI)
|
||||||
|
if widget.messages == nil || len(widget.messages) == 0 {
|
||||||
|
return title, "No Messages To Display", false
|
||||||
|
}
|
||||||
var str string
|
var str string
|
||||||
for idx, message := range messages {
|
for idx, message := range widget.messages {
|
||||||
row := fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
`[%s] [blue]%s [lightslategray]%s: [%s]%s [aqua]%s`,
|
`[%s] [blue]%s [lightslategray]%s: [%s]%s [aqua]%s`,
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
@ -97,7 +95,7 @@ func (widget *Widget) contentFrom(messages []Message) string {
|
|||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(message.Text))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(message.Text))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, str, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) openMessage() {
|
func (widget *Widget) openMessage() {
|
||||||
|
@ -67,17 +67,17 @@ func (widget *Widget) Refresh() {
|
|||||||
|
|
||||||
// Render sets up the widget data for redrawing to the screen
|
// Render sets up the widget data for redrawing to the screen
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
if widget.stories == nil {
|
widget.RedrawFunc(widget.content)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
title := fmt.Sprintf("%s - %s stories", widget.CommonSettings().Title, widget.settings.storyType)
|
|
||||||
widget.Redraw(title, widget.contentFrom(widget.stories), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(stories []Story) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := fmt.Sprintf("%s - %s stories", widget.CommonSettings().Title, widget.settings.storyType)
|
||||||
|
stories := widget.stories
|
||||||
|
if stories == nil || len(stories) == 0 {
|
||||||
|
return title, "No stories to display", false
|
||||||
|
}
|
||||||
var str string
|
var str string
|
||||||
|
|
||||||
for idx, story := range stories {
|
for idx, story := range stories {
|
||||||
@ -94,7 +94,7 @@ func (widget *Widget) contentFrom(stories []Story) string {
|
|||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(story.Title))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(story.Title))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) openStory() {
|
func (widget *Widget) openStory() {
|
||||||
|
@ -52,7 +52,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.ipinfo()
|
widget.ipinfo()
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, widget.result, false)
|
widget.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
|
||||||
}
|
}
|
||||||
|
|
||||||
//this method reads the config and calls ipinfo for ip information
|
//this method reads the config and calls ipinfo for ip information
|
||||||
|
@ -44,7 +44,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.ipinfo()
|
widget.ipinfo()
|
||||||
|
|
||||||
widget.TextWidget.Redraw(widget.CommonSettings().Title, widget.result, false)
|
widget.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
|
||||||
}
|
}
|
||||||
|
|
||||||
//this method reads the config and calls ipinfo for ip information
|
//this method reads the config and calls ipinfo for ip information
|
||||||
|
@ -2,7 +2,6 @@ package jenkins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
"github.com/wtfutil/wtf/view"
|
"github.com/wtfutil/wtf/view"
|
||||||
@ -60,18 +59,18 @@ func (widget *Widget) Refresh() {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
if widget.view == nil {
|
widget.RedrawFunc(widget.content)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
title := fmt.Sprintf("%s: [red]%s", widget.CommonSettings().Title, widget.view.Name)
|
|
||||||
|
|
||||||
widget.Redraw(title, widget.contentFrom(widget.view), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(view *View) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := fmt.Sprintf("%s: [red]%s", widget.CommonSettings().Title, widget.view.Name)
|
||||||
|
if widget.view == nil {
|
||||||
|
return title, "No content to display", false
|
||||||
|
}
|
||||||
|
|
||||||
var str string
|
var str string
|
||||||
for idx, job := range view.Jobs {
|
jobs := widget.view.Jobs
|
||||||
|
for idx, job := range jobs {
|
||||||
|
|
||||||
row := fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
`[%s] [%s]%-6s[white]`,
|
`[%s] [%s]%-6s[white]`,
|
||||||
@ -83,7 +82,7 @@ func (widget *Widget) contentFrom(view *View) string {
|
|||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(job.Name))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(job.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) jobColor(job *Job) string {
|
func (widget *Widget) jobColor(job *Job) string {
|
||||||
|
@ -7,10 +7,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
repoData := widget.currentData()
|
repoData := widget.currentData()
|
||||||
if repoData == nil {
|
if repoData == nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, " Mercurial repo data is unavailable ", false)
|
return widget.CommonSettings().Title, " Mercurial repo data is unavailable ", false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings().Title, repoData.Repository)
|
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings().Title, repoData.Repository)
|
||||||
@ -24,7 +27,7 @@ func (widget *Widget) display() {
|
|||||||
str += "\n"
|
str += "\n"
|
||||||
str += widget.formatCommits(repoData.Commits)
|
str += widget.formatCommits(repoData.Commits)
|
||||||
|
|
||||||
widget.Redraw(title, str, false)
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) formatChanges(data []string) string {
|
func (widget *Widget) formatChanges(data []string) string {
|
||||||
|
@ -45,36 +45,37 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.Redraw(widget.CommonSettings().Title, widget.nbascore(), false)
|
widget.RedrawFunc(widget.nbascore)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
return widget.KeyboardWidget.HelpText()
|
return widget.KeyboardWidget.HelpText()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) nbascore() string {
|
func (widget *Widget) nbascore() (string, string, bool) {
|
||||||
|
title := widget.CommonSettings().Title
|
||||||
cur := time.Now().AddDate(0, 0, offset) // Go back/forward offset days
|
cur := time.Now().AddDate(0, 0, offset) // Go back/forward offset days
|
||||||
curString := cur.Format("20060102") // Need 20060102 format to feed to api
|
curString := cur.Format("20060102") // Need 20060102 format to feed to api
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, err := http.NewRequest("GET", "http://data.nba.net/10s/prod/v1/"+curString+"/scoreboard.json", nil)
|
req, err := http.NewRequest("GET", "http://data.nba.net/10s/prod/v1/"+curString+"/scoreboard.json", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error()
|
return title, err.Error(), true
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Accept-Language", widget.language)
|
req.Header.Set("Accept-Language", widget.language)
|
||||||
req.Header.Set("User-Agent", "curl")
|
req.Header.Set("User-Agent", "curl")
|
||||||
response, err := client.Do(req)
|
response, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error()
|
return title, err.Error(), true
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
if response.StatusCode != 200 {
|
if response.StatusCode != 200 {
|
||||||
return err.Error()
|
return title, err.Error(), true
|
||||||
} // Get data from data.nba.net and check if successful
|
} // Get data from data.nba.net and check if successful
|
||||||
|
|
||||||
contents, err := ioutil.ReadAll(response.Body)
|
contents, err := ioutil.ReadAll(response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error()
|
return title, err.Error(), true
|
||||||
}
|
}
|
||||||
result := map[string]interface{}{}
|
result := map[string]interface{}{}
|
||||||
json.Unmarshal(contents, &result)
|
json.Unmarshal(contents, &result)
|
||||||
@ -135,5 +136,5 @@ func (widget *Widget) nbascore() string {
|
|||||||
}
|
}
|
||||||
allGame += fmt.Sprintf("%s%5s%v[white] %s %3s [white]vs %s%-3s %s\n", qColor, "Q", quarter, vTeam, vScore, hColor, hScore, hTeam) // Format the score and store in allgame
|
allGame += fmt.Sprintf("%s%5s%v[white] %s %3s [white]vs %s%-3s %s\n", qColor, "Q", quarter, vTeam, vScore, hColor, hScore, hTeam) // Format the score and store in allgame
|
||||||
}
|
}
|
||||||
return allGame
|
return title, allGame, false
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
"github.com/wtfutil/wtf/view"
|
"github.com/wtfutil/wtf/view"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
nr "github.com/yfronto/newrelic"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
@ -32,6 +31,12 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
app, appErr := widget.client.Application()
|
app, appErr := widget.client.Application()
|
||||||
deploys, depErr := widget.client.Deployments()
|
deploys, depErr := widget.client.Deployments()
|
||||||
|
|
||||||
@ -47,16 +52,7 @@ func (widget *Widget) Refresh() {
|
|||||||
wrap = true
|
wrap = true
|
||||||
content = depErr.Error()
|
content = depErr.Error()
|
||||||
} else {
|
} else {
|
||||||
content = widget.contentFrom(deploys)
|
content += fmt.Sprintf(
|
||||||
}
|
|
||||||
|
|
||||||
widget.Redraw(title, content, wrap)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
|
||||||
str := fmt.Sprintf(
|
|
||||||
" %s\n",
|
" %s\n",
|
||||||
"[red]Latest Deploys[white]",
|
"[red]Latest Deploys[white]",
|
||||||
)
|
)
|
||||||
@ -75,7 +71,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
|||||||
revLen = len(deploy.Revision)
|
revLen = len(deploy.Revision)
|
||||||
}
|
}
|
||||||
|
|
||||||
str += fmt.Sprintf(
|
content += fmt.Sprintf(
|
||||||
" [green]%s[%s] %s %-.16s[white]\n",
|
" [green]%s[%s] %s %-.16s[white]\n",
|
||||||
deploy.Revision[0:revLen],
|
deploy.Revision[0:revLen],
|
||||||
lineColor,
|
lineColor,
|
||||||
@ -90,6 +86,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return str
|
return title, content, wrap
|
||||||
}
|
}
|
||||||
|
@ -28,10 +28,17 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
data, err := widget.Fetch(
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
onCallResponses, err := widget.Fetch(
|
||||||
widget.settings.scheduleIdentifierType,
|
widget.settings.scheduleIdentifierType,
|
||||||
widget.settings.schedule,
|
widget.settings.schedule,
|
||||||
)
|
)
|
||||||
|
title := widget.CommonSettings().Title
|
||||||
|
|
||||||
var content string
|
var content string
|
||||||
wrap := false
|
wrap := false
|
||||||
@ -39,16 +46,6 @@ func (widget *Widget) Refresh() {
|
|||||||
wrap = true
|
wrap = true
|
||||||
content = err.Error()
|
content = err.Error()
|
||||||
} else {
|
} else {
|
||||||
content = widget.contentFrom(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, content, wrap)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(onCallResponses []*OnCallResponse) string {
|
|
||||||
str := ""
|
|
||||||
|
|
||||||
for _, data := range onCallResponses {
|
for _, data := range onCallResponses {
|
||||||
if (len(data.OnCallData.Recipients) == 0) && (widget.settings.displayEmpty == false) {
|
if (len(data.OnCallData.Recipients) == 0) && (widget.settings.displayEmpty == false) {
|
||||||
@ -62,11 +59,12 @@ func (widget *Widget) contentFrom(onCallResponses []*OnCallResponse) string {
|
|||||||
msg = fmt.Sprintf(" %s\n\n", strings.Join(utils.NamesFromEmails(data.OnCallData.Recipients), ", "))
|
msg = fmt.Sprintf(" %s\n\n", strings.Join(utils.NamesFromEmails(data.OnCallData.Recipients), ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
str += widget.cleanScheduleName(data.OnCallData.Parent.Name)
|
content += widget.cleanScheduleName(data.OnCallData.Parent.Name)
|
||||||
str += msg
|
content += msg
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, content, wrap
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) cleanScheduleName(schedule string) string {
|
func (widget *Widget) cleanScheduleName(schedule string) string {
|
||||||
|
@ -29,12 +29,14 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
widget.Battery.Refresh()
|
|
||||||
|
|
||||||
content := fmt.Sprintf(" %10s: %s\n", "Source", powerSource())
|
content := fmt.Sprintf(" %10s: %s\n", "Source", powerSource())
|
||||||
content += "\n"
|
content += "\n"
|
||||||
content += widget.Battery.String()
|
content += widget.Battery.String()
|
||||||
|
return widget.CommonSettings().Title, content, true
|
||||||
widget.Redraw(widget.CommonSettings().Title, content, true)
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) Refresh() {
|
||||||
|
widget.Battery.Refresh()
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
}
|
}
|
||||||
|
@ -65,13 +65,14 @@ func (widget *Widget) Render() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.projectName)
|
widget.RedrawFunc(widget.content)
|
||||||
widget.Redraw(title, widget.contentFrom(widget.items), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(result *Result) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.projectName)
|
||||||
|
result := widget.items
|
||||||
if result == nil {
|
if result == nil {
|
||||||
return "No results"
|
return title, "No results", false
|
||||||
}
|
}
|
||||||
var str string
|
var str string
|
||||||
if len(result.Items) > widget.settings.count {
|
if len(result.Items) > widget.settings.count {
|
||||||
@ -94,7 +95,7 @@ func (widget *Widget) contentFrom(result *Result) string {
|
|||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(item.Title))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(item.Title))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func statusColor(item *Item) string {
|
func statusColor(item *Item) string {
|
||||||
|
@ -32,15 +32,14 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := NewSecurityData()
|
widget.RedrawFunc(widget.content)
|
||||||
data.Fetch()
|
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(data), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(data *SecurityData) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
data := NewSecurityData()
|
||||||
|
data.Fetch()
|
||||||
str := " [red]WiFi[white]\n"
|
str := " [red]WiFi[white]\n"
|
||||||
str += fmt.Sprintf(" %8s: %s\n", "Network", data.WifiName)
|
str += fmt.Sprintf(" %8s: %s\n", "Network", data.WifiName)
|
||||||
str += fmt.Sprintf(" %8s: %s\n", "Crypto", data.WifiEncryption)
|
str += fmt.Sprintf(" %8s: %s\n", "Crypto", data.WifiEncryption)
|
||||||
@ -60,7 +59,7 @@ func (widget *Widget) contentFrom(data *SecurityData) string {
|
|||||||
str += fmt.Sprintf(" %12s\n", data.DnsAt(1))
|
str += fmt.Sprintf(" %12s\n", data.DnsAt(1))
|
||||||
str += "\n"
|
str += "\n"
|
||||||
|
|
||||||
return str
|
return widget.CommonSettings().Title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) labelColor(label string) string {
|
func (widget *Widget) labelColor(label string) string {
|
||||||
|
@ -51,28 +51,23 @@ func (w *Widget) refreshSpotifyInfos() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Widget) Refresh() {
|
func (w *Widget) Refresh() {
|
||||||
w.render()
|
w.RedrawFunc(w.createOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
return widget.KeyboardWidget.HelpText()
|
return widget.KeyboardWidget.HelpText()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Widget) render() {
|
func (w *Widget) createOutput() (string, string, bool) {
|
||||||
err := w.refreshSpotifyInfos()
|
|
||||||
var content string
|
var content string
|
||||||
|
err := w.refreshSpotifyInfos()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
content = err.Error()
|
content = err.Error()
|
||||||
} else {
|
} else {
|
||||||
content = w.createOutput()
|
content = utils.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width)
|
||||||
|
content += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n ", w.Info.Title), w.CommonSettings().Width)
|
||||||
|
content += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artist), w.CommonSettings().Width)
|
||||||
|
content += utils.CenterText(fmt.Sprintf("[green]%v:[white] %v\n", w.Info.TrackNumber, w.Info.Album), w.CommonSettings().Width)
|
||||||
}
|
}
|
||||||
w.Redraw(w.CommonSettings().Title, content, true)
|
return w.CommonSettings().Title, content, true
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Widget) createOutput() string {
|
|
||||||
output := utils.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width)
|
|
||||||
output += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n ", w.Info.Title), w.CommonSettings().Width)
|
|
||||||
output += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artist), w.CommonSettings().Width)
|
|
||||||
output += utils.CenterText(fmt.Sprintf("[green]%v:[white] %v\n", w.Info.TrackNumber, w.Info.Album), w.CommonSettings().Width)
|
|
||||||
return output
|
|
||||||
}
|
}
|
||||||
|
@ -154,19 +154,19 @@ func (w *Widget) refreshSpotifyInfos() error {
|
|||||||
|
|
||||||
// Refresh refreshes the current view of the widget
|
// Refresh refreshes the current view of the widget
|
||||||
func (w *Widget) Refresh() {
|
func (w *Widget) Refresh() {
|
||||||
err := w.refreshSpotifyInfos()
|
w.RedrawFunc(w.createOutput)
|
||||||
if err != nil {
|
|
||||||
w.Redraw(w.CommonSettings().Title, err.Error(), true)
|
|
||||||
} else {
|
|
||||||
w.Redraw(w.CommonSettings().Title, w.createOutput(), false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
return widget.KeyboardWidget.HelpText()
|
return widget.KeyboardWidget.HelpText()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Widget) createOutput() string {
|
func (w *Widget) createOutput() (string, string, bool) {
|
||||||
|
err := w.refreshSpotifyInfos()
|
||||||
|
var output string
|
||||||
|
if err != nil {
|
||||||
|
output = err.Error()
|
||||||
|
} else {
|
||||||
output := utils.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width)
|
output := utils.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width)
|
||||||
output += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n", w.Info.Title), w.CommonSettings().Width)
|
output += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n", w.Info.Title), w.CommonSettings().Width)
|
||||||
output += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artists), w.CommonSettings().Width)
|
output += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artists), w.CommonSettings().Width)
|
||||||
@ -176,5 +176,6 @@ func (w *Widget) createOutput() string {
|
|||||||
} else {
|
} else {
|
||||||
output += utils.CenterText(fmt.Sprintf("[green]Shuffle:[white] off\n"), w.CommonSettings().Width)
|
output += utils.CenterText(fmt.Sprintf("[green]Shuffle:[white] off\n"), w.CommonSettings().Width)
|
||||||
}
|
}
|
||||||
return output
|
}
|
||||||
|
return w.CommonSettings().Title, output, true
|
||||||
}
|
}
|
||||||
|
@ -28,12 +28,12 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.Redraw(widget.CommonSettings().Title, widget.animation(), false)
|
widget.RedrawFunc(widget.animation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) animation() string {
|
func (widget *Widget) animation() (string, string, bool) {
|
||||||
icons := []string{"|", "/", "-", "\\", "|"}
|
icons := []string{"|", "/", "-", "\\", "|"}
|
||||||
next := icons[widget.CurrentIcon]
|
next := icons[widget.CurrentIcon]
|
||||||
|
|
||||||
@ -42,5 +42,5 @@ func (widget *Widget) animation() string {
|
|||||||
widget.CurrentIcon = 0
|
widget.CurrentIcon = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return next
|
return widget.CommonSettings().Title, next, false
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func NewWidget(app *tview.Application, date, version string, settings *Settings)
|
|||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) display() (string, string, bool) {
|
||||||
content := fmt.Sprintf(
|
content := fmt.Sprintf(
|
||||||
"%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s",
|
"%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s",
|
||||||
"Built",
|
"Built",
|
||||||
@ -46,7 +46,12 @@ func (widget *Widget) Refresh() {
|
|||||||
"Build",
|
"Build",
|
||||||
widget.systemInfo.BuildVersion,
|
widget.systemInfo.BuildVersion,
|
||||||
)
|
)
|
||||||
widget.Redraw(widget.CommonSettings().Title, content, false)
|
|
||||||
|
return widget.CommonSettings().Title, content, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) Refresh() {
|
||||||
|
widget.RedrawFunc(widget.display)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) prettyDate() string {
|
func (widget *Widget) prettyDate() string {
|
||||||
|
@ -71,6 +71,10 @@ func (widget *Widget) HelpText() string {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
title := fmt.Sprintf("[green]%s[white]", widget.CurrentSource())
|
title := fmt.Sprintf("[green]%s[white]", widget.CurrentSource())
|
||||||
|
|
||||||
_, _, width, _ := widget.View.GetRect()
|
_, _, width, _ := widget.View.GetRect()
|
||||||
@ -82,7 +86,7 @@ func (widget *Widget) display() {
|
|||||||
text += widget.plainText()
|
text += widget.plainText()
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.Redraw(title, text, widget.settings.wrapText)
|
return title, text, widget.settings.wrapText
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) fileName() string {
|
func (widget *Widget) fileName() string {
|
||||||
|
@ -9,6 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
str := ""
|
str := ""
|
||||||
newList := checklist.NewChecklist(
|
newList := checklist.NewChecklist(
|
||||||
widget.settings.common.Sigils.Checkbox.Checked,
|
widget.settings.common.Sigils.Checkbox.Checked,
|
||||||
@ -31,7 +35,7 @@ func (widget *Widget) display() {
|
|||||||
newList.SetSelectedByItem(widget.list.SelectedItem())
|
newList.SetSelectedByItem(widget.list.SelectedItem())
|
||||||
widget.SetList(newList)
|
widget.SetList(newList)
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, str, false)
|
return widget.CommonSettings().Title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string {
|
func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string {
|
||||||
|
@ -7,14 +7,15 @@ import (
|
|||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
proj := widget.CurrentProject()
|
proj := widget.CurrentProject()
|
||||||
|
|
||||||
if proj == nil {
|
if proj == nil {
|
||||||
return
|
return widget.CommonSettings().Title, "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
title := fmt.Sprintf("[green]%s[white]", proj.Project.Name)
|
title := fmt.Sprintf("[green]%s[white]", proj.Project.Name)
|
||||||
|
|
||||||
str := ""
|
str := ""
|
||||||
|
|
||||||
for idx, item := range proj.tasks {
|
for idx, item := range proj.tasks {
|
||||||
@ -27,6 +28,9 @@ func (widget *Widget) display() {
|
|||||||
|
|
||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(item.Content))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(item.Content))
|
||||||
}
|
}
|
||||||
|
return title, str, false
|
||||||
widget.ScrollableWidget.Redraw(title, str, false)
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) display() {
|
||||||
|
widget.ScrollableWidget.RedrawFunc(widget.content)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,8 @@ import (
|
|||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(data []*transmissionrpc.Torrent) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
data := widget.torrents
|
||||||
str := ""
|
str := ""
|
||||||
|
|
||||||
for idx, torrent := range data {
|
for idx, torrent := range data {
|
||||||
@ -27,12 +28,11 @@ func (widget *Widget) contentFrom(data []*transmissionrpc.Torrent) string {
|
|||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(torrName))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(torrName))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return widget.CommonSettings().Title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
content := widget.contentFrom(widget.torrents)
|
widget.ScrollableWidget.RedrawFunc(widget.content)
|
||||||
widget.ScrollableWidget.Redraw(widget.CommonSettings().Title, content, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) prettyTorrentName(name string) string {
|
func (widget *Widget) prettyTorrentName(name string) string {
|
||||||
|
@ -59,13 +59,13 @@ func (widget *Widget) Render() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
|
widget.RedrawFunc(widget.content)
|
||||||
widget.Redraw(title, widget.contentFrom(widget.builds), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(builds *Builds) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
|
||||||
var str string
|
var str string
|
||||||
for idx, build := range builds.Builds {
|
for idx, build := range widget.builds.Builds {
|
||||||
|
|
||||||
row := fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
"[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n",
|
"[%s] [%s] %s-%s (%s) [%s]%s - [blue]%s\n",
|
||||||
@ -81,7 +81,7 @@ func (widget *Widget) contentFrom(builds *Builds) string {
|
|||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildColor(build *Build) string {
|
func buildColor(build *Build) string {
|
||||||
|
@ -27,6 +27,13 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
|
||||||
client := trello.NewClient(
|
client := trello.NewClient(
|
||||||
widget.settings.apiKey,
|
widget.settings.apiKey,
|
||||||
widget.settings.accessToken,
|
widget.settings.accessToken,
|
||||||
@ -41,7 +48,7 @@ func (widget *Widget) Refresh() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
var title string
|
var title string
|
||||||
var content string
|
content := ""
|
||||||
|
|
||||||
wrap := false
|
wrap := false
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -49,31 +56,20 @@ func (widget *Widget) Refresh() {
|
|||||||
title = widget.CommonSettings().Title
|
title = widget.CommonSettings().Title
|
||||||
content = err.Error()
|
content = err.Error()
|
||||||
} else {
|
} else {
|
||||||
widget.View.SetWrap(false)
|
|
||||||
title = fmt.Sprintf(
|
title = fmt.Sprintf(
|
||||||
"[white]%s: [green]%s ",
|
"[white]%s: [green]%s ",
|
||||||
widget.CommonSettings().Title,
|
widget.CommonSettings().Title,
|
||||||
widget.settings.board,
|
widget.settings.board,
|
||||||
)
|
)
|
||||||
content = widget.contentFrom(searchResult)
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.Redraw(title, content, wrap)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(searchResult *SearchResult) string {
|
|
||||||
str := ""
|
|
||||||
|
|
||||||
for list, cardArray := range searchResult.TrelloCards {
|
for list, cardArray := range searchResult.TrelloCards {
|
||||||
str += fmt.Sprintf(" [red]%s[white]\n", list)
|
content += fmt.Sprintf(" [red]%s[white]\n", list)
|
||||||
|
|
||||||
for _, card := range cardArray {
|
for _, card := range cardArray {
|
||||||
str += fmt.Sprintf(" %s[white]\n", card.Name)
|
content += fmt.Sprintf(" %s[white]\n", card.Name)
|
||||||
|
}
|
||||||
|
content = fmt.Sprintf("%s\n", content)
|
||||||
}
|
}
|
||||||
str = fmt.Sprintf("%s\n", str)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, content, wrap
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,10 @@ func (widget *Widget) HelpText() string {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
widget.client.screenName = widget.CurrentSource()
|
widget.client.screenName = widget.CurrentSource()
|
||||||
tweets := widget.client.Tweets()
|
tweets := widget.client.Tweets()
|
||||||
|
|
||||||
@ -69,8 +73,7 @@ func (widget *Widget) display() {
|
|||||||
|
|
||||||
if len(tweets) == 0 {
|
if len(tweets) == 0 {
|
||||||
str := fmt.Sprintf("\n\n\n%s", utils.CenterText("[lightblue]No Tweets[white]", 50))
|
str := fmt.Sprintf("\n\n\n%s", utils.CenterText("[lightblue]No Tweets[white]", 50))
|
||||||
widget.Redraw(title, str, true)
|
return title, str, true
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, width, _ := widget.View.GetRect()
|
_, _, width, _ := widget.View.GetRect()
|
||||||
@ -79,7 +82,7 @@ func (widget *Widget) display() {
|
|||||||
str += widget.format(tweet)
|
str += widget.format(tweet)
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.Redraw(title, str, true)
|
return title, str, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the tweet's Username is the same as the account we're watching, no
|
// If the tweet's Username is the same as the account we're watching, no
|
||||||
|
@ -27,5 +27,5 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
content := fmt.Sprintf("Widget %s and/or type %s does not exist", widget.Name(), widget.CommonSettings().Module.Type)
|
content := fmt.Sprintf("Widget %s and/or type %s does not exist", widget.Name(), widget.CommonSettings().Module.Type)
|
||||||
widget.Redraw(widget.CommonSettings().Title, content, true)
|
widget.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, content, true })
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.prettyWeather()
|
widget.prettyWeather()
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, widget.result, false)
|
widget.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
|
||||||
}
|
}
|
||||||
|
|
||||||
//this method reads the config and calls wttr.in for pretty weather
|
//this method reads the config and calls wttr.in for pretty weather
|
||||||
|
@ -9,6 +9,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
var err string
|
var err string
|
||||||
|
|
||||||
if widget.apiKeyValid() == false {
|
if widget.apiKeyValid() == false {
|
||||||
@ -40,7 +44,7 @@ func (widget *Widget) display() {
|
|||||||
content += widget.sunInfo(cityData)
|
content += widget.sunInfo(cityData)
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.Redraw(title, content, setWrap)
|
return title, content, setWrap
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) description(cityData *owm.CurrentWeatherData) string {
|
func (widget *Widget) description(cityData *owm.CurrentWeatherData) string {
|
||||||
|
@ -53,13 +53,14 @@ func (widget *Widget) Refresh() {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
title := fmt.Sprintf("%s (%d)", widget.CommonSettings().Title, widget.result.Count)
|
widget.RedrawFunc(widget.content)
|
||||||
widget.Redraw(title, widget.textContent(widget.result.Tickets), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) textContent(items []Ticket) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := fmt.Sprintf("%s (%d)", widget.CommonSettings().Title, widget.result.Count)
|
||||||
|
items := widget.result.Tickets
|
||||||
if len(items) == 0 {
|
if len(items) == 0 {
|
||||||
return fmt.Sprintf("No unassigned tickets in queue - woop!!")
|
return title, "No unassigned tickets in queue - woop!!", false
|
||||||
}
|
}
|
||||||
|
|
||||||
str := ""
|
str := ""
|
||||||
@ -67,7 +68,7 @@ func (widget *Widget) textContent(items []Ticket) string {
|
|||||||
str += widget.format(data, idx)
|
str += widget.format(data, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) format(ticket Ticket, idx int) string {
|
func (widget *Widget) format(ticket Ticket, idx int) string {
|
||||||
|
@ -38,6 +38,16 @@ func (widget *TextWidget) Redraw(title, text string, wrap bool) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (widget *TextWidget) RedrawFunc(data func() (string, string, bool)) {
|
||||||
|
widget.app.QueueUpdateDraw(func() {
|
||||||
|
title, content, wrap := data()
|
||||||
|
widget.View.Clear()
|
||||||
|
widget.View.SetWrap(wrap)
|
||||||
|
widget.View.SetTitle(widget.ContextualTitle(title))
|
||||||
|
widget.View.SetText(content)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *TextWidget) createView(bordered bool) *tview.TextView {
|
func (widget *TextWidget) createView(bordered bool) *tview.TextView {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user