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
|
||||
type BarGraph struct {
|
||||
app *tview.Application
|
||||
bordered bool
|
||||
commonSettings *cfg.Common
|
||||
enabled bool
|
||||
focusable bool
|
||||
key string
|
||||
maxStars int
|
||||
name string
|
||||
quitChan chan bool
|
||||
refreshing bool
|
||||
refreshInterval int
|
||||
starChar string
|
||||
maxStars int
|
||||
starChar string
|
||||
|
||||
Base
|
||||
View *tview.TextView
|
||||
}
|
||||
|
||||
@ -37,17 +28,19 @@ type Bar struct {
|
||||
// NewBarGraph initialize your fancy new graph
|
||||
func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common, focusable bool) BarGraph {
|
||||
widget := BarGraph{
|
||||
commonSettings: commonSettings,
|
||||
Base: Base{
|
||||
app: app,
|
||||
bordered: commonSettings.Bordered,
|
||||
commonSettings: commonSettings,
|
||||
enabled: commonSettings.Enabled,
|
||||
focusable: focusable,
|
||||
name: commonSettings.Title,
|
||||
quitChan: make(chan bool),
|
||||
refreshInterval: commonSettings.RefreshInterval,
|
||||
},
|
||||
|
||||
app: app,
|
||||
bordered: commonSettings.Bordered,
|
||||
enabled: commonSettings.Enabled,
|
||||
focusable: focusable,
|
||||
maxStars: commonSettings.Config.UInt("graphStars", 20),
|
||||
name: commonSettings.Title,
|
||||
quitChan: make(chan bool),
|
||||
refreshInterval: commonSettings.RefreshInterval,
|
||||
starChar: commonSettings.Config.UString("graphIcon", "|"),
|
||||
maxStars: commonSettings.Config.UInt("graphStars", 20),
|
||||
starChar: commonSettings.Config.UString("graphIcon", "|"),
|
||||
}
|
||||
|
||||
widget.View = widget.addView()
|
||||
|
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,33 +10,24 @@ import (
|
||||
)
|
||||
|
||||
type TextWidget struct {
|
||||
app *tview.Application
|
||||
bordered bool
|
||||
commonSettings *cfg.Common
|
||||
enabled bool
|
||||
focusChar string
|
||||
focusable bool
|
||||
name string
|
||||
quitChan chan bool
|
||||
refreshInterval int
|
||||
refreshing bool
|
||||
|
||||
Base
|
||||
View *tview.TextView
|
||||
}
|
||||
|
||||
func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget {
|
||||
widget := TextWidget{
|
||||
commonSettings: commonSettings,
|
||||
|
||||
app: app,
|
||||
bordered: commonSettings.Bordered,
|
||||
enabled: commonSettings.Enabled,
|
||||
focusChar: commonSettings.FocusChar(),
|
||||
focusable: focusable,
|
||||
name: commonSettings.Name,
|
||||
quitChan: make(chan bool),
|
||||
refreshInterval: commonSettings.RefreshInterval,
|
||||
refreshing: false,
|
||||
Base: Base{
|
||||
commonSettings: commonSettings,
|
||||
app: app,
|
||||
bordered: commonSettings.Bordered,
|
||||
enabled: commonSettings.Enabled,
|
||||
focusChar: commonSettings.FocusChar(),
|
||||
focusable: focusable,
|
||||
name: commonSettings.Name,
|
||||
quitChan: make(chan bool),
|
||||
refreshInterval: commonSettings.RefreshInterval,
|
||||
refreshing: false,
|
||||
},
|
||||
}
|
||||
|
||||
widget.View = widget.addView()
|
||||
|
Loading…
x
Reference in New Issue
Block a user