forked from gen2brain/dlgs
/
message_linux.go
64 lines (52 loc) · 1.34 KB
/
message_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// +build linux,!windows,!darwin,!js
package dlgs
import (
"os/exec"
"syscall"
)
// Info displays information dialog.
func Info(title, text string) (bool, error) {
return cmdDialog(title, text, "info")
}
// Warning displays warning dialog.
func Warning(title, text string) (bool, error) {
return cmdDialog(title, text, "warning")
}
// Error displays error dialog.
func Error(title, text string) (bool, error) {
return cmdDialog(title, text, "error")
}
// Question displays question dialog.
func Question(title, text string, defaultCancel bool) (bool, error) {
cmd, err := cmdPath()
if err != nil {
return false, err
}
dflt := ""
if defaultCancel {
dflt = "--default-cancel"
}
err = exec.Command(cmd, "--question", "--title", title, "--text", text, dflt).Run()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
ws := exitError.Sys().(syscall.WaitStatus)
return ws.ExitStatus() == 0, nil
}
}
return true, err
}
// cmdDialog displays dialog.
func cmdDialog(title, text, level string) (bool, error) {
cmd, err := cmdPath()
if err != nil {
return false, err
}
err = exec.Command(cmd, "--"+level, "--title", title, "--text", text).Run()
if err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
ws := exitError.Sys().(syscall.WaitStatus)
return ws.ExitStatus() == 0, nil
}
}
return true, err
}