File tree Expand file tree Collapse file tree 2 files changed +29
-29
lines changed Expand file tree Collapse file tree 2 files changed +29
-29
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package goat
22
33import (
44 "bufio"
5- "bytes"
65 "io"
76)
87
@@ -101,34 +100,6 @@ type Canvas struct {
101100 text map [Index ]rune
102101}
103102
104- func (c * Canvas ) String () string {
105- var buffer bytes.Buffer
106-
107- for h := 0 ; h < c .Height ; h ++ {
108- for w := 0 ; w < c .Width ; w ++ {
109- idx := Index {w , h }
110-
111- // Search 'text' map; if nothing there try the 'data' map.
112- r , ok := c .text [idx ]
113- if ! ok {
114- r = c .runeAt (idx )
115- }
116-
117- _ , err := buffer .WriteRune (r )
118- if err != nil {
119- continue
120- }
121- }
122-
123- err := buffer .WriteByte ('\n' )
124- if err != nil {
125- continue
126- }
127- }
128-
129- return buffer .String ()
130- }
131-
132103func (c * Canvas ) heightScreen () int {
133104 return c .Height * 16 + 8 + 1
134105}
@@ -158,6 +129,7 @@ func (c *Canvas) runeAt(i Index) rune {
158129
159130// NewCanvas creates a new canvas with contents read from the given io.Reader.
160131// Content should be newline delimited.
132+ // XX Move this to top of file.
161133func NewCanvas (in io.Reader ) (c Canvas ) {
162134 width := 0
163135 height := 0
Original file line number Diff line number Diff line change @@ -31,3 +31,31 @@ func TestReadASCII(t *testing.T) {
3131
3232 c .Assert (expected , qt .Equals , canvas .String ())
3333}
34+
35+ func (c * Canvas ) String () string {
36+ var buffer bytes.Buffer
37+
38+ for h := 0 ; h < c .Height ; h ++ {
39+ for w := 0 ; w < c .Width ; w ++ {
40+ idx := Index {w , h }
41+
42+ // Search 'text' map; if nothing there try the 'data' map.
43+ r , ok := c .text [idx ]
44+ if ! ok {
45+ r = c .runeAt (idx )
46+ }
47+
48+ _ , err := buffer .WriteRune (r )
49+ if err != nil {
50+ continue
51+ }
52+ }
53+
54+ err := buffer .WriteByte ('\n' )
55+ if err != nil {
56+ continue
57+ }
58+ }
59+
60+ return buffer .String ()
61+ }
You can’t perform that action at this time.
0 commit comments