Skip to content

Commit 961ab83

Browse files
committed
Add controls
1 parent 6a172c7 commit 961ab83

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

model.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (m *model) View() string {
105105
keyboard = ""
106106
}
107107

108-
game := lipgloss.JoinVertical(lipgloss.Center, status, grid, keyboard)
108+
game := lipgloss.JoinVertical(lipgloss.Center, status, grid, keyboard, _controls)
109109
return lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, game)
110110
}
111111

@@ -256,7 +256,7 @@ func (m *model) doLoss() tea.Cmd {
256256

257257
// viewStatus renders the status line.
258258
func (m *model) viewStatus() string {
259-
return m.status
259+
return lipgloss.NewStyle().Foreground(colorPrimary).Render(m.status)
260260
}
261261

262262
// viewGrid renders the grid.
@@ -325,7 +325,7 @@ func (m *model) viewGridRowCurrent(row [numChars]byte, rowIdx int) string {
325325
} else {
326326
key = " "
327327
}
328-
keys[i] = m.viewKey(key, keyStateUnselected.color())
328+
keys[i] = m.viewKey(key, colorPrimary)
329329
}
330330
return lipgloss.JoinHorizontal(lipgloss.Bottom, keys[:]...)
331331
}
@@ -409,6 +409,14 @@ func (m *model) reportError(err error, msg string) tea.Cmd {
409409
// msgResetStatus is sent when the status line should be reset.
410410
type msgResetStatus struct{}
411411

412+
const (
413+
colorPrimary = lipgloss.Color("#d7dadc")
414+
colorSecondary = lipgloss.Color("#626262")
415+
colorSeparator = lipgloss.Color("#9c9c9c")
416+
colorYellow = lipgloss.Color("#b59f3b")
417+
colorGreen = lipgloss.Color("#538d4e")
418+
)
419+
412420
// keyState represents the state of a key.
413421
type keyState int
414422

@@ -421,27 +429,28 @@ const (
421429

422430
// color returns the appropriate dark mode color for the given key state.
423431
func (s keyState) color() lipgloss.Color {
424-
const (
425-
colorPrimary = lipgloss.Color("#d7dadc")
426-
colorAbsent = lipgloss.Color("#3a3a3c")
427-
colorPresent = lipgloss.Color("#b59f3b")
428-
colorCorrect = lipgloss.Color("#538d4e")
429-
)
430-
431432
switch s {
432433
case keyStateUnselected:
433434
return colorPrimary
434435
case keyStateAbsent:
435-
return colorAbsent
436+
return colorSecondary
436437
case keyStatePresent:
437-
return colorPresent
438+
return colorYellow
438439
case keyStateCorrect:
439-
return colorCorrect
440+
return colorGreen
440441
default:
441442
panic("invalid key status")
442443
}
443444
}
444445

446+
var _controls = fmt.Sprintf("%s %s %s %s %s",
447+
lipgloss.NewStyle().Foreground(colorPrimary).Render("ctrl+c"),
448+
lipgloss.NewStyle().Foreground(colorSecondary).Render("quit"),
449+
lipgloss.NewStyle().Foreground(colorSeparator).Render("//"),
450+
lipgloss.NewStyle().Foreground(colorPrimary).Render("ctrl+r"),
451+
lipgloss.NewStyle().Foreground(colorSecondary).Render("restart"),
452+
)
453+
445454
// isAsciiUpper checks if a rune is between A-Z.
446455
func isAsciiUpper(r rune) bool {
447456
return 'A' <= r && r <= 'Z'

0 commit comments

Comments
 (0)