-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathalert.go
59 lines (52 loc) · 934 Bytes
/
alert.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
package duit
import (
"fmt"
"image"
)
// Alert creates a new window that show text and a button labeled OK that closes the window.
func Alert(text string) (err error) {
stop := make(chan struct{}, 1)
dui, err := NewDUI("alert", &DUIOpts{Dimensions: "300x200"})
if err != nil {
return fmt.Errorf("new alert window: %s", err)
}
dui.Top.UI = NewMiddle(SpaceXY(20, 10),
&Box{
Margin: image.Pt(0, 10),
Kids: NewKids(
&Box{
Width: -1,
Kids: NewKids(
&Label{Text: text},
),
},
CenterUI(Space{},
&Button{
Colorset: &dui.Primary,
Text: "OK",
Click: func() (e Event) {
stop <- struct{}{}
return
},
},
),
),
},
)
dui.Render()
for {
select {
case e := <-dui.Inputs:
dui.Input(e)
case xerr, ok := <-dui.Error:
if !ok {
return
}
dui.Close()
return xerr
case <-stop:
dui.Close()
return
}
}
}