summaryrefslogtreecommitdiffstats
path: root/widgets/disk.go
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2018-02-18 23:25:02 -0800
committerCaleb Bassi <calebjbassi@gmail.com>2018-02-19 02:00:21 -0800
commit40775db60b90cd290a206108cc4d22b236be9ba5 (patch)
tree28b5e5d7921a399cdcc8fb9559df0e69a31354be /widgets/disk.go
Initial commit
Diffstat (limited to 'widgets/disk.go')
-rw-r--r--widgets/disk.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/widgets/disk.go b/widgets/disk.go
new file mode 100644
index 0000000..7b3c2c8
--- /dev/null
+++ b/widgets/disk.go
@@ -0,0 +1,37 @@
+package widgets
+
+import (
+ "fmt"
+ "time"
+
+ ui "github.com/cjbassi/gotop/termui"
+ "github.com/cjbassi/gotop/utils"
+ ps "github.com/shirou/gopsutil/disk"
+)
+
+type Disk struct {
+ *ui.Gauge
+ fs string // which filesystem to get the disk usage of
+ interval time.Duration
+}
+
+func NewDisk() *Disk {
+ d := &Disk{ui.NewGauge(), "/", time.Second * 5}
+ d.Label = "Disk Usage"
+
+ go d.update()
+ ticker := time.NewTicker(d.interval)
+ go func() {
+ for range ticker.C {
+ d.update()
+ }
+ }()
+
+ return d
+}
+
+func (d *Disk) update() {
+ disk, _ := ps.Usage(d.fs)
+ d.Percent = int(disk.UsedPercent)
+ d.Description = fmt.Sprintf(" (%dGB free)", utils.BytesToGB(int(disk.Free)))
+}