Skip to content

Commit 79a23a4

Browse files
author
dmullis
committed
Panic if TAB character is seen on input. Make more symbols private.
1 parent 9ff4c2b commit 79a23a4

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

‎canvas.go‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Package goat formats "ASCII-art" drawings into Github-flavored Markdown.
33
44
<goat>
5-
porcelain API
5+
porcelain API · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
6+
67
BuildAndWriteSVG()
78
.----------.
89
ASCII-art | | Markdown
@@ -11,9 +12,8 @@ Package goat formats "ASCII-art" drawings into Github-flavored Markdown.
1112
'----------'
1213
1314
14-
· · · · · · · · · · · · · · · · · · · · · · · ·
15+
deep API · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
1516
16-
plumbing API
1717
Canvas{}
1818
NewCanvas() .-------------------. WriteSVGBody()
1919
| | .-------.
@@ -156,8 +156,8 @@ func (c *Canvas) runeAt(i Index) rune {
156156
return ' '
157157
}
158158

159-
// NewCanvas creates a new canvas with contents read from the given io.Reader.
160-
// Content should be newline delimited.
159+
// NewCanvas creates a fully-populated Canvas according to GoAT-formatted text read from
160+
// an io.Reader, consuming all bytes available.
161161
func NewCanvas(in io.Reader) (c Canvas) {
162162
// XX Move this function to top of file.
163163
width := 0
@@ -185,6 +185,9 @@ func NewCanvas(in io.Reader) (c Canvas) {
185185
// fmt.Printf("linestr=\"%s\"\n", lineStr)
186186
// fmt.Printf("r == 0x%x\n", r)
187187
//}
188+
if r == ' ' {
189+
panic("TAB character found on input")
190+
}
188191
i := Index{w, height}
189192
c.data[i] = r
190193
w++
@@ -221,7 +224,7 @@ func (c *Canvas) MoveToText() {
221224

222225
// Drawable represents anything that can Draw itself.
223226
type Drawable interface {
224-
Draw(out io.Writer)
227+
draw(out io.Writer)
225228
}
226229

227230
// Line represents a straight segment between two points 'start' and 'stop', where
@@ -349,27 +352,28 @@ const (
349352
W // West
350353
)
351354

355+
// WriteSVGBody writes the entire content of a Canvas out to a stream in SVG format.
352356
func (c *Canvas) WriteSVGBody(dst io.Writer) {
353357
writeBytes(dst, "<g transform='translate(8,16)'>\n")
354358

355359
for _, l := range c.Lines() {
356-
l.Draw(dst)
360+
l.draw(dst)
357361
}
358362

359363
for _, tI := range c.Triangles() {
360-
tI.Draw(dst)
364+
tI.draw(dst)
361365
}
362366

363367
for _, c := range c.RoundedCorners() {
364-
c.Draw(dst)
368+
c.draw(dst)
365369
}
366370

367371
for _, c := range c.Circles() {
368-
c.Draw(dst)
372+
c.draw(dst)
369373
}
370374

371375
for _, bI := range c.Bridges() {
372-
bI.Draw(dst)
376+
bI.draw(dst)
373377
}
374378

375379
writeText(dst, c)

‎index.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ type Index struct {
66
X, Y int
77
}
88

9-
// Pixel represents the CSS-pixel coordinates for an Index.
10-
type Pixel Index // XX different units -- create separate base type?
9+
// pixel represents the CSS-pixel coordinates for an Index.
10+
type pixel Index // XX different units -- create separate base type?
1111

12-
func (i *Index) asPixel() Pixel {
12+
func (i *Index) asPixel() pixel {
1313
// TODO define constants rather than hard-wire width and height of cell
14-
return Pixel{
14+
return pixel{
1515
X: i.X * 8,
1616
Y: i.Y * 16}
1717
}

‎svg.go‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ type SVG struct {
1313
Height int
1414
}
1515

16-
// See:
17-
// https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme
16+
// See: https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme
1817
func (s SVG) String(svgColorLightScheme, svgColorDarkScheme string) string {
1918
style := fmt.Sprintf(
2019
`<style type="text/css">
@@ -81,12 +80,12 @@ func writeText(out io.Writer, canvas *Canvas) {
8180
`)
8281
for _, textObj := range canvas.Text() {
8382
// usual, baseline case
84-
textObj.Draw(out)
83+
textObj.draw(out)
8584
}
8685
}
8786

8887
// Draw a straight line as an SVG path.
89-
func (l Line) Draw(out io.Writer) {
88+
func (l Line) draw(out io.Writer) {
9089
start := l.start.asPixel()
9190
stop := l.stop.asPixel()
9291

@@ -214,7 +213,7 @@ func (l Line) Draw(out io.Writer) {
214213
}
215214

216215
// Draw a solid triangle as an SVG polygon element.
217-
func (t Triangle) Draw(out io.Writer) {
216+
func (t Triangle) draw(out io.Writer) {
218217
// https://www.w3.org/TR/SVG/shapes.html#PolygonElement
219218

220219
/*
@@ -320,7 +319,7 @@ func (t Triangle) Draw(out io.Writer) {
320319
}
321320

322321
// Draw a solid circle as an SVG circle element.
323-
func (c *Circle) Draw(out io.Writer) {
322+
func (c *Circle) draw(out io.Writer) {
324323
var fill string
325324
if c.bold {
326325
fill = "currentColor"
@@ -339,7 +338,7 @@ func (c *Circle) Draw(out io.Writer) {
339338
}
340339

341340
// Draw a single text character as an SVG text element.
342-
func (t Text) Draw(out io.Writer) {
341+
func (t Text) draw(out io.Writer) {
343342
p := t.start.asPixel()
344343
c := t.str
345344

@@ -390,7 +389,7 @@ func (t Text) Draw(out io.Writer) {
390389
}
391390

392391
// Draw a rounded corner as an SVG elliptical arc element.
393-
func (c *RoundedCorner) Draw(out io.Writer) {
392+
func (c *RoundedCorner) draw(out io.Writer) {
394393
// https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
395394

396395
x, y := c.start.asPixelXY()
@@ -432,7 +431,7 @@ func (c *RoundedCorner) Draw(out io.Writer) {
432431
}
433432

434433
// Draw a bridge as an SVG elliptical arc element.
435-
func (b Bridge) Draw(out io.Writer) {
434+
func (b Bridge) draw(out io.Writer) {
436435
x, y := b.start.asPixelXY()
437436
sweepFlag := 1
438437

0 commit comments

Comments
 (0)