mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Convert the bulk of modules over to RedrawFunc
This commit is contained in:
parent
51e4325f0b
commit
3a716bcf9a
@ -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() {
|
||||||
|
|
||||||
|
widget.RedrawFunc(widget.content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
if ok == false {
|
if ok == false {
|
||||||
widget.Redraw(widget.CommonSettings().Title, errorText, true)
|
return widget.CommonSettings().Title, errorText, true
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
list := &widget.summaryList
|
||||||
summaryText := widget.summaryText(&widget.summaryList)
|
|
||||||
widget.Redraw(widget.CommonSettings().Title, summaryText, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) summaryText(list *summaryList) string {
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
@ -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) content() (string, string, bool) {
|
||||||
}
|
title := widget.settings.common.Title
|
||||||
|
calEvents := widget.calEvents
|
||||||
func (widget *Widget) contentFrom(calEvents []*CalEvent) string {
|
|
||||||
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 {
|
||||||
|
@ -72,15 +72,14 @@ func (widget *Widget) HelpText() string {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
func (widget *Widget) display() {
|
||||||
if widget.messages == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
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.roomURI)
|
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 widget.messages {
|
for idx, message := range widget.messages {
|
||||||
row := fmt.Sprintf(
|
row := fmt.Sprintf(
|
||||||
|
@ -67,10 +67,6 @@ 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 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
widget.RedrawFunc(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +75,9 @@ func (widget *Widget) Render() {
|
|||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
title := fmt.Sprintf("%s - %s stories", widget.CommonSettings().Title, widget.settings.storyType)
|
title := fmt.Sprintf("%s - %s stories", widget.CommonSettings().Title, widget.settings.storyType)
|
||||||
stories := widget.stories
|
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 {
|
||||||
|
@ -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
|
||||||
|
@ -59,15 +59,14 @@ func (widget *Widget) Refresh() {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Render() {
|
func (widget *Widget) Render() {
|
||||||
if widget.view == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.RedrawFunc(widget.content)
|
widget.RedrawFunc(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 {
|
||||||
|
return title, "No content to display", false
|
||||||
|
}
|
||||||
|
|
||||||
var str string
|
var str string
|
||||||
jobs := widget.view.Jobs
|
jobs := widget.view.Jobs
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user