summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cloudflare/durationSlider.go83
-rw-r--r--cloudflare/oneLiner.go48
-rw-r--r--dnsLookupStatus.go30
-rw-r--r--gui.go7
-rw-r--r--structs.go8
5 files changed, 23 insertions, 153 deletions
diff --git a/cloudflare/durationSlider.go b/cloudflare/durationSlider.go
deleted file mode 100644
index 1ab0e50..0000000
--- a/cloudflare/durationSlider.go
+++ /dev/null
@@ -1,83 +0,0 @@
-// This is a simple example
-package cloudflare
-
-import (
- "log"
- "fmt"
- "time"
-
- "go.wit.com/gui"
-)
-
-// TODO: use: https://github.com/robfig/cron/
-
-// ttl := cloudflare.DurationSlider(g2, "control panel TTL (in tenths of seconds)", 10 * time.Millisecond, 5 * time.Second)
-// ttl.Set(200 * time.Millisecond)
-
-// The Node is a binary tree. This is how all GUI elements are stored
-// simply the name and the size of whatever GUI element exists
-type Duration struct {
- p *gui.Node // parent widget
- l *gui.Node // label widget
- s *gui.Node // slider widget
-
- Label string
- Low time.Duration
- High time.Duration
- Duration time.Duration
-
- Custom func()
-}
-
-func (n *Duration) Set(d time.Duration) {
- var timeRange, step, offset time.Duration
-
- if (d > n.High) {
- d = n.High
- }
- if (d < n.Low) {
- d = n.Low
- }
-
- // set the duration
- n.Duration = d
-
- // figure out the integer offset for the Slider GUI Widget
- timeRange = n.High - n.Low
- step = timeRange / 1000
- if (step == 0) {
- log.Println("duration.Set() division by step == 0", n.Low, n.High, timeRange, step)
- n.s.Set(0)
- return
- }
- offset = d - n.Low
- i := int(offset / step)
- log.Println("duration.Set() =", n.Low, n.High, d, "i =", i)
- n.s.I = i
- n.s.Set(i)
- n.s.Custom()
-}
-
-func NewDurationSlider(n *gui.Node, label string, low time.Duration, high time.Duration) *Duration {
- d := Duration {
- p: n,
- Label: label,
- High: high,
- Low: low,
- }
-
- // various timeout settings
- d.l = n.NewLabel(label)
- d.s = n.NewSlider(label, 0, 1000)
- d.s.Custom = func () {
- d.Duration = low + (high - low) * time.Duration(d.s.I) / 1000
- log.Println("d.Duration =", d.Duration)
- s := fmt.Sprintf("%s (%v)", d.Label, d.Duration)
- d.l.SetText(s)
- if (d.Custom != nil) {
- d.Custom()
- }
- }
-
- return &d
-}
diff --git a/cloudflare/oneLiner.go b/cloudflare/oneLiner.go
deleted file mode 100644
index 230f370..0000000
--- a/cloudflare/oneLiner.go
+++ /dev/null
@@ -1,48 +0,0 @@
-// This is a simple example
-package cloudflare
-
-import (
- "go.wit.com/log"
- "go.wit.com/gui"
-)
-
-type OneLiner struct {
- p *gui.Node // parent widget
- l *gui.Node // label widget
- v *gui.Node // value widget
-
- value string
- label string
-
- Custom func()
-}
-
-func (n *OneLiner) Get() string {
- return n.value
-}
-
-func (n *OneLiner) Set(value string) *OneLiner {
- log.Println("OneLiner.Set() =", value)
- if (n.v != nil) {
- n.v.Set(value)
- }
- n.value = value
- return n
-}
-
-func NewOneLiner(n *gui.Node, name string) *OneLiner {
- d := OneLiner {
- p: n,
- value: "",
- }
-
- // various timeout settings
- d.l = n.NewLabel(name)
- d.v = n.NewLabel("")
- d.v.Custom = func() {
- d.value = d.v.S
- log.Println("OneLiner.Custom() user changed value to =", d.value)
- }
-
- return &d
-}
diff --git a/dnsLookupStatus.go b/dnsLookupStatus.go
index 9166f72..d146464 100644
--- a/dnsLookupStatus.go
+++ b/dnsLookupStatus.go
@@ -21,7 +21,7 @@ import (
"go.wit.com/log"
"go.wit.com/gui"
- "go.wit.com/control-panel-dns/cloudflare"
+ "go.wit.com/gui/gadgets"
"go.wit.com/shell"
"github.com/miekg/dns"
@@ -40,10 +40,10 @@ type digStatus struct {
box *gui.Node
summary *gui.Node
- status *cloudflare.OneLiner
- statusAAAA *cloudflare.OneLiner
- speed *cloudflare.OneLiner
- speedActual *cloudflare.OneLiner
+ status *gadgets.OneLiner
+ statusAAAA *gadgets.OneLiner
+ speed *gadgets.OneLiner
+ speedActual *gadgets.OneLiner
details *gui.Node
dsLocalhost *dnsStatus
@@ -53,8 +53,8 @@ type digStatus struct {
DnsDigUDP *gui.Node
DnsDigTCP *gui.Node
- httpGoWitCom *cloudflare.OneLiner
- statusHTTP *cloudflare.OneLiner
+ httpGoWitCom *gadgets.OneLiner
+ statusHTTP *gadgets.OneLiner
}
type dnsStatus struct {
@@ -104,11 +104,11 @@ func NewDigStatusWindow(p *gui.Node) *digStatus {
g := ds.summary.NewGrid("LookupStatus", 2, 2)
g.Pad()
- ds.status = cloudflare.NewOneLiner(g, "status").Set("unknown")
- ds.statusAAAA = cloudflare.NewOneLiner(g, "IPv6 status").Set("unknown")
- ds.statusHTTP = cloudflare.NewOneLiner(g, "IPv6 via HTTP").Set("unknown")
- ds.speed = cloudflare.NewOneLiner(g, "speed").Set("unknown")
- ds.speedActual = cloudflare.NewOneLiner(g, "actual").Set("unknown")
+ ds.status = gadgets.NewOneLiner(g, "status").Set("unknown")
+ ds.statusAAAA = gadgets.NewOneLiner(g, "IPv6 status").Set("unknown")
+ ds.statusHTTP = gadgets.NewOneLiner(g, "IPv6 via HTTP").Set("unknown")
+ ds.speed = gadgets.NewOneLiner(g, "speed").Set("unknown")
+ ds.speedActual = gadgets.NewOneLiner(g, "actual").Set("unknown")
// make the area to store the raw details
ds.details = ds.box.NewGroup("Details")
@@ -200,9 +200,9 @@ func (ds *digStatus) set(a any, s string) {
n.SetText(s)
return
}
- var ol *cloudflare.OneLiner
+ var ol *gadgets.OneLiner
if reflect.TypeOf(a) == reflect.TypeOf(ol) {
- ol = a.(*cloudflare.OneLiner)
+ ol = a.(*gadgets.OneLiner)
ol.Set(s)
return
}
@@ -374,7 +374,7 @@ func (ds *digStatus) makeHttpStatusGrid() {
group := ds.details.NewGroup("dns.google.com via HTTPS")
grid := group.NewGrid("LookupStatus", 2, 2)
- ds.httpGoWitCom = cloudflare.NewOneLiner(grid, "go.wit.com")
+ ds.httpGoWitCom = gadgets.NewOneLiner(grid, "go.wit.com")
me.digStatus.set(ds.httpGoWitCom, "unknown")
group.Pad()
diff --git a/gui.go b/gui.go
index 3301712..abc0485 100644
--- a/gui.go
+++ b/gui.go
@@ -11,6 +11,7 @@ import (
"strings"
"go.wit.com/gui"
+ "go.wit.com/gui/gadgets"
"go.wit.com/log"
"go.wit.com/shell"
"go.wit.com/control-panel-dns/cloudflare"
@@ -178,11 +179,11 @@ func debugTab(title string) {
}
// makes a slider widget
- me.ttl = cloudflare.NewDurationSlider(g2, "Loop Timeout", 10 * time.Millisecond, 5 * time.Second)
+ me.ttl = gadgets.NewDurationSlider(g2, "Loop Timeout", 10 * time.Millisecond, 5 * time.Second)
me.ttl.Set(300 * time.Millisecond)
// makes a slider widget
- me.dnsTtl = cloudflare.NewDurationSlider(g2, "DNS Timeout", 800 * time.Millisecond, 300 * time.Second)
+ me.dnsTtl = gadgets.NewDurationSlider(g2, "DNS Timeout", 800 * time.Millisecond, 300 * time.Second)
me.dnsTtl.Set(60 * time.Second)
g2.Margin()
@@ -358,7 +359,7 @@ func statusGrid(n *gui.Node) {
gridP.NewLabel("DNS Status =")
me.DnsStatus = gridP.NewLabel("unknown")
- me.statusIPv6 = cloudflare.NewOneLiner(gridP, "IPv6 working")
+ me.statusIPv6 = gadgets.NewOneLiner(gridP, "IPv6 working")
me.statusIPv6.Set("known")
gridP.NewLabel("hostname =")
diff --git a/structs.go b/structs.go
index a75c518..7b30611 100644
--- a/structs.go
+++ b/structs.go
@@ -5,7 +5,7 @@ import (
"net"
"time"
"go.wit.com/gui"
- "go.wit.com/control-panel-dns/cloudflare"
+ "go.wit.com/gui/gadgets"
"github.com/miekg/dns"
)
@@ -24,8 +24,8 @@ type Host struct {
artificialSleep float64 `default:"0.7"` // artificial sleep on startup
artificialS string `default:"abc"` // artificial sleep on startup
- ttl *cloudflare.Duration
- dnsTtl *cloudflare.Duration
+ ttl *gadgets.Duration
+ dnsTtl *gadgets.Duration
dnsSleep time.Duration
localSleep time.Duration
@@ -75,7 +75,7 @@ type Host struct {
dbProc *gui.Node // button for setting proc debugging on
digStatus *digStatus
- statusIPv6 *cloudflare.OneLiner
+ statusIPv6 *gadgets.OneLiner
digStatusButton *gui.Node
hostnameStatus *hostnameStatus