-
Notifications
You must be signed in to change notification settings - Fork 43
/
goat.go
48 lines (43 loc) · 1.53 KB
/
goat.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
/*
Package goat formats "ASCII-art" drawings into Github-flavored Markdown.
<goat>
porcelain API
BuildAndWriteSVG()
.----------.
ASCII-art | | Markdown
----------------------->| +------------------------->
| |
'----------'
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
plumbing API
Canvas{}
NewCanvas() .-------------------. WriteSVGBody()
| | .-------.
ASCII-art .--. | data map[x,y]rune | | SVG{} | Markdown
---------->| +--->| text map[x,y]rune +-->| +------->
'--' | | | |
'-------------------' '-------'
</goat>
*/
package goat
import (
"bytes"
"io"
)
// BuildAndWriteSVG reads in a newline-delimited ASCII diagram from src and writes a
// corresponding SVG diagram to dst.
func BuildAndWriteSVG(src io.Reader, dst io.Writer,
svgColorLightScheme, svgColorDarkScheme string) {
svg := buildSVG(src)
writeBytes(dst, svg.String(svgColorLightScheme, svgColorDarkScheme))
}
func buildSVG(src io.Reader) SVG {
var buff bytes.Buffer
canvas := NewCanvas(src)
canvas.WriteSVGBody(&buff)
return SVG{
Body: buff.String(),
Width: canvas.widthScreen(),
Height: canvas.heightScreen(),
}
}