-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiece.go
54 lines (46 loc) · 945 Bytes
/
piece.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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/tehmaze-labs/go-piece/parser"
"github.com/tehmaze-labs/go-sauce"
)
func main() {
flag.Parse()
format := flag.String("format", "html", "Output format")
for _, filename := range flag.Args() {
f, err := os.Open(filename)
if err != nil {
panic(err)
}
defer f.Close()
w, h := 80, 25
s, err := sauce.Parse(filename)
if err != nil {
log.Printf("%s: failed to parse SAUCE: %v\n", filename, err)
}
if s == nil {
log.Printf("%s: no SAUCE record\n", filename)
} else {
if s.DataType == sauce.DATA_TYPE_CHARACTER {
switch s.FileType {
case 0, 1:
w = int(s.TInfo[0])
}
}
}
log.Printf("creating %d x %d buffer\n", w, h)
p := parser.NewANSI(w, h)
p.Parse(f)
switch *format {
case "html":
fmt.Println(p.Html())
case "text":
fmt.Println(p.String())
default:
log.Fatalf("Unknown format %q\n", *format)
}
}
}