-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdate_text.go
75 lines (61 loc) · 1.39 KB
/
update_text.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
70
71
72
73
74
75
package main
import (
"fmt"
"math/rand"
"time"
"github.com/gizak/termui/v3/widgets"
)
/* Generate random initial coordinates for the text */
func generateRandomCoords() (xCoord, yCoord int) {
rand.Seed(int64(time.Now().Nanosecond()))
min := 1
max := termHeight - pTextHeight - 3
yCoord = rand.Intn(max-min) + min
max = termWidth - pTextLength - 3
xCoord = rand.Intn(max-min) + min
return xCoord, yCoord
}
/* Update the color of text when it hits the corner if all colors is used */
func updateTextColor(p **widgets.Paragraph) {
colorsPos++
(*p).Text = fmt.Sprintf("[%s](fg:%s,mod:bold)", displayText, colors[colorsPos])
/* If the last we're at the last element in the list, begin from start */
if colorsPos == len(colors)-1 {
colorsPos = 0
}
}
/* Draw the text on termui */
func drawText(p **widgets.Paragraph) {
updateColor := false
/* Did text hit the bottom or top of the term? */
if py == yEdge {
yAdd = false
updateColor = true
} else if py == 0 {
yAdd = true
updateColor = true
}
/* Did the text hit the right or left of term? */
if px == xEdge {
xAdd = false
updateColor = true
} else if px == 0 {
xAdd = true
updateColor = true
}
/* Update color on hit and when all a flag is used */
if updateColor && allColors {
updateTextColor(p)
}
if yAdd {
py++
} else {
py--
}
if xAdd {
px++
} else {
px--
}
(*p).SetRect(px, py, termWidth, termHeight)
}