-
Notifications
You must be signed in to change notification settings - Fork 0
/
memphis.go
59 lines (51 loc) · 1.25 KB
/
memphis.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 memphis
import (
"fmt"
"sync"
"github.com/go-curses/cdk/lib/paint"
"github.com/go-curses/cdk/lib/ptypes"
"github.com/gofrs/uuid"
)
var (
surfaces = make(map[uuid.UUID]*CSurface)
surfacesLock = &sync.RWMutex{}
)
func RegisterSurface(id uuid.UUID, origin ptypes.Point2I, size ptypes.Rectangle, style paint.Style) (err error) {
surfacesLock.Lock()
defer surfacesLock.Unlock()
if _, ok := surfaces[id]; ok {
return fmt.Errorf("surface exists for id: %v", id)
}
surfaces[id] = NewSurface(origin, size, style)
return nil
}
func GetSurface(id uuid.UUID) (*CSurface, error) {
surfacesLock.RLock()
defer surfacesLock.RUnlock()
if c, ok := surfaces[id]; ok {
return c, nil
}
return nil, fmt.Errorf("surface not found: %v", id)
}
func DelSurface(id uuid.UUID) {
surfacesLock.Lock()
defer surfacesLock.Unlock()
if _, ok := surfaces[id]; ok {
delete(surfaces, id)
}
}
func FillSurface(id uuid.UUID, theme paint.Theme) (err error) {
var s Surface
if s, err = GetSurface(id); err == nil {
s.Fill(theme)
}
return
}
func ConfigureSurface(id uuid.UUID, origin ptypes.Point2I, size ptypes.Rectangle, style paint.Style) (err error) {
var s Surface
if s, err = GetSurface(id); err == nil {
s.SetOrigin(origin)
s.Resize(size, style)
}
return
}