1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/view/text_widget.go
Chris Cummer 200dbcc03c
WTF-730 Fix missing color key config error (#738)
* WTF-730 Fix missing color key config error

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Add Subheading color formatting to modules

Users can now set a `subheading` color in their config to change the
color of subheadings in widget display.

Defaults to `red`.

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix oustanding color issues

Clean up missing color config changes not addressed in earlier commits.

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Remove unused dependency

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Base cleanup

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix a few bugs related to color config changes

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix issues with PagerDuty subheading display

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix bug with Todo list colour rendering

Signed-off-by: Chris Cummer <chriscummer@me.com>
2019-11-09 11:21:45 -08:00

57 lines
1.5 KiB
Go

package view
import (
"github.com/rivo/tview"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf"
)
// TextWidget defines the data necessary to make a text widget
type TextWidget struct {
Base
View *tview.TextView
}
// NewTextWidget creates and returns an instance of TextWidget
func NewTextWidget(app *tview.Application, commonSettings *cfg.Common) TextWidget {
widget := TextWidget{
Base: NewBase(app, commonSettings),
}
widget.View = widget.createView(widget.bordered)
return widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *TextWidget) TextView() *tview.TextView {
return widget.View
}
func (widget *TextWidget) Redraw(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 -------------------- */
func (widget *TextWidget) createView(bordered bool) *tview.TextView {
view := tview.NewTextView()
view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.WidgetTheme.Background))
view.SetBorder(bordered)
view.SetBorderColor(wtf.ColorFor(widget.BorderColor()))
view.SetDynamicColors(true)
view.SetTextColor(wtf.ColorFor(widget.commonSettings.Colors.TextTheme.Text))
view.SetTitleColor(wtf.ColorFor(widget.commonSettings.Colors.TextTheme.Title))
view.SetWrap(false)
return view
}