mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add ability to explicitly stop modules via a QuitChan
This commit is contained in:
@@ -17,6 +17,7 @@ type BarGraph struct {
|
||||
key string
|
||||
maxStars int
|
||||
name string
|
||||
quitChan chan bool
|
||||
refreshing bool
|
||||
starChar string
|
||||
|
||||
@@ -37,9 +38,11 @@ func NewBarGraph(app *tview.Application, name string, settings *cfg.Common, focu
|
||||
focusable: focusable,
|
||||
maxStars: settings.Config.UInt("graphStars", 20),
|
||||
name: settings.Title,
|
||||
quitChan: make(chan bool),
|
||||
starChar: settings.Config.UString("graphIcon", "|"),
|
||||
RefreshInt: settings.RefreshInterval,
|
||||
commonSettings: settings,
|
||||
|
||||
RefreshInt: settings.RefreshInterval,
|
||||
}
|
||||
|
||||
widget.View = widget.addView()
|
||||
@@ -90,6 +93,10 @@ func (widget *BarGraph) Name() string {
|
||||
return widget.name
|
||||
}
|
||||
|
||||
func (widget *BarGraph) QuitChan() chan bool {
|
||||
return widget.quitChan
|
||||
}
|
||||
|
||||
// Refreshing returns TRUE if the widget is currently refreshing its data, FALSE if it is not
|
||||
func (widget *BarGraph) Refreshing() bool {
|
||||
return widget.refreshing
|
||||
@@ -104,6 +111,11 @@ func (widget *BarGraph) SetFocusChar(char string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (widget *BarGraph) Stop() {
|
||||
widget.enabled = false
|
||||
widget.quitChan <- true
|
||||
}
|
||||
|
||||
func (widget *BarGraph) TextView() *tview.TextView {
|
||||
return widget.View
|
||||
}
|
||||
|
||||
6
wtf/stoppable.go
Normal file
6
wtf/stoppable.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package wtf
|
||||
|
||||
// Stoppable is the interface that enforces a stoppable state
|
||||
type Stoppable interface {
|
||||
Stop()
|
||||
}
|
||||
@@ -15,6 +15,7 @@ type TextWidget struct {
|
||||
focusable bool
|
||||
focusChar string
|
||||
name string
|
||||
quitChan chan bool
|
||||
refreshing bool
|
||||
refreshInterval int
|
||||
app *tview.Application
|
||||
@@ -32,6 +33,7 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable
|
||||
focusable: focusable,
|
||||
focusChar: commonSettings.FocusChar(),
|
||||
name: commonSettings.Name,
|
||||
quitChan: make(chan bool),
|
||||
refreshing: false,
|
||||
refreshInterval: commonSettings.RefreshInterval,
|
||||
}
|
||||
@@ -97,6 +99,10 @@ func (widget *TextWidget) HelpText() string {
|
||||
return fmt.Sprintf("\n There is no help available for widget %s", widget.commonSettings.Module.Type)
|
||||
}
|
||||
|
||||
func (widget *TextWidget) QuitChan() chan bool {
|
||||
return widget.quitChan
|
||||
}
|
||||
|
||||
func (widget *TextWidget) Name() string {
|
||||
return widget.name
|
||||
}
|
||||
@@ -115,6 +121,11 @@ func (widget *TextWidget) SetFocusChar(char string) {
|
||||
widget.focusChar = char
|
||||
}
|
||||
|
||||
func (widget *TextWidget) Stop() {
|
||||
widget.enabled = false
|
||||
widget.quitChan <- true
|
||||
}
|
||||
|
||||
func (widget *TextWidget) String() string {
|
||||
return widget.name
|
||||
}
|
||||
|
||||
@@ -10,12 +10,14 @@ import (
|
||||
type Wtfable interface {
|
||||
Enablable
|
||||
Schedulable
|
||||
Stoppable
|
||||
|
||||
BorderColor() string
|
||||
ConfigText() string
|
||||
FocusChar() string
|
||||
Focusable() bool
|
||||
HelpText() string
|
||||
QuitChan() chan bool
|
||||
Name() string
|
||||
SetFocusChar(string)
|
||||
TextView() *tview.TextView
|
||||
|
||||
Reference in New Issue
Block a user