-
Notifications
You must be signed in to change notification settings - Fork 0
/
hr.go
43 lines (36 loc) · 578 Bytes
/
hr.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
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
cols, _, err := TerminalDimensions()
if err != nil {
fmt.Println(err)
return
}
w := bufio.NewWriter(os.Stdout)
if len(os.Args) == 1 {
os.Args = append(os.Args, "#")
}
for _, str := range os.Args[1:] {
var runes int
r := NewInfiniteRuneReader(str)
if r == nil {
continue
}
for runes < cols {
ch, _, err := r.ReadRune()
if err != nil {
panic(err)
}
if _, err := w.WriteRune(ch); err != nil {
panic(err)
}
runes++
}
w.Write([]byte(newline))
w.Flush()
}
}