mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* WTF-1031 Rename WtfApp.app to WtfApp.tviewApp Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-1031 Add scaffolding for main to support multiple WtfApp instances Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-1031 WIP Signed-off-by: Chris Cummer <chriscummer@me.com> * Remove common functionality from KeyboardWidget and into Base Signed-off-by: Chris Cummer <chriscummer@me.com> * Augment with some descriptive comments Signed-off-by: Chris Cummer <chriscummer@me.com> * Add full support for multiple app instances via the AppManager. Still to do: * Config support for multiple apps/multiple config files * The ability to switch between apps Signed-off-by: Chris Cummer <chriscummer@me.com> * Move SetTerminal out of main and into its own file Signed-off-by: Chris Cummer <chriscummer@me.com>
73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
package view
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"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
|
|
*KeyboardWidget
|
|
|
|
View *tview.TextView
|
|
|
|
tviewApp *tview.Application
|
|
}
|
|
|
|
// NewTextWidget creates and returns an instance of TextWidget
|
|
func NewTextWidget(tviewApp *tview.Application, pages *tview.Pages, commonSettings *cfg.Common) TextWidget {
|
|
widget := TextWidget{
|
|
Base: NewBase(tviewApp, pages, commonSettings),
|
|
KeyboardWidget: NewKeyboardWidget(commonSettings),
|
|
|
|
tviewApp: tviewApp,
|
|
}
|
|
|
|
widget.View = widget.createView(widget.bordered)
|
|
widget.View.SetInputCapture(widget.KeyboardWidget.InputCapture)
|
|
|
|
widget.Base.SetView(widget.View)
|
|
widget.Base.helpTextFunc = widget.KeyboardWidget.HelpText
|
|
|
|
return widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
// TextView returns the tview.TextView instance
|
|
func (widget *TextWidget) TextView() *tview.TextView {
|
|
return widget.View
|
|
}
|
|
|
|
// Redraw forces a refresh of the onscreen text content of this widget
|
|
func (widget *TextWidget) Redraw(data func() (string, string, bool)) {
|
|
widget.tviewApp.QueueUpdateDraw(func() {
|
|
title, content, wrap := data()
|
|
|
|
widget.View.Clear()
|
|
widget.View.SetWrap(wrap)
|
|
widget.View.SetTitle(widget.ContextualTitle(title))
|
|
widget.View.SetText(strings.TrimRight(content, "\n"))
|
|
})
|
|
}
|
|
|
|
/* -------------------- 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
|
|
}
|