-
Notifications
You must be signed in to change notification settings - Fork 0
/
cursors.go
47 lines (40 loc) · 908 Bytes
/
cursors.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
package dull
// Cursors represents a collection of cursors that a window may render.
//
// An instance is provided by a Window.
type Cursors struct {
nextId CursorId
window *Window
cursors map[CursorId]*Cursor
}
func NewCursors(window *Window) *Cursors {
return &Cursors{
nextId: 0,
window: window,
cursors: make(map[CursorId]*Cursor),
}
}
func (c *Cursors) New() *Cursor {
return &Cursor{
window: c.window,
}
}
// Add adds a cursor.
//
// The returned CursorId may be later used to remove the cursor.
func (c *Cursors) Add(cursor *Cursor) CursorId {
c.nextId++
id := c.nextId
c.cursors[id] = cursor
return id
}
// Removes a cursor.
//
// The cursor is identified by an id returned from the Add function.
func (c *Cursors) Remove(id CursorId) {
delete(c.cursors, id)
}
// RemoveAll removes all cursors.
func (c *Cursors) RemoveAll() {
c.cursors = make(map[CursorId]*Cursor)
}