mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
package gspreadsheets
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/rivo/tview"
|
|
"github.com/wtfutil/wtf/view"
|
|
"github.com/wtfutil/wtf/wtf"
|
|
sheets "google.golang.org/api/sheets/v4"
|
|
)
|
|
|
|
type Widget struct {
|
|
view.TextWidget
|
|
|
|
settings *Settings
|
|
}
|
|
|
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|
widget := Widget{
|
|
TextWidget: view.NewTextWidget(app, settings.common, false),
|
|
|
|
settings: settings,
|
|
}
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
cells, _ := widget.Fetch()
|
|
|
|
widget.Redraw(widget.CommonSettings().Title, widget.contentFrom(cells), false)
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) contentFrom(valueRanges []*sheets.ValueRange) string {
|
|
if valueRanges == nil {
|
|
return "error 1"
|
|
}
|
|
|
|
res := ""
|
|
|
|
cells := wtf.ToStrs(widget.settings.cellNames)
|
|
for i := 0; i < len(valueRanges); i++ {
|
|
res += fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, valueRanges[i].Values[0][0])
|
|
}
|
|
|
|
return res
|
|
}
|