File tree Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ func main() {
28
28
29
29
func runCli () {
30
30
model := & model {}
31
- program := tea .NewProgram (model , tea . WithAltScreen (), tea . WithOutput ( os . Stderr ) )
31
+ program := tea .NewProgram (model , teaOptions ... )
32
32
33
33
exitCode := 0
34
34
if err := program .Start (); err != nil {
Original file line number Diff line number Diff line change @@ -274,16 +274,29 @@ func (m *model) viewGrid() string {
274
274
// viewGridRowFilled renders a filled-in grid row. It chooses the appropriate
275
275
// color for each key.
276
276
func (m * model ) viewGridRowFilled (word [numChars ]byte ) string {
277
- var keys [numChars ]string
277
+ var keyStates [numChars ]keyState
278
+ letters := m .word
279
+
280
+ // Mark keyStatusCorrect.
278
281
for i := 0 ; i < numChars ; i ++ {
279
- key := word [i ]
280
- keyStatus := keyStateAbsent
281
- if key == m .word [i ] {
282
- keyStatus = keyStateCorrect
283
- } else if bytes .IndexByte (m .word [:], key ) != - 1 {
284
- keyStatus = keyStatePresent
282
+ if word [i ] == m .word [i ] {
283
+ keyStates [i ] = keyStateCorrect
284
+ letters [i ] = 0
285
+ }
286
+ }
287
+
288
+ // Mark keyStatusPresent.
289
+ for i := 0 ; i < numChars ; i ++ {
290
+ if foundIdx := bytes .IndexByte (letters [:], word [i ]); foundIdx != - 1 {
291
+ keyStates [i ] = keyStatePresent
292
+ letters [foundIdx ] = 0
285
293
}
286
- keys [i ] = m .viewKey (string (key ), keyStatus .color ())
294
+ }
295
+
296
+ // Render keys.
297
+ var keys [numChars ]string
298
+ for i := 0 ; i < numChars ; i ++ {
299
+ keys [i ] = m .viewKey (string (word [i ]), keyStates [i ].color ())
287
300
}
288
301
return lipgloss .JoinHorizontal (lipgloss .Bottom , keys [:]... )
289
302
}
You can’t perform that action at this time.
0 commit comments