-
Notifications
You must be signed in to change notification settings - Fork 0
/
cursor.go
58 lines (43 loc) · 1.19 KB
/
cursor.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
package main
import "fmt"
type Cursor struct {
x int
y int
screen *Screen
}
func (c *Cursor) String() string {
return fmt.Sprintf("Cursor: (%v, %v)", c.x, c.y)
}
func NewCursor(x, y int, screen *Screen) *Cursor {
cursor := &Cursor{x, y, screen}
screen.tScreen.ShowCursor(cursor.x, cursor.y)
return cursor
}
// use this method to set the position of the cursor
// dont directly change the x and y values
func (c *Cursor) SetPos(x, y int, tb *TabBuffer) {
sWidth, _ := c.screen.tScreen.Size()
upperBound := tb.GetUpperBound()
lowerBound := tb.GetLowerBound()
if x < 0 {
x = 0
} else if x > sWidth {
x = sWidth
}
if y < upperBound {
y = upperBound
} else if y >= lowerBound {
y = lowerBound - 1
}
c.x = x
c.y = y
c.screen.tScreen.ShowCursor(c.x, c.y)
// primary, _, _, width := c.screen.tScreen.GetContent(c.x, c.y)
// c.screen.WriteDebug(fmt.Sprintf("Item: %v, Width: %v", primary, width))
c.screen.WriteDebug(fmt.Sprintf("Col: %d, Row: %d", c.x, c.y), 0)
// c.screen.WriteDebug(fmt.Sprintf("buffer: %v ", c.screen.tabBuffer.lines[c.y].buffer), 1)
}
func (c *Cursor) GetCursorPos() (int, int) {
upperBound := c.screen.tabBuffer.GetUpperBound()
return c.x, c.y - upperBound
}