-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
71 lines (53 loc) · 1.48 KB
/
main.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
package main
import (
"bufio"
"fmt"
"io"
"os"
"github.com/danielgatis/go-vte"
)
var _ (vte.Performer) = (*performer)(nil)
type performer struct{}
func (p *performer) Print(r rune) {
fmt.Printf("[Print] %c\n", r)
}
func (p *performer) Execute(b byte) {
fmt.Printf("[Execute] %02x\n", b)
}
func (p *performer) Put(b byte) {
fmt.Printf("[Put] %02x\n", b)
}
func (p *performer) Unhook() {
fmt.Printf("[Unhook]\n")
}
func (p *performer) Hook(params [][]uint16, intermediates []byte, ignore bool, r rune) {
fmt.Printf("[Hook] params=%v, intermediates=%v, ignore=%v, r=%c\n", params, intermediates, ignore, r)
}
func (p *performer) OscDispatch(params [][]byte, bellTerminated bool) {
fmt.Printf("[OscDispatch] params=%v, bellTerminated=%v\n", params, bellTerminated)
}
func (p *performer) CsiDispatch(params [][]uint16, intermediates []byte, ignore bool, r rune) {
fmt.Printf("[CsiDispatch] params=%v, intermediates=%v, ignore=%v, r=%c\n", params, intermediates, ignore, r)
}
func (p *performer) EscDispatch(intermediates []byte, ignore bool, b byte) {
fmt.Printf("[EscDispatch] intermediates=%v, ignore=%v, byte=%02x\n", intermediates, ignore, b)
}
func main() {
reader := bufio.NewReader(os.Stdin)
performer := &performer{}
parser := vte.NewParser(performer)
buff := make([]byte, 2048)
for {
n, err := reader.Read(buff)
if err != nil {
if err == io.EOF {
return
}
fmt.Printf("Err %v:", err)
return
}
for _, b := range buff[:n] {
parser.Advance(b)
}
}
}