summaryrefslogtreecommitdiff
path: root/doGui.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-08-17 17:02:29 -0500
committerJeff Carr <[email protected]>2025-08-17 22:57:06 -0500
commit25c604aeee7cd821d27dfd4c09bf0626e9312535 (patch)
treee7b875d4077ffb7fa265c7a1bd8fefafbc9d0235 /doGui.go
parentbd5b16d8755bc9e5f0dc90162bc4724d319c725e (diff)
protobuf file for block devices
Diffstat (limited to 'doGui.go')
-rw-r--r--doGui.go58
1 files changed, 50 insertions, 8 deletions
diff --git a/doGui.go b/doGui.go
index bc8890b..9a902ee 100644
--- a/doGui.go
+++ b/doGui.go
@@ -6,6 +6,7 @@ package main
// An app to submit patches for the 30 GO GUI repos
import (
+ "fmt"
"os"
"strings"
"time"
@@ -13,16 +14,45 @@ import (
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/shell"
+ "go.wit.com/lib/protobuf/virtpb"
"go.wit.com/log"
)
func debug() {
for {
- time.Sleep(3 * time.Second)
- log.Info("TODO: use this?")
+ time.Sleep(10 * time.Second)
+ log.Info("TODO: use this debug loop for something?")
}
}
+// adds a new drive to the dropdown menu and protobuf
+func addDrive(devname string, displayDesc string) *Block {
+ if blkpb := me.pb.FindByName(devname); blkpb != nil {
+ return blkpb
+ }
+
+ s := log.Sprintf("%-12s %-8s", devname, displayDesc)
+ log.Info(s)
+ me.dd.AddText(s)
+
+ blkpb := me.pb.InsertByName(devname)
+ return blkpb
+}
+
+func switchDrive(blk *Block) {
+ me.currentDev = blk
+ me.parted.SetText("Partition " + blk.Name)
+
+ log.Info("check if", me.currentDev.Name, "is in use")
+ result, err := shell.RunVerbose([]string{"parted", me.currentDev.Name, "print"})
+ log.Info("result =", result.Stdout, "err =", err)
+ out := strings.Join(result.Stdout, "\n")
+ if err != nil {
+ out += fmt.Sprintf("err = %v", err)
+ }
+ me.driveInfoBox.SetText(out)
+}
+
func doGui() {
me.myGui = gui.New()
me.myGui.InitEmbed(resources)
@@ -51,19 +81,21 @@ func drawWindow(win *gadgets.GenericWindow) {
if len(fields) < 1 {
return
}
- me.currentDev = fields[0]
- me.parted.SetText("Partition " + me.currentDev)
+ if blkpb := me.pb.FindByName(fields[0]); blkpb != nil {
+ switchDrive(blkpb)
+ } else {
+ log.Info("couldn't find in protobuf:", fields)
+ }
}
grid.NextRow()
// a button to format or blank a drive
me.parted = grid.NewButton("select drive", func() {
- if me.currentDev == "" {
+ if me.currentDev == nil {
log.Info("You must select a drive first")
return
}
- log.Info("check if", me.currentDev, "is in use")
- shell.RunVerbose([]string{"parted", me.currentDev, "print"})
+ log.Info("TODO: figure out if the drive is in use")
})
grid.NextRow()
@@ -72,6 +104,16 @@ func drawWindow(win *gadgets.GenericWindow) {
doDrives()
})
- doDrives2()
+ grid.NewButton("show blkpb", func() {
+ for blk := range me.pb.IterAll() {
+ log.Printf("found %-12s %s\n", blk.Name, virtpb.HumanFormatBytes(int64(blk.SizeBytes)))
+ }
+ })
+ grid.NextRow()
+ grid = win.Middle.RawGrid()
+ me.driveInfoBox = grid.NewLabel("<drive info>")
+
+ doDrives2()
+ doDrives()
}