mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge branch 'renormalizedraw' of github.com:Seanstoppable/wtf into Seanstoppable-renormalizedraw
This commit is contained in:
commit
bc80b9f60b
@ -44,7 +44,7 @@ func (widget *Widget) Refresh() {
|
|||||||
time.Now().Local().Format(wtf.DateFormat),
|
time.Now().Local().Format(wtf.DateFormat),
|
||||||
)
|
)
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -32,7 +32,7 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -5,13 +5,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat string) {
|
func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat string) {
|
||||||
if len(clocks) == 0 {
|
|
||||||
title := fmt.Sprintf("\n%s", " no timezone data available")
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, title, true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
str := ""
|
str := ""
|
||||||
|
if len(clocks) == 0 {
|
||||||
|
str = fmt.Sprintf("\n%s", " no timezone data available")
|
||||||
|
} else {
|
||||||
|
|
||||||
for idx, clock := range clocks {
|
for idx, clock := range clocks {
|
||||||
rowColor := widget.settings.colors.rows.odd
|
rowColor := widget.settings.colors.rows.odd
|
||||||
|
|
||||||
@ -27,6 +25,7 @@ func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat stri
|
|||||||
clock.Date(dateFormat),
|
clock.Date(dateFormat),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
widget.Redraw(widget.CommonSettings().Title, str, false)
|
|
||||||
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, str, true })
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ func (widget *Widget) content() (string, string, bool) {
|
|||||||
|
|
||||||
// Refresh executes the command and updates the view with the results
|
// Refresh executes the command and updates the view with the results
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns the string representation of the widget
|
// String returns the string representation of the widget
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -33,7 +33,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -46,7 +46,7 @@ func (widget *Widget) Refresh() {
|
|||||||
widget.toplistWidget.Refresh(&wg)
|
widget.toplistWidget.Refresh(&wg)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -42,7 +42,7 @@ func (widget *Widget) Refresh() {
|
|||||||
if monitorErr != nil {
|
if monitorErr != nil {
|
||||||
widget.monitors = nil
|
widget.monitors = nil
|
||||||
widget.SetItemCount(0)
|
widget.SetItemCount(0)
|
||||||
widget.Redraw(widget.CommonSettings().Title, monitorErr.Error(), true)
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, monitorErr.Error(), true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
triggeredMonitors := []datadog.Monitor{}
|
triggeredMonitors := []datadog.Monitor{}
|
||||||
@ -60,7 +60,7 @@ func (widget *Widget) Refresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
|
@ -29,6 +29,7 @@ type Widget struct {
|
|||||||
stories []*FeedItem
|
stories []*FeedItem
|
||||||
parser *gofeed.Parser
|
parser *gofeed.Parser
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWidget creates a new instance of a widget
|
// NewWidget creates a new instance of a widget
|
||||||
@ -76,22 +77,21 @@ func (widget *Widget) Fetch(feedURLs []string) ([]*FeedItem, error) {
|
|||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
feedItems, err := widget.Fetch(widget.settings.feeds)
|
feedItems, err := widget.Fetch(widget.settings.feeds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
widget.err = err
|
||||||
}
|
widget.stories = nil
|
||||||
|
widget.SetItemCount(0)
|
||||||
|
} else {
|
||||||
|
widget.err = nil
|
||||||
widget.stories = feedItems
|
widget.stories = feedItems
|
||||||
widget.SetItemCount(len(feedItems))
|
widget.SetItemCount(len(feedItems))
|
||||||
|
}
|
||||||
|
|
||||||
widget.Render()
|
widget.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.Redraw(widget.content)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
@ -123,8 +123,14 @@ func (widget *Widget) fetchForFeed(feedURL string) ([]*FeedItem, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
data := widget.stories
|
|
||||||
title := widget.CommonSettings().Title
|
title := widget.CommonSettings().Title
|
||||||
|
if widget.err != nil {
|
||||||
|
return title, widget.err.Error(), true
|
||||||
|
}
|
||||||
|
data := widget.stories
|
||||||
|
if data == nil || len(data) == 0 {
|
||||||
|
return title, "No data", false
|
||||||
|
}
|
||||||
var str string
|
var str string
|
||||||
|
|
||||||
for idx, feedItem := range data {
|
for idx, feedItem := range data {
|
||||||
|
@ -25,7 +25,7 @@ func (widget *Widget) sortedEvents() ([]*CalEvent, []*CalEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -76,9 +76,7 @@ func (widget *Widget) Refresh() {
|
|||||||
}
|
}
|
||||||
gerrit, err := glb.NewClient(gerritUrl, httpClient)
|
gerrit, err := glb.NewClient(gerritUrl, httpClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.View.SetWrap(true)
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
widget.gerrit = gerrit
|
widget.gerrit = gerrit
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.TextWidget.RedrawFunc(widget.content)
|
widget.TextWidget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -44,19 +44,19 @@ func (widget *Widget) Refresh() {
|
|||||||
|
|
||||||
room, err := GetRoom(widget.settings.roomURI, widget.settings.apiToken)
|
room, err := GetRoom(widget.settings.roomURI, widget.settings.apiToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if room == nil {
|
if room == nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, "No room", true)
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, "No room", true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
messages, err := GetMessages(room.ID, widget.settings.numberOfMessages, widget.settings.apiToken)
|
messages, err := GetMessages(room.ID, widget.settings.numberOfMessages, widget.settings.apiToken)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
widget.messages = messages
|
widget.messages = messages
|
||||||
@ -72,7 +72,7 @@ func (widget *Widget) HelpText() string {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -25,5 +25,5 @@ func (widget *Widget) Refresh() {
|
|||||||
websiteReports := widget.Fetch()
|
websiteReports := widget.Fetch()
|
||||||
contentTable := widget.createTable(websiteReports)
|
contentTable := widget.createTable(websiteReports)
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, contentTable, false)
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, contentTable, false })
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ type Widget struct {
|
|||||||
view.TextWidget
|
view.TextWidget
|
||||||
|
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
cells []*sheets.ValueRange
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
@ -29,23 +30,24 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
cells, _ := widget.Fetch()
|
cells, _ := widget.Fetch()
|
||||||
|
widget.cells = cells
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(cells), false)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(valueRanges []*sheets.ValueRange) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
if valueRanges == nil {
|
if widget.cells == nil {
|
||||||
return "error 1"
|
return widget.CommonSettings().Title, "error 1", false
|
||||||
}
|
}
|
||||||
|
|
||||||
res := ""
|
res := ""
|
||||||
|
|
||||||
cells := utils.ToStrs(widget.settings.cellNames)
|
cells := utils.ToStrs(widget.settings.cellNames)
|
||||||
for i := 0; i < len(valueRanges); i++ {
|
for i := 0; i < len(widget.cells); i++ {
|
||||||
res += fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, valueRanges[i].Values[0][0])
|
res += fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, widget.cells[i].Values[0][0])
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return widget.CommonSettings().Title, res, false
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func (widget *Widget) Refresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var stories []Story
|
var stories []Story
|
||||||
@ -67,7 +67,7 @@ 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() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -11,8 +11,9 @@ import (
|
|||||||
type Widget struct {
|
type Widget struct {
|
||||||
view.TextWidget
|
view.TextWidget
|
||||||
|
|
||||||
accounts []string
|
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
data []*Status
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWidget creates a new instance of a widget
|
// NewWidget creates a new instance of a widget
|
||||||
@ -48,29 +49,28 @@ func (widget *Widget) Fetch(accounts []string) ([]*Status, error) {
|
|||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
data, err := widget.Fetch(widget.settings.accounts)
|
data, err := widget.Fetch(widget.settings.accounts)
|
||||||
|
|
||||||
title := widget.CommonSettings().Title
|
|
||||||
title = title + widget.sinceDateForTitle()
|
|
||||||
|
|
||||||
var wrap bool
|
|
||||||
var content string
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wrap = true
|
widget.err = err
|
||||||
content = err.Error()
|
widget.data = nil
|
||||||
} else {
|
} else {
|
||||||
wrap = false
|
widget.err = nil
|
||||||
content = widget.contentFrom(data)
|
widget.data = data
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.Redraw(title, content, wrap)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(data []*Status) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := widget.CommonSettings().Title
|
||||||
|
if widget.err != nil {
|
||||||
|
return title, widget.err.Error(), true
|
||||||
|
}
|
||||||
|
title = title + widget.sinceDateForTitle()
|
||||||
str := ""
|
str := ""
|
||||||
|
|
||||||
for _, stat := range data {
|
for _, stat := range widget.data {
|
||||||
color := widget.settings.colors.ok
|
color := widget.settings.colors.ok
|
||||||
if stat.HasBeenCompromised() {
|
if stat.HasBeenCompromised() {
|
||||||
color = widget.settings.colors.pwned
|
color = widget.settings.colors.pwned
|
||||||
@ -79,7 +79,7 @@ func (widget *Widget) contentFrom(data []*Status) string {
|
|||||||
str += fmt.Sprintf(" [%s]%s[white]\n", color, stat.Account)
|
str += fmt.Sprintf(" [%s]%s[white]\n", color, stat.Account)
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) sinceDateForTitle() string {
|
func (widget *Widget) sinceDateForTitle() string {
|
||||||
|
@ -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.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
|
widget.Redraw(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.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
|
widget.Redraw(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
|
||||||
|
@ -13,6 +13,7 @@ type Widget struct {
|
|||||||
|
|
||||||
settings *Settings
|
settings *Settings
|
||||||
view *View
|
view *View
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
@ -47,11 +48,11 @@ func (widget *Widget) Refresh() {
|
|||||||
widget.view = view
|
widget.view = view
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
widget.err = err
|
||||||
return
|
widget.SetItemCount(0)
|
||||||
}
|
} else {
|
||||||
|
|
||||||
widget.SetItemCount(len(widget.view.Jobs))
|
widget.SetItemCount(len(widget.view.Jobs))
|
||||||
|
}
|
||||||
|
|
||||||
widget.Render()
|
widget.Render()
|
||||||
}
|
}
|
||||||
@ -59,12 +60,15 @@ func (widget *Widget) Refresh() {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
title := fmt.Sprintf("%s: [red]%s", widget.CommonSettings().Title, widget.view.Name)
|
title := fmt.Sprintf("%s: [red]%s", widget.CommonSettings().Title, widget.view.Name)
|
||||||
if widget.view == nil {
|
if widget.err != nil {
|
||||||
|
return title, widget.err.Error(), true
|
||||||
|
}
|
||||||
|
if widget.view == nil || len(widget.view.Jobs) == 0 {
|
||||||
return title, "No content to display", false
|
return title, "No content to display", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ type Widget struct {
|
|||||||
|
|
||||||
result *SearchResult
|
result *SearchResult
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
@ -43,23 +44,18 @@ func (widget *Widget) Refresh() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
widget.err = err
|
||||||
widget.result = nil
|
widget.result = nil
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
widget.err = nil
|
||||||
widget.result = searchResult
|
widget.result = searchResult
|
||||||
widget.SetItemCount(len(searchResult.Issues))
|
widget.SetItemCount(len(searchResult.Issues))
|
||||||
widget.Render()
|
widget.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
if widget.result == nil {
|
widget.Redraw(widget.content)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
str := fmt.Sprintf("%s- [green]%s[white]", widget.CommonSettings().Title, widget.settings.projects)
|
|
||||||
|
|
||||||
widget.Redraw(str, widget.contentFrom(widget.result), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
@ -72,10 +68,19 @@ func (widget *Widget) openItem() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(searchResult *SearchResult) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
if widget.err != nil {
|
||||||
|
return widget.CommonSettings().Title, widget.err.Error(), true
|
||||||
|
}
|
||||||
|
|
||||||
|
title := fmt.Sprintf("%s- [green]%s[white]", widget.CommonSettings().Title, widget.settings.projects)
|
||||||
str := " [red]Assigned Issues[white]\n"
|
str := " [red]Assigned Issues[white]\n"
|
||||||
|
|
||||||
for idx, issue := range searchResult.Issues {
|
if widget.result == nil || len(widget.result.Issues) == 0 {
|
||||||
|
return title, "No results to display", false
|
||||||
|
}
|
||||||
|
|
||||||
|
for idx, issue := range widget.result.Issues {
|
||||||
row := fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
`[%s] [%s]%-6s[white] [green]%-10s[white] [yellow][%s][white] [%s]%s`,
|
`[%s] [%s]%-6s[white] [green]%-10s[white] [yellow][%s][white] [%s]%s`,
|
||||||
widget.RowColor(idx),
|
widget.RowColor(idx),
|
||||||
@ -90,7 +95,7 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string {
|
|||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(issue.IssueFields.Summary))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(issue.IssueFields.Summary))
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) issueTypeColor(issue *Issue) string {
|
func (widget *Widget) issueTypeColor(issue *Issue) string {
|
||||||
|
@ -48,7 +48,7 @@ func (widget *Widget) Refresh() {
|
|||||||
if utils.Includes(widget.objects, "nodes") {
|
if utils.Includes(widget.objects, "nodes") {
|
||||||
nodeList, nodeError := client.getNodes()
|
nodeList, nodeError := client.getNodes()
|
||||||
if nodeError != nil {
|
if nodeError != nil {
|
||||||
widget.Redraw(title, "[red] Error getting node data [white]\n", true)
|
widget.Redraw(func() (string, string, bool) { return title, "[red] Error getting node data [white]\n", true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content += "[red]Nodes[white]\n"
|
content += "[red]Nodes[white]\n"
|
||||||
@ -61,7 +61,7 @@ func (widget *Widget) Refresh() {
|
|||||||
if utils.Includes(widget.objects, "deployments") {
|
if utils.Includes(widget.objects, "deployments") {
|
||||||
deploymentList, deploymentError := client.getDeployments(widget.namespaces)
|
deploymentList, deploymentError := client.getDeployments(widget.namespaces)
|
||||||
if deploymentError != nil {
|
if deploymentError != nil {
|
||||||
widget.Redraw(title, "[red] Error getting deployment data [white]\n", true)
|
widget.Redraw(func() (string, string, bool) { return title, "[red] Error getting deployment data [white]\n", true })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content += "[red]Deployments[white]\n"
|
content += "[red]Deployments[white]\n"
|
||||||
@ -74,7 +74,7 @@ func (widget *Widget) Refresh() {
|
|||||||
if utils.Includes(widget.objects, "pods") {
|
if utils.Includes(widget.objects, "pods") {
|
||||||
podList, podError := client.getPods(widget.namespaces)
|
podList, podError := client.getPods(widget.namespaces)
|
||||||
if podError != nil {
|
if podError != nil {
|
||||||
widget.Redraw(title, "[red] Error getting pod data [white]\n", false)
|
widget.Redraw(func() (string, string, bool) { return title, "[red] Error getting pod data [white]\n", false })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content += "[red]Pods[white]\n"
|
content += "[red]Pods[white]\n"
|
||||||
@ -84,7 +84,7 @@ func (widget *Widget) Refresh() {
|
|||||||
content += "\n"
|
content += "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.Redraw(title, content, false)
|
widget.Redraw(func() (string, string, bool) { return title, content, false })
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -34,18 +34,17 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
|
|
||||||
// Refresh updates the onscreen contents of the widget
|
// Refresh updates the onscreen contents of the widget
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
if log.LogFileMissing() {
|
widget.Redraw(widget.content)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
logLines := widget.tailFile()
|
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(logLines), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(logLines []string) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
if log.LogFileMissing() {
|
||||||
|
return widget.CommonSettings().Title, "File missing", false
|
||||||
|
}
|
||||||
|
|
||||||
|
logLines := widget.tailFile()
|
||||||
str := ""
|
str := ""
|
||||||
|
|
||||||
for _, line := range logLines {
|
for _, line := range logLines {
|
||||||
@ -61,7 +60,7 @@ func (widget *Widget) contentFrom(logLines []string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return widget.CommonSettings().Title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) tailFile() []string {
|
func (widget *Widget) tailFile() []string {
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -45,7 +45,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.RedrawFunc(widget.nbascore)
|
widget.Redraw(widget.nbascore)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
|
@ -31,7 +31,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -28,7 +28,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -59,7 +59,7 @@ func (widget *Widget) Refresh() {
|
|||||||
content = widget.contentFrom(onCalls, incidents)
|
content = widget.contentFrom(onCalls, incidents)
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, content, wrap)
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, content, wrap })
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -38,5 +38,5 @@ func (widget *Widget) content() (string, string, bool) {
|
|||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.Battery.Refresh()
|
widget.Battery.Refresh()
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ type Widget struct {
|
|||||||
|
|
||||||
items *Result
|
items *Result
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWidget creates a new instance of a widget
|
// NewWidget creates a new instance of a widget
|
||||||
@ -49,11 +50,13 @@ func (widget *Widget) Refresh() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
widget.err = err
|
||||||
return
|
widget.items = nil
|
||||||
}
|
widget.SetItemCount(0)
|
||||||
|
} else {
|
||||||
widget.items = &items.Results
|
widget.items = &items.Results
|
||||||
widget.SetItemCount(len(widget.items.Items))
|
widget.SetItemCount(len(widget.items.Items))
|
||||||
|
}
|
||||||
|
|
||||||
widget.Render()
|
widget.Render()
|
||||||
}
|
}
|
||||||
@ -61,17 +64,16 @@ func (widget *Widget) Refresh() {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
if widget.items == nil {
|
widget.Redraw(widget.content)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.projectName)
|
title := fmt.Sprintf("%s - %s", widget.CommonSettings().Title, widget.settings.projectName)
|
||||||
|
if widget.err != nil {
|
||||||
|
return widget.CommonSettings().Title, widget.err.Error(), true
|
||||||
|
}
|
||||||
result := widget.items
|
result := widget.items
|
||||||
if result == nil {
|
if result == nil || len(result.Items) == 0 {
|
||||||
return title, "No results", false
|
return title, "No results", false
|
||||||
}
|
}
|
||||||
var str string
|
var str string
|
||||||
|
@ -32,7 +32,7 @@ func (widget *Widget) Refresh() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -51,7 +51,7 @@ func (w *Widget) refreshSpotifyInfos() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Widget) Refresh() {
|
func (w *Widget) Refresh() {
|
||||||
w.RedrawFunc(w.createOutput)
|
w.Redraw(w.createOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
|
@ -154,7 +154,7 @@ 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() {
|
||||||
w.RedrawFunc(w.createOutput)
|
w.Redraw(w.createOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
|
@ -28,7 +28,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.RedrawFunc(widget.animation)
|
widget.Redraw(widget.animation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -51,7 +51,7 @@ func (widget *Widget) display() (string, string, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.RedrawFunc(widget.display)
|
widget.Redraw(widget.display)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) prettyDate() string {
|
func (widget *Widget) prettyDate() string {
|
||||||
|
@ -71,7 +71,7 @@ func (widget *Widget) HelpText() string {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -32,5 +32,5 @@ func (widget *Widget) content() (string, string, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.ScrollableWidget.RedrawFunc(widget.content)
|
widget.ScrollableWidget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := widget.CommonSettings().Title
|
||||||
|
if widget.err != nil {
|
||||||
|
return title, widget.err.Error(), true
|
||||||
|
}
|
||||||
data := widget.torrents
|
data := widget.torrents
|
||||||
|
if data == nil || len(data) == 0 {
|
||||||
|
return title, "No data", false
|
||||||
|
}
|
||||||
str := ""
|
str := ""
|
||||||
|
|
||||||
for idx, torrent := range data {
|
for idx, torrent := range data {
|
||||||
@ -28,11 +35,11 @@ func (widget *Widget) content() (string, string, bool) {
|
|||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(torrName))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(torrName))
|
||||||
}
|
}
|
||||||
|
|
||||||
return widget.CommonSettings().Title, str, false
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.ScrollableWidget.RedrawFunc(widget.content)
|
widget.ScrollableWidget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) prettyTorrentName(name string) string {
|
func (widget *Widget) prettyTorrentName(name string) string {
|
||||||
|
@ -16,6 +16,7 @@ type Widget struct {
|
|||||||
client *transmissionrpc.Client
|
client *transmissionrpc.Client
|
||||||
settings *Settings
|
settings *Settings
|
||||||
torrents []*transmissionrpc.Torrent
|
torrents []*transmissionrpc.Torrent
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWidget creates a new instance of a widget
|
// NewWidget creates a new instance of a widget
|
||||||
@ -63,13 +64,14 @@ func (widget *Widget) Fetch() ([]*transmissionrpc.Torrent, error) {
|
|||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
torrents, err := widget.Fetch()
|
torrents, err := widget.Fetch()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
widget.err = err
|
||||||
|
widget.torrents = nil
|
||||||
widget.SetItemCount(0)
|
widget.SetItemCount(0)
|
||||||
widget.ScrollableWidget.Redraw(widget.CommonSettings().Title, err.Error(), false)
|
} else {
|
||||||
return
|
widget.err = nil
|
||||||
}
|
|
||||||
|
|
||||||
widget.torrents = torrents
|
widget.torrents = torrents
|
||||||
widget.SetItemCount(len(torrents))
|
widget.SetItemCount(len(torrents))
|
||||||
|
}
|
||||||
|
|
||||||
widget.display()
|
widget.display()
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ type Widget struct {
|
|||||||
|
|
||||||
builds *Builds
|
builds *Builds
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
@ -44,27 +45,29 @@ func (widget *Widget) Refresh() {
|
|||||||
builds, err := BuildsFor(widget.settings.apiKey, widget.settings.pro)
|
builds, err := BuildsFor(widget.settings.apiKey, widget.settings.pro)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
widget.err = err
|
||||||
return
|
widget.builds = nil
|
||||||
}
|
widget.SetItemCount(0)
|
||||||
|
} else {
|
||||||
|
widget.err = nil
|
||||||
widget.builds = builds
|
widget.builds = builds
|
||||||
widget.SetItemCount(len(builds.Builds))
|
widget.SetItemCount(len(builds.Builds))
|
||||||
|
}
|
||||||
widget.Render()
|
widget.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
if widget.builds == nil {
|
widget.Redraw(widget.content)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
|
title := fmt.Sprintf("%s - Builds", widget.CommonSettings().Title)
|
||||||
var str string
|
var str string
|
||||||
|
if widget.err != nil {
|
||||||
|
str = widget.err.Error()
|
||||||
|
} else {
|
||||||
for idx, build := range widget.builds.Builds {
|
for idx, build := range widget.builds.Builds {
|
||||||
|
|
||||||
row := fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
@ -80,6 +83,7 @@ func (widget *Widget) content() (string, string, bool) {
|
|||||||
)
|
)
|
||||||
str += utils.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name))
|
str += utils.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return title, str, false
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
@ -62,7 +62,7 @@ func (widget *Widget) HelpText() string {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -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.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, content, true })
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, content, true })
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ type Widget struct {
|
|||||||
|
|
||||||
teams []OnCallTeam
|
teams []OnCallTeam
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWidget creates a new widget
|
// NewWidget creates a new widget
|
||||||
@ -36,18 +37,25 @@ func (widget *Widget) Refresh() {
|
|||||||
teams, err := Fetch(widget.settings.apiID, widget.settings.apiKey)
|
teams, err := Fetch(widget.settings.apiID, widget.settings.apiKey)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
|
widget.err = err
|
||||||
|
widget.teams = nil
|
||||||
} else {
|
} else {
|
||||||
|
widget.err = nil
|
||||||
widget.teams = teams
|
widget.teams = teams
|
||||||
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(widget.teams), true)
|
|
||||||
}
|
}
|
||||||
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom(teams []OnCallTeam) string {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := widget.CommonSettings().Title
|
||||||
|
if widget.err != nil {
|
||||||
|
return title, widget.err.Error(), true
|
||||||
|
}
|
||||||
|
teams := widget.teams
|
||||||
var str string
|
var str string
|
||||||
|
|
||||||
if teams == nil || len(teams) == 0 {
|
if teams == nil || len(teams) == 0 {
|
||||||
return "No teams specified"
|
return title, "No teams specified", false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, team := range teams {
|
for _, team := range teams {
|
||||||
@ -69,5 +77,5 @@ func (widget *Widget) contentFrom(teams []OnCallTeam) string {
|
|||||||
if len(str) == 0 {
|
if len(str) == 0 {
|
||||||
str = "Could not find any teams to display"
|
str = "Could not find any teams to display"
|
||||||
}
|
}
|
||||||
return str
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
@ -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.RedrawFunc(func() (string, string, bool) { return widget.CommonSettings().Title, widget.result, false })
|
widget.Redraw(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,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -53,7 +53,7 @@ func (widget *Widget) Refresh() {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
widget.RedrawFunc(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
@ -72,8 +72,8 @@ func (widget *ScrollableWidget) Unselect() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *ScrollableWidget) Redraw(title, content string, wrap bool) {
|
func (widget *ScrollableWidget) Redraw(data func() (string, string, bool)) {
|
||||||
widget.TextWidget.Redraw(title, content, wrap)
|
widget.TextWidget.Redraw(data)
|
||||||
widget.app.QueueUpdateDraw(func() {
|
widget.app.QueueUpdateDraw(func() {
|
||||||
widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight()
|
widget.View.Highlight(strconv.Itoa(widget.Selected)).ScrollToHighlight()
|
||||||
})
|
})
|
||||||
|
@ -29,16 +29,7 @@ func (widget *TextWidget) TextView() *tview.TextView {
|
|||||||
return widget.View
|
return widget.View
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *TextWidget) Redraw(title, text string, wrap bool) {
|
func (widget *TextWidget) Redraw(data func() (string, string, bool)) {
|
||||||
widget.app.QueueUpdateDraw(func() {
|
|
||||||
widget.View.Clear()
|
|
||||||
widget.View.SetWrap(wrap)
|
|
||||||
widget.View.SetTitle(widget.ContextualTitle(title))
|
|
||||||
widget.View.SetText(text)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *TextWidget) RedrawFunc(data func() (string, string, bool)) {
|
|
||||||
widget.app.QueueUpdateDraw(func() {
|
widget.app.QueueUpdateDraw(func() {
|
||||||
title, content, wrap := data()
|
title, content, wrap := data()
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user