This repository was archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_grid_test.go
68 lines (64 loc) · 1.56 KB
/
example_grid_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
58
59
60
61
62
63
64
65
66
67
68
// This example demontrates how to create a new grid and do some simple
// manipulations.
package gruid_test
import (
"fmt"
"github.com/anaseto/gruid"
)
func ExampleGrid() {
// Create a new 20x20 grid.
gd := gruid.NewGrid(20, 20)
// Fill the whole grid with dots.
gd.Fill(gruid.Cell{Rune: '.'})
// Define a range (5,5)-(15,15).
rg := gruid.NewRange(5, 5, 15, 15)
// Define a slice of the grid using the range.
rectangle := gd.Slice(rg)
// Fill the rectangle with #.
rectangle.Fill(gruid.Cell{Rune: '#'})
// Print the grid using a non-styled string representation.
fmt.Print(gd)
// Output:
// ....................
// ....................
// ....................
// ....................
// ....................
// .....##########.....
// .....##########.....
// .....##########.....
// .....##########.....
// .....##########.....
// .....##########.....
// .....##########.....
// .....##########.....
// .....##########.....
// .....##########.....
// ....................
// ....................
// ....................
// ....................
// ....................
}
func ExampleGridIterator() {
// Create a new 26x2 grid.
gd := gruid.NewGrid(26, 2)
// Get an iterator.
it := gd.Iterator()
// Iterate on the grid and fill it with successive alphabetic
// characters.
r := 'a'
max := gd.Size()
for it.Next() {
it.SetCell(gruid.Cell{Rune: r})
r++
if it.P().X == max.X-1 {
r = 'A'
}
}
// Print the grid using a non-styled string representation.
fmt.Print(gd)
// Output:
// abcdefghijklmnopqrstuvwxyz
// ABCDEFGHIJKLMNOPQRSTUVWXYZ
}