Skip to content

Commit

Permalink
Allow admin to exit when nothing connected
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4ntonn committed Mar 27, 2024
1 parent 0463556 commit 2ed667d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions admin/admin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package main
Expand Down Expand Up @@ -27,6 +28,7 @@ func main() {
printer.InitPrinter()

termbox.Init()
go listenCtrlC()

options := initial.ParseOptions()

Expand Down Expand Up @@ -55,6 +57,9 @@ func main() {
os.Exit(0)
}

// kill listenCtrlC
termbox.Interrupt()

admin := process.NewAdmin()

admin.Topology = topo
Expand All @@ -69,3 +74,18 @@ func main() {

admin.Run()
}

// let process exit if nothing connected
func listenCtrlC() {
for {
event := termbox.PollEvent()
if event.Type == termbox.EventInterrupt {
break
}

if event.Key == termbox.KeyCtrlC {
termbox.Close()
os.Exit(0)
}
}
}

0 comments on commit 2ed667d

Please sign in to comment.