Skip to content

Commit 0ded65c

Browse files
committed
finalize protip function and add manatee
1 parent 2e43881 commit 0ded65c

File tree

2 files changed

+98
-17
lines changed

2 files changed

+98
-17
lines changed

pkg/cmd/protip/protip.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func NewCmdProtip(f *cmdutil.Factory, runF func(*ProtipOptions) error) *cobra.Co
2323
opts := &ProtipOptions{
2424
IO: f.IOStreams,
2525
Sprites: map[string]*Sprite{
26-
"clippy": Clippy(),
26+
"clippy": Clippy(),
27+
"manatee": Manatee(),
2728
},
2829
}
2930

@@ -50,6 +51,8 @@ func NewCmdProtip(f *cmdutil.Factory, runF func(*ProtipOptions) error) *cobra.Co
5051
func protipRun(opts *ProtipOptions) error {
5152
tcell.SetEncodingFallback(tcell.EncodingFallbackASCII)
5253

54+
tip := getProtip()
55+
5356
style := tcell.StyleDefault
5457

5558
s, err := tcell.NewScreen()
@@ -96,15 +99,9 @@ loop:
9699
break loop
97100
case <-time.After(time.Millisecond * 500):
98101
}
99-
//w, h := s.Size()
100-
//w, _ := s.Size()
101102
s.Clear()
102103
drawSprite(s, 0, 0, style, opts.Sprite)
103-
tipLines := []string{
104-
"To merge a PR, review it until",
105-
"it is approved.",
106-
}
107-
drawProtip(s, opts.Sprite.Width, 1, style, tipLines)
104+
drawProtip(s, opts.Sprite.Width, 1, style, tip)
108105
s.Show()
109106
}
110107

@@ -147,20 +144,20 @@ func drawProtip(s tcell.Screen, startX, startY int, st tcell.Style, tipLines []s
147144
topBorder += "-*"
148145
bottomBorder += "_*"
149146

150-
emitStr(s, startX, startY, st, topBorder)
147+
drawStr(s, startX, startY, st, topBorder)
151148

152149
y := startY + 1
153150

154151
for iy, line := range tipLines {
155-
emitStr(s, startX, y+iy, st, pad(line))
152+
drawStr(s, startX, y+iy, st, pad(line))
156153
y += iy
157154
}
158155

159-
emitStr(s, startX, y+1, st, bottomBorder)
160-
emitStr(s, startX, y+2, st, "/")
156+
drawStr(s, startX, y+1, st, bottomBorder)
157+
drawStr(s, startX, y+2, st, "/")
161158
}
162159

163-
func emitStr(s tcell.Screen, x, y int, style tcell.Style, str string) {
160+
func drawStr(s tcell.Screen, x, y int, style tcell.Style, str string) {
164161
for _, c := range str {
165162
var comb []rune
166163
w := runewidth.RuneWidth(c)
@@ -175,7 +172,6 @@ func emitStr(s tcell.Screen, x, y int, style tcell.Style, str string) {
175172
}
176173

177174
func drawSprite(s tcell.Screen, x, y int, st tcell.Style, sp *Sprite) {
178-
// TODO worry about animation later
179175
cells := sp.Cells()
180176
for y := 0; y < len(cells); y++ {
181177
row := cells[y]
@@ -185,6 +181,3 @@ func drawSprite(s tcell.Screen, x, y int, st tcell.Style, sp *Sprite) {
185181
}
186182
sp.IncrFrame()
187183
}
188-
189-
// Want to be able to have a sprite that occupies a rectangle and can animate internally relative to
190-
// its own geometry.

pkg/cmd/protip/sprites.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,94 @@ func (s *Sprite) Cells() [][]rune {
2727
return out
2828
}
2929

30+
func Manatee() *Sprite {
31+
s := &Sprite{
32+
Width: 40,
33+
Height: 14,
34+
}
35+
36+
s.AddFrame(`
37+
_.---.._
38+
_ _.-' ''-.
39+
.' '-,_.-' '''.
40+
( _ o :
41+
'._ .-' '-._ \ \- ---]
42+
'-.___.-') )..-'
43+
(_/
44+
45+
46+
47+
(art by MJP)
48+
`)
49+
s.AddFrame(`
50+
51+
_.---.._
52+
_ _.-' ''-.
53+
.' '-,_.-' '''.
54+
( _ o :
55+
'._ .-' '-._ \ \- ---]
56+
'-.___.-') )..-'
57+
(_/
58+
59+
60+
(art by MJP)
61+
`)
62+
s.AddFrame(`
63+
64+
65+
_.---.._
66+
_ _.-' ''-.
67+
.' '-,_.-' '''.
68+
( _ o :
69+
'._ .-' '-._ \ \- ---]
70+
'-.___.-') )..-'
71+
(_/
72+
73+
(art by MJP)
74+
`)
75+
s.AddFrame(`
76+
77+
78+
79+
_.---.._
80+
_ _.-' ''-.
81+
.' '-,_.-' '''.
82+
( _ o :
83+
'._ .-' '-._ \ \- ---]
84+
'-.___.-') )..-'
85+
(_/
86+
(art by MJP)
87+
`)
88+
s.AddFrame(`
89+
90+
91+
_.---.._
92+
_ _.-' ''-.
93+
.' '-,_.-' '''.
94+
( _ o :
95+
'._ .-' '-._ \ \- ---]
96+
'-.___.-') )..-'
97+
(_/
98+
99+
(art by MJP)
100+
`)
101+
s.AddFrame(`
102+
103+
_.---.._
104+
_ _.-' ''-.
105+
.' '-,_.-' '''.
106+
( _ o :
107+
'._ .-' '-._ \ \- ---]
108+
'-.___.-') )..-'
109+
(_/
110+
111+
112+
(art by MJP)
113+
`)
114+
115+
return s
116+
}
117+
30118
func Clippy() *Sprite {
31119
s := &Sprite{
32120
Width: 15,

0 commit comments

Comments
 (0)