Skip to content

Commit 6a172c7

Browse files
committed
Gray out letters in grid
1 parent 1959abe commit 6a172c7

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func runServer(addr string) {
5050

5151
server, err := wish.NewServer(
5252
wish.WithAddress(addr),
53-
wish.WithMaxTimeout(30*time.Minute),
53+
wish.WithIdleTimeout(30*time.Minute),
5454
wish.WithMiddleware(
5555
bm.Middleware(func(s ssh.Session) (tea.Model, []tea.ProgramOption) {
5656
pty, _, active := s.Pty()

model.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,15 @@ func (m *model) reset() {
130130

131131
// setStatus sets the status message, and returns a tea.Cmd that restores the
132132
// 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 {
134134
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
139142
}
140143

141144
// resetStatus immediately resets the status message to its default value.
@@ -151,13 +154,13 @@ func (m *model) doAcceptWord() tea.Cmd {
151154

152155
// Only accept a word if it is complete.
153156
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)
155158
}
156159

157160
// Check if the input word is valid.
158161
word := m.grid[m.gridRow]
159162
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)
161164
}
162165

163166
// Update the state of the used letters.
@@ -234,7 +237,7 @@ func (m *model) doWin() tea.Cmd {
234237
db.addWin(m.gridRow)
235238
m.score = db.score()
236239
}),
237-
m.setStatus("You win! Press [Enter] to play again."),
240+
m.setStatus("You win!", 0),
238241
)
239242
}
240243

@@ -247,7 +250,7 @@ func (m *model) doLoss() tea.Cmd {
247250
db.addLoss()
248251
m.score = db.score()
249252
}),
250-
m.setStatus(msg),
253+
m.setStatus(msg, 0),
251254
)
252255
}
253256

@@ -277,6 +280,11 @@ func (m *model) viewGridRowFilled(word [numChars]byte) string {
277280
var keyStates [numChars]keyState
278281
letters := m.word
279282

283+
// Mark keyStatusAbsent.
284+
for i := 0; i < numChars; i++ {
285+
keyStates[i] = keyStateAbsent
286+
}
287+
280288
// Mark keyStatusCorrect.
281289
for i := 0; i < numChars; i++ {
282290
if word[i] == m.word[i] {
@@ -395,7 +403,7 @@ func (m *model) withDb(f func(db *db)) tea.Cmd {
395403
// reportError stores the given error and prints a message to the status line.
396404
func (m *model) reportError(err error, msg string) tea.Cmd {
397405
m.errors = append(m.errors, err)
398-
return m.setStatus(msg)
406+
return m.setStatus(msg, 3*time.Second)
399407
}
400408

401409
// msgResetStatus is sent when the status line should be reset.

0 commit comments

Comments
 (0)