Add Pi-hole blocked percentage and date widgets
This commit is contained in:
42
widgets/date.go
Normal file
42
widgets/date.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"ArinDash/util"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/mum4k/termdash/terminal/terminalapi"
|
||||
"github.com/mum4k/termdash/widgetapi"
|
||||
"github.com/mum4k/termdash/widgets/text"
|
||||
)
|
||||
|
||||
type DateOptions struct {
|
||||
}
|
||||
|
||||
func Date() DateOptions {
|
||||
widgetOptions["DateOptions"] = createDate
|
||||
return DateOptions{}
|
||||
}
|
||||
|
||||
func createDate(ctx context.Context, _ terminalapi.Terminal, _ interface{}) widgetapi.Widget {
|
||||
widget := util.PanicOnErrorWithResult(text.New())
|
||||
|
||||
go util.Periodic(ctx, 1*time.Second, func() error {
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
now := time.Now()
|
||||
if err := widget.Write(now.Format("Monday 2.1.2006"), text.WriteReplace()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return widget
|
||||
}
|
||||
36
widgets/piholeblocked.go
Normal file
36
widgets/piholeblocked.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"ArinDash/apis/pihole"
|
||||
"ArinDash/util"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/mum4k/termdash/cell"
|
||||
"github.com/mum4k/termdash/terminal/terminalapi"
|
||||
"github.com/mum4k/termdash/widgetapi"
|
||||
"github.com/mum4k/termdash/widgets/donut"
|
||||
)
|
||||
|
||||
type PiholeBlockedOptions struct {
|
||||
}
|
||||
|
||||
func PiholeBlocked() PiholeBlockedOptions {
|
||||
widgetOptions["PiholeBlockedOptions"] = createPiholeBlocked
|
||||
return PiholeBlockedOptions{}
|
||||
}
|
||||
|
||||
func createPiholeBlocked(ctx context.Context, _ terminalapi.Terminal, _ interface{}) widgetapi.Widget {
|
||||
widget := util.PanicOnErrorWithResult(donut.New(donut.CellOpts(cell.FgColor(cell.ColorRed), cell.Blink()), donut.HolePercent(20), donut.ShowTextProgress()))
|
||||
|
||||
ph := pihole.Connect()
|
||||
go util.Periodic(ctx, 1*time.Minute, func() error {
|
||||
summary := ph.Summary()
|
||||
if err := widget.Percent(int(summary.Queries.PercentBlocked)); err != nil {
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return widget
|
||||
}
|
||||
Reference in New Issue
Block a user