-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhtml.go
More file actions
30 lines (25 loc) · 701 Bytes
/
html.go
File metadata and controls
30 lines (25 loc) · 701 Bytes
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
package midterm
import (
"bytes"
"html"
)
// HTML renders v as an HTML fragment. One idea for how to use this is to debug
// the current state of the screen reader.
func (v *Terminal) HTML() string {
v.mut.Lock()
defer v.mut.Unlock()
var buf bytes.Buffer
buf.WriteString(`<pre style="color:white;background-color:black;">`)
for y := 0; y < v.Format.Height(); y++ {
var x int
for region := range v.Format.Regions(y) {
buf.WriteString(`<span style="` + region.F.css() + `">`)
buf.WriteString(html.EscapeString(string(v.Content[y][x : x+region.Size])))
buf.WriteString("</span>")
x += region.Size
}
buf.WriteRune('\n')
}
buf.WriteString("</pre>")
return buf.String()
}