-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
32 lines (28 loc) · 1022 Bytes
/
utils.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
package main
import (
"fmt"
"strings"
)
// moveCursor - produces escape seq: \033[1;1H
// ^ ^
// ^ col
// ^
// row
// in the above example it's job is to move cursor to row=1, col=1
// see: https://en.wikipedia.org/wiki/ANSI_escape_code#Sequence_elements
// https://stackoverflow.com/questions/15442292/golang-how-to-have-an-inplace-string-that-updates-at-stdout
func moveCursor(row int, column int) string {
return fmt.Sprintf("\033[%d;%dH", row, column)
}
func header(column int, step int) string {
stepIn8 := step % 8
if stepIn8 == 0 {
stepIn8 = 8
}
return fmt.Sprintf("%s %d ", moveCursor(1, column), stepIn8)
}
func footer(maxColumns int, column int, lastRow int) string {
leftPad := strings.Repeat(" ", column-1)
rightPad := strings.Repeat(" ", maxColumns-column)
return fmt.Sprintf("%s%s", moveCursor(lastRow, 1), leftPad+"*"+rightPad)
}