-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctest.go
81 lines (66 loc) · 1.57 KB
/
ctest.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
76
77
78
79
80
81
package main
import ("fmt"
/*"bufio"
"os"
"io"
"bytes"*/
"flag"
"math/rand"
"unsafe"
"syscall"
"strconv"
)
/****/
type winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
func getWidth() uint {
ws := &winsize{}
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
uintptr(syscall.Stdin),
uintptr(syscall.TIOCGWINSZ),
uintptr(unsafe.Pointer(ws)))
if int(retCode) == -1 {
panic(errno)
}
return uint(ws.Col)
}
func getHeight() uint {
ws := &winsize{}
retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
uintptr(syscall.Stdin),
uintptr(syscall.TIOCGWINSZ),
uintptr(unsafe.Pointer(ws)))
if int(retCode) == -1 {
panic(errno)
}
return uint(ws.Row)
}
func letter(n int64) string {
return strconv.FormatInt(n, 36)
}
func run(n int, c chan string) {
//fmt.Println("\033[5;%dHHello\n", n)
if n%2==0 {
r := rand.Intn(64)
rs := letter(int64(r))
c <- fmt.Sprintf("\033[5;%dH%s\n", n, rs)
}
}
/****/
func main() {
bothMode := flag.Bool("both", true, "display both width and height")
heightMode := flag.Bool("height", false, "height mode")
widthMode := flag.Bool("width", false, "width mode")
flag.Parse()
if *bothMode {
fmt.Printf("%dx%d\n", getWidth(), getHeight())
} else if *heightMode {//only first and last
fmt.Printf("%d\n", getHeight())
} else if *widthMode {
fmt.Printf("%d\n", getWidth())
}
}