43 lines
783 B
Go
43 lines
783 B
Go
//go:build windows
|
|
|
|
package prompt
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func FatalDialog(message string) {
|
|
text, _ := windows.UTF16PtrFromString(message)
|
|
title, _ := windows.UTF16PtrFromString("tsrun")
|
|
_, _ = windows.MessageBox(0, text, title, windows.MB_ICONERROR|windows.MB_OK)
|
|
}
|
|
|
|
func WaitForEnter(message string) {
|
|
fi, err := os.Stdin.Stat()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if fi.Mode()&os.ModeCharDevice == 0 {
|
|
return
|
|
}
|
|
fmt.Println(message)
|
|
done := make(chan struct{}, 1)
|
|
go func() {
|
|
_, _ = bufio.NewReader(os.Stdin).ReadString('\n')
|
|
done <- struct{}{}
|
|
}()
|
|
sigCh := make(chan os.Signal, 1)
|
|
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
|
|
defer signal.Stop(sigCh)
|
|
select {
|
|
case <-done:
|
|
case <-sigCh:
|
|
}
|
|
}
|