From ccba007256bf14a2bea871c181855e4c4741a382 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 24 May 2019 15:35:41 -0700 Subject: [PATCH] ping almost works Signed-off-by: Jeff Carr --- debug.go | 74 +++++++++++++++++++---------------------------------- structs.go | 1 + vmWindow.go | 1 + 3 files changed, 28 insertions(+), 48 deletions(-) diff --git a/debug.go b/debug.go index 31fc0f1..acc2907 100644 --- a/debug.go +++ b/debug.go @@ -12,9 +12,9 @@ import "github.com/gookit/config" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" -// import pb "git.wit.com/wit/witProtobuf" +import "github.com/davecgh/go-spew/spew" -// import "github.com/davecgh/go-spew/spew" +// import pb "git.wit.com/wit/witProtobuf" // can not pass any args to this (?) func setupCloudUI() { @@ -72,69 +72,47 @@ func addDebuggingButtons(vbox *ui.Box, custom func(*ButtonMap)) { vbox.Append(add2button, false) // ATTEMPT TO ADD THE TABLE HERE END - // hbox.Append(ui.NewVerticalSeparator(), false) - - // Send a test protobuf Event to localhost - add3button := CreateButton("Add buf to chan", "ADD CHAN BUF", custom) -/* - add3button := ui.NewButton("Add buf to chann") - add3button.OnClicked(func(*ui.Button) { - log.Println("add protobuf event to the channel") - addSampleEvent() - }) -*/ - vbox.Append(add3button, false) - - add4button := CreateButton("Add Demo Event", "ADD DEMO EVENT", custom) -/* - add4button := ui.NewButton("Add Demo Event") - add4button.OnClicked(func(*ui.Button) { - log.Println("add demo protobuf event to the channel") - msg := pb.CreateSampleEvent() - msg.Name = "generated in addSampleEvent()" - msg.Type = pb.Event_DEMO - addEvent(msg) - }) -*/ - vbox.Append(add4button, false) - vbox.Append(CreateButton("Close GUI", "QUIT", custom), false) - - // Send a protobuf Event over the WIT socket - add5button := CreateButton("Send protobuf to localhost", "SEND PROTOBUF TO LOCALHOST", custom) -/* - add5button := ui.NewButton("Send protobuf to localhost") - add5button.OnClicked(func(*ui.Button) { - log.Println("sent a Marshal'd protobuf to a localhost socket") - sendDataToDest() - }) -*/ - vbox.Append(add5button, false) - vbox.Append(CreateButton("DEBUG goroutines", "DEBUG", custom), false) + // vbox.Append(CreateButton("ping", "PING", runPingClick), false) vbox.Append(CreateButton("xterm", "XTERM", runTestExecClick), false) vbox.Append(CreateButton("Load test.json config file", "CONFIG", custom), false) } +func runPingClick(b *ButtonMap) { + log.Println("runPingClick START") + spew.Dump(b) + var tmp []string + tmp = append(tmp, "xterm", "-e", "ping localhost") + runCommand(tmp) + log.Println("runPingClick END") +} + func runTestExecClick(b *ButtonMap) { log.Println("runTestExecClick START") if runtime.GOOS == "linux" { - go runCommand("xterm -report-fonts") - } else if runtime.GOOS == "windows" { - go runCommand("cmd.exe") + go runSimpleCommand("xterm -report-fonts") + } else if runtime.GOOS == "windows" { + go runSimpleCommand("cmd.exe") } else { - go runCommand("xterm") + go runSimpleCommand("xterm") } log.Println("runTestExecClick END") } -func runCommand(s string) { - log.Println("runXterm START") - log.Println("runXterm START") - log.Println("runXterm START") +func runSimpleCommand(s string) { cmd := strings.TrimSpace(s) // this is like 'chomp' in perl cmdArgs := strings.Fields(cmd) + runCommand(cmdArgs) +} + +func runCommand(cmdArgs []string) { + log.Println("runXterm START") + log.Println("runXterm START") + log.Println("runXterm START") + log.Println("runXterm START", cmdArgs) process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) + // process := exec.Command("xterm", "-e", "ping localhost") log.Println("runXterm process.Start()") process.Start() log.Println("runXterm process.Wait()") diff --git a/structs.go b/structs.go index e868fde..3f25033 100644 --- a/structs.go +++ b/structs.go @@ -102,6 +102,7 @@ type ButtonMap struct { onClick func (int, string) onChanged func (int, string) custom func (*ButtonMap) + pbVM *pb.Event_VM Name string // the text on the button Note string // what type of button AccNick string // what account this button is for diff --git a/vmWindow.go b/vmWindow.go index ca25a9d..280ccf6 100644 --- a/vmWindow.go +++ b/vmWindow.go @@ -111,6 +111,7 @@ func createVmBox(tab *ui.Tab, custom func(*ButtonMap), pbVM *pb.Event_VM) { hboxButtons.Append(CreateButton("Power On", "POWERON", custom), false) hboxButtons.Append(CreateButton("Power Off", "POWEROFF", custom), false) hboxButtons.Append(CreateButton("Destroy", "DESTROY", custom), false) + hboxButtons.Append(CreateButton("ping", "PING", runPingClick), false) hboxButtons.Append(CreateButton("Console", "XTERM", runTestExecClick), false) hboxButtons.Append(CreateButton("Save", "SAVE", custom), false) hboxButtons.Append(CreateButton("Done", "DONE", custom), false)