mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Extract common attributes from BarGraph and TextWidget into Base
This commit is contained in:
parent
98eb3c9013
commit
275ea37a01
@ -12,19 +12,10 @@ import (
|
|||||||
|
|
||||||
//BarGraph lets make graphs
|
//BarGraph lets make graphs
|
||||||
type BarGraph struct {
|
type BarGraph struct {
|
||||||
app *tview.Application
|
|
||||||
bordered bool
|
|
||||||
commonSettings *cfg.Common
|
|
||||||
enabled bool
|
|
||||||
focusable bool
|
|
||||||
key string
|
|
||||||
maxStars int
|
maxStars int
|
||||||
name string
|
|
||||||
quitChan chan bool
|
|
||||||
refreshing bool
|
|
||||||
refreshInterval int
|
|
||||||
starChar string
|
starChar string
|
||||||
|
|
||||||
|
Base
|
||||||
View *tview.TextView
|
View *tview.TextView
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,16 +28,18 @@ type Bar struct {
|
|||||||
// NewBarGraph initialize your fancy new graph
|
// NewBarGraph initialize your fancy new graph
|
||||||
func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common, focusable bool) BarGraph {
|
func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common, focusable bool) BarGraph {
|
||||||
widget := BarGraph{
|
widget := BarGraph{
|
||||||
commonSettings: commonSettings,
|
Base: Base{
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
bordered: commonSettings.Bordered,
|
bordered: commonSettings.Bordered,
|
||||||
|
commonSettings: commonSettings,
|
||||||
enabled: commonSettings.Enabled,
|
enabled: commonSettings.Enabled,
|
||||||
focusable: focusable,
|
focusable: focusable,
|
||||||
maxStars: commonSettings.Config.UInt("graphStars", 20),
|
|
||||||
name: commonSettings.Title,
|
name: commonSettings.Title,
|
||||||
quitChan: make(chan bool),
|
quitChan: make(chan bool),
|
||||||
refreshInterval: commonSettings.RefreshInterval,
|
refreshInterval: commonSettings.RefreshInterval,
|
||||||
|
},
|
||||||
|
|
||||||
|
maxStars: commonSettings.Config.UInt("graphStars", 20),
|
||||||
starChar: commonSettings.Config.UString("graphIcon", "|"),
|
starChar: commonSettings.Config.UString("graphIcon", "|"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
view/base.go
Normal file
20
view/base.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package view
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/rivo/tview"
|
||||||
|
"github.com/wtfutil/wtf/cfg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Base struct {
|
||||||
|
app *tview.Application
|
||||||
|
bordered bool
|
||||||
|
commonSettings *cfg.Common
|
||||||
|
enabled bool
|
||||||
|
focusChar string
|
||||||
|
focusable bool
|
||||||
|
key string
|
||||||
|
name string
|
||||||
|
quitChan chan bool
|
||||||
|
refreshing bool
|
||||||
|
refreshInterval int
|
||||||
|
}
|
@ -10,24 +10,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TextWidget struct {
|
type TextWidget struct {
|
||||||
app *tview.Application
|
Base
|
||||||
bordered bool
|
|
||||||
commonSettings *cfg.Common
|
|
||||||
enabled bool
|
|
||||||
focusChar string
|
|
||||||
focusable bool
|
|
||||||
name string
|
|
||||||
quitChan chan bool
|
|
||||||
refreshInterval int
|
|
||||||
refreshing bool
|
|
||||||
|
|
||||||
View *tview.TextView
|
View *tview.TextView
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget {
|
func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget {
|
||||||
widget := TextWidget{
|
widget := TextWidget{
|
||||||
|
Base: Base{
|
||||||
commonSettings: commonSettings,
|
commonSettings: commonSettings,
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
bordered: commonSettings.Bordered,
|
bordered: commonSettings.Bordered,
|
||||||
enabled: commonSettings.Enabled,
|
enabled: commonSettings.Enabled,
|
||||||
@ -37,6 +27,7 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable
|
|||||||
quitChan: make(chan bool),
|
quitChan: make(chan bool),
|
||||||
refreshInterval: commonSettings.RefreshInterval,
|
refreshInterval: commonSettings.RefreshInterval,
|
||||||
refreshing: false,
|
refreshing: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.View = widget.addView()
|
widget.View = widget.addView()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user