Repository navigation
Expand file tree
/
Copy pathtext_widget.go
More file actions
72 lines (55 loc) · 1.96 KB
/
Copy pathtext_widget.go
File metadata and controls
72 lines (55 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
}
// NewTextWidget creates and returns an instance of TextWidget
func NewTextWidget(tviewApp *tview.Application, redrawChan chan bool, pages *tview.Pages, commonSettings *cfg.Common) TextWidget {
widget := TextWidget{
Base: NewBase(tviewApp, redrawChan, pages, commonSettings),
KeyboardWidget: NewKeyboardWidget(commonSettings),
}
widget.View = widget.createView(widget.bordered)
widget.View.SetInputCapture(widget.InputCapture)
widget.SetView(widget.View)
widget.helpTextFunc = widget.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)) {
title, content, wrap := data()
widget.View.Clear()
widget.View.SetWrap(wrap)
widget.View.SetTitle(widget.ContextualTitle(title))
widget.View.SetText(strings.TrimRight(content, "\n"))
// Non-blocking send to avoid deadlock when multiple widgets refresh simultaneously
select {
case widget.RedrawChan <- true:
default:
}
}
/* -------------------- Unexported Functions -------------------- */
func (widget *TextWidget) createView(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.SetWrap(false)
return view
}