-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
57 lines (48 loc) · 1.37 KB
/
example_test.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
package bbs_test
import (
"bytes"
"embed"
"fmt"
"log"
"github.com/bengarrett/bbs"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/transform"
)
//go:embed static/*
var static embed.FS
func Example() {
// print about the file
file, err := static.Open("static/examples/hello.pcb")
if err != nil {
log.Fatal(err)
}
defer file.Close()
s, name, err := bbs.Fields(file)
if err != nil {
log.Print(err)
return
}
fmt.Printf("Found %d %s color controls.\n\n", len(s), name)
// reopen the file
file, err = static.Open("static/examples/hello.pcb")
if err != nil {
log.Print(err)
return
}
defer file.Close()
// transform the MS-DOS legacy text to Unicode
decoder := charmap.CodePage437.NewDecoder()
reader := transform.NewReader(file, decoder)
// create the HTML equivalent of BBS color codes
var buf bytes.Buffer
if _, err := bbs.HTML(&buf, reader); err != nil {
log.Print(err)
return
}
fmt.Print(buf.String())
// Output: Found 11 PCBoard @X color controls.
//
// <i class="PB0 PFF"> </i><i class="PB7 PF0"> ┌─────────────┐ </i><i class="PB0 PF7">
// </i><i class="PB0 PFF"> </i><i class="PB7 PF0"> │ Hello </i><i class="PBF PF0">world </i><i class="PB7 PF0">│ </i><i class="PB0 PF7">
// </i><i class="PB0 PFF"> </i><i class="PB7 PF0"> └─────────────┘ </i><i class="PB0 PF7"></i>
}