Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgatis authored Sep 16, 2023
1 parent 2e8421e commit 51463a1
Showing 1 changed file with 3 additions and 87 deletions.
90 changes: 3 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,98 +19,15 @@ go get -u github.com/danielgatis/go-vte
And then import the package in your code:

```go
import "github.com/danielgatis/go-vte/vtparser"
import "github.com/danielgatis/go-vte"
```

### Example

An example described below is one of the use cases.

```go
package main

import (
"bufio"
"fmt"
"io"
"os"

"github.com/danielgatis/go-vte/vtparser"
)

type dispatcher struct{}

func (p *dispatcher) Print(r rune) {
fmt.Printf("[Print] %c\n", r)
}

func (p *dispatcher) Execute(b byte) {
fmt.Printf("[Execute] %02x\n", b)
}

func (p *dispatcher) Put(b byte) {
fmt.Printf("[Put] %02x\n", b)
}

func (p *dispatcher) Unhook() {
fmt.Printf("[Unhook]\n")
}

func (p *dispatcher) Hook(params []int64, intermediates []byte, ignore bool, r rune) {
fmt.Printf("[Hook] params=%v, intermediates=%v, ignore=%v, r=%v\n", params, intermediates, ignore, r)
}

func (p *dispatcher) OscDispatch(params [][]byte, bellTerminated bool) {
fmt.Printf("[OscDispatch] params=%v, bellTerminated=%v\n", params, bellTerminated)
}

func (p *dispatcher) CsiDispatch(params []int64, intermediates []byte, ignore bool, r rune) {
fmt.Printf("[CsiDispatch] params=%v, intermediates=%v, ignore=%v, r=%v\n", params, intermediates, ignore, r)
}

func (p *dispatcher) 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)
dispatcher := &dispatcher{}
parser := vtparser.New(
dispatcher.Print,
dispatcher.Execute,
dispatcher.Put,
dispatcher.Unhook,
dispatcher.Hook,
dispatcher.OscDispatch,
dispatcher.CsiDispatch,
dispatcher.EscDispatch,
)

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)
}
}
}
Please look at: [examples/parserlog/main.go](examples/parserlog/main.go)

```


```
❯ echo -ne "Hello\nWorld" | go run main.go
❯ echo -ne "Hello\nWorld" | go run ./examples/parserlog/main.go
[Print] H
[Print] e
[Print] l
Expand All @@ -124,7 +41,6 @@ func main() {
[Print] d
```


## License

Copyright (c) 2020-present [Daniel Gatis](https://github.com/danielgatis)
Expand Down

0 comments on commit 51463a1

Please sign in to comment.