-
Notifications
You must be signed in to change notification settings - Fork 0
/
loading.go
53 lines (47 loc) 路 1.13 KB
/
loading.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
package ui
import (
"fmt"
"github.com/jroimartin/gocui"
)
type LoadingPanel struct {
ViewName string
viewPosition ViewPosition
}
func NewLoadingPanel() (*LoadingPanel, error) {
loadingPanel := LoadingPanel{
ViewName: "loading",
viewPosition: ViewPosition{
x0: Position{0.1, 0},
y0: Position{0.35, 0},
x1: Position{0.9, 2},
y1: Position{0.5, 2},
},
}
return &loadingPanel, nil
}
func (loadingPanel *LoadingPanel) ShowLoading(g *gocui.Gui, callback func()) error {
g.Update(func(g *gocui.Gui) error {
loadingPanel.DrawView(g)
g.Update(func(g *gocui.Gui) error {
callback()
g.DeleteView(loadingPanel.ViewName)
return nil
})
return nil
})
return nil
}
func (loadingPanel *LoadingPanel) DrawView(g *gocui.Gui) error {
maxX, maxY := g.Size()
x0, y0, x1, y1 := loadingPanel.viewPosition.GetCoordinates(maxX, maxY)
if v, err := g.SetView(loadingPanel.ViewName, x0, y0, x1, y1); err != nil {
v.SelBgColor = gocui.ColorMagenta
g.SetCurrentView(loadingPanel.ViewName)
_, err := g.SetCurrentView(loadingPanel.ViewName)
if err != nil {
return err
}
fmt.Fprintf(v, "LOADING....")
}
return nil
}