@@ -130,12 +130,15 @@ func (m *model) reset() {
130
130
131
131
// setStatus sets the status message, and returns a tea.Cmd that restores the
132
132
// default status message after a delay.
133
- func (m * model ) setStatus (msg string ) tea.Cmd {
133
+ func (m * model ) setStatus (msg string , duration time. Duration ) tea.Cmd {
134
134
m .status = msg
135
- m .statusPending ++
136
- return tea .Tick (5 * time .Second , func (time.Time ) tea.Msg {
137
- return msgResetStatus {}
138
- })
135
+ if duration > 0 {
136
+ m .statusPending ++
137
+ return tea .Tick (duration , func (time.Time ) tea.Msg {
138
+ return msgResetStatus {}
139
+ })
140
+ }
141
+ return nil
139
142
}
140
143
141
144
// resetStatus immediately resets the status message to its default value.
@@ -151,13 +154,13 @@ func (m *model) doAcceptWord() tea.Cmd {
151
154
152
155
// Only accept a word if it is complete.
153
156
if m .gridCol != numChars {
154
- return m .setStatus ("Your guess must be a 5-letter word." )
157
+ return m .setStatus ("Your guess must be a 5-letter word." , 1 * time . Second )
155
158
}
156
159
157
160
// Check if the input word is valid.
158
161
word := m .grid [m .gridRow ]
159
162
if ! isWord (string (word [:])) {
160
- return m .setStatus ("That's not a valid word." )
163
+ return m .setStatus ("That's not a valid word." , 1 * time . Second )
161
164
}
162
165
163
166
// Update the state of the used letters.
@@ -234,7 +237,7 @@ func (m *model) doWin() tea.Cmd {
234
237
db .addWin (m .gridRow )
235
238
m .score = db .score ()
236
239
}),
237
- m .setStatus ("You win! Press [Enter] to play again." ),
240
+ m .setStatus ("You win!" , 0 ),
238
241
)
239
242
}
240
243
@@ -247,7 +250,7 @@ func (m *model) doLoss() tea.Cmd {
247
250
db .addLoss ()
248
251
m .score = db .score ()
249
252
}),
250
- m .setStatus (msg ),
253
+ m .setStatus (msg , 0 ),
251
254
)
252
255
}
253
256
@@ -277,6 +280,11 @@ func (m *model) viewGridRowFilled(word [numChars]byte) string {
277
280
var keyStates [numChars ]keyState
278
281
letters := m .word
279
282
283
+ // Mark keyStatusAbsent.
284
+ for i := 0 ; i < numChars ; i ++ {
285
+ keyStates [i ] = keyStateAbsent
286
+ }
287
+
280
288
// Mark keyStatusCorrect.
281
289
for i := 0 ; i < numChars ; i ++ {
282
290
if word [i ] == m .word [i ] {
@@ -395,7 +403,7 @@ func (m *model) withDb(f func(db *db)) tea.Cmd {
395
403
// reportError stores the given error and prints a message to the status line.
396
404
func (m * model ) reportError (err error , msg string ) tea.Cmd {
397
405
m .errors = append (m .errors , err )
398
- return m .setStatus (msg )
406
+ return m .setStatus (msg , 3 * time . Second )
399
407
}
400
408
401
409
// msgResetStatus is sent when the status line should be reset.
0 commit comments