From 787d1a3ba9466f858e33fdd901b2e11234b68caa Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 23:14:44 -0700 Subject: [PATCH] BarGraph supports customizable titles in config --- view/bargraph.go | 17 ++++++++--------- view/text_widget.go | 10 ++++------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/view/bargraph.go b/view/bargraph.go index afde39cb..1b79f153 100644 --- a/view/bargraph.go +++ b/view/bargraph.go @@ -34,18 +34,13 @@ func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common starChar: commonSettings.Config.UString("graphIcon", "|"), } - widget.View = widget.addView() - widget.View.SetBorder(widget.bordered) + widget.View = widget.addView(widget.bordered) return widget } /* -------------------- Exported Functions -------------------- */ -func (widget *BarGraph) TextView() *tview.TextView { - return widget.View -} - // BuildBars will build a string of * to represent your data of [time][value] // time should be passed as a int64 func (widget *BarGraph) BuildBars(data []Bar) { @@ -98,16 +93,20 @@ func BuildStars(data []Bar, maxStars int, starChar string) string { return buffer.String() } +func (widget *BarGraph) TextView() *tview.TextView { + return widget.View +} + /* -------------------- Unexported Functions -------------------- */ -func (widget *BarGraph) addView() *tview.TextView { +func (widget *BarGraph) addView(bordered bool) *tview.TextView { view := tview.NewTextView() view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background)) - view.SetBorder(true) + view.SetBorder(bordered) view.SetBorderColor(wtf.ColorFor(widget.BorderColor())) view.SetDynamicColors(true) - view.SetTitle(widget.Name()) + view.SetTitle(widget.ContextualTitle(widget.CommonSettings().Title)) view.SetTitleColor(wtf.ColorFor(widget.commonSettings.Colors.Title)) view.SetWrap(false) diff --git a/view/text_widget.go b/view/text_widget.go index 1654c179..ee2bf140 100644 --- a/view/text_widget.go +++ b/view/text_widget.go @@ -16,8 +16,7 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable Base: NewBase(app, commonSettings, focusable), } - widget.View = widget.addView() - widget.View.SetBorder(widget.bordered) + widget.View = widget.addView(widget.bordered) return widget } @@ -39,16 +38,15 @@ func (widget *TextWidget) Redraw(title, text string, wrap bool) { /* -------------------- Unexported Functions -------------------- */ -func (widget *TextWidget) addView() *tview.TextView { +func (widget *TextWidget) addView(bordered bool) *tview.TextView { view := tview.NewTextView() view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background)) + view.SetBorder(bordered) view.SetBorderColor(wtf.ColorFor(widget.BorderColor())) + view.SetDynamicColors(true) view.SetTextColor(wtf.ColorFor(widget.commonSettings.Colors.Text)) view.SetTitleColor(wtf.ColorFor(widget.commonSettings.Colors.Title)) - - view.SetBorder(true) - view.SetDynamicColors(true) view.SetWrap(false) return view