-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
42 lines (36 loc) · 671 Bytes
/
utils.go
File metadata and controls
42 lines (36 loc) · 671 Bytes
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
package main
import "fmt"
func getLineNumWidth(num int) int {
if num%10 == 0 {
return 1
}
return 1 + getLineNumWidth(num/10)
}
func getWordLength(content string, startIdx int) int {
wordLength := 0
for _, c := range content[startIdx:] {
if c == 32 || c == 10 {
return wordLength
}
wordLength += 1
}
return wordLength
}
func moveCursor(x int, y int) {
// ESC [ LINE ; COL H
fmt.Printf("\033[%d;%dH", y+1, x)
}
func flushRegion(xa, xb, ya, yb int) {
// Flushes a region within given coordinates
yptr := ya
xptr := xa
for yptr <= yb {
for xptr <= xb {
moveCursor(xptr, yptr)
fmt.Print(" ")
xptr += 1
}
yptr += 1
xptr = xa
}
}