-
Notifications
You must be signed in to change notification settings - Fork 5
/
dialog.go
69 lines (59 loc) · 1.8 KB
/
dialog.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
65
66
67
68
69
package main
import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
func popup(width int, height int, primitive tview.Primitive) *tview.Flex {
flex := tview.NewFlex().
AddItem(nil, 0, 1, false).
AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(nil, 0, 1, false).
AddItem(primitive, height, 1, true).
AddItem(nil, 0, 1, false), width, 1, true).
AddItem(nil, 0, 1, false)
return flex
}
func showFailWindow(msg string) {
fail := tview.NewModal().
SetText(msg).
AddButtons([]string{S_MODAL_BUTTON_OK}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
layoutRoot.RemovePage("fail")
})
fail.SetTitle(S_MODAL_TITLE_ERROR)
fail.Box.SetBackgroundColor(tcell.ColorDarkRed)
fail.SetBackgroundColor(tcell.ColorDarkRed)
layoutRoot.AddPage("fail", fail, true, true)
}
func showSuccessWindow(msg string, callback func()) {
succ := tview.NewModal().
SetText(msg).
AddButtons([]string{S_MODAL_BUTTON_OK}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
// update info window & mainFrame window
layoutRoot.RemovePage("success")
if callback != nil {
callback()
}
})
succ.SetTitle(S_MODAL_TITLE_SUCCESS)
succ.Box.SetBackgroundColor(tcell.ColorDarkGreen)
succ.SetBackgroundColor(tcell.ColorDarkGreen)
layoutRoot.AddPage("success", succ, true, true)
}
func showInfoWindow(msg string, callback func()) {
info := tview.NewModal().
SetText(msg).
AddButtons([]string{S_MODAL_BUTTON_OK}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
// update info window & mainFrame window
layoutRoot.RemovePage("info")
if callback != nil {
callback()
}
})
info.SetTitle(S_MODAL_TITLE_INFO)
info.Box.SetBackgroundColor(tcell.ColorDarkBlue)
info.SetBackgroundColor(tcell.ColorDarkBlue)
layoutRoot.AddPage("info", info, true, true)
}