97 lines
2.1 KiB
Go
97 lines
2.1 KiB
Go
package gui
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
var hotPinkText = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF06B7"))
|
|
var frontText = lipgloss.NewStyle().Foreground(lipgloss.Color("#268bd2"))
|
|
var backText = lipgloss.NewStyle().Foreground(lipgloss.Color("#6c71c4"))
|
|
|
|
func (m *model) nextCard() {
|
|
m.drawSeen = false
|
|
}
|
|
|
|
func (m *model) updateDraw(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
switch msg := msg.(type) {
|
|
|
|
case tea.KeyMsg:
|
|
// string value of keypresses
|
|
switch msg.String() {
|
|
|
|
case "1": // View
|
|
m.drawSeen = true
|
|
case "2": // Correct
|
|
if m.drawSeen {
|
|
// TODO
|
|
}
|
|
case "3": // Incorrect
|
|
if m.drawSeen {
|
|
// TODO:
|
|
}
|
|
case "4": // Skip
|
|
if !m.drawSeen {
|
|
// CAN SKIP
|
|
// TODO:
|
|
}
|
|
|
|
case "ctrl+c", "q":
|
|
return m, tea.Quit
|
|
case "s":
|
|
m.switchMode(Select)
|
|
}
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (m *model) viewDraw() string {
|
|
// TODO: translation I guess?
|
|
viewText := "1: View"
|
|
correctText := "2: Correct"
|
|
incorrectText := "3: Incorrect"
|
|
skipText := "4: Skip"
|
|
correct := fmt.Sprintf(strings.Repeat(" ", len(correctText)+2))
|
|
incorrect := fmt.Sprintf(strings.Repeat(" ", len(incorrectText)+2))
|
|
skip := fmt.Sprintf(strings.Repeat(" ", len(skipText)+2))
|
|
|
|
s := fmt.Sprintf("Draw Mode (%d cards, %v):\n\n", len(m.selected), m.selectedCardIndexes())
|
|
|
|
s += m.cardListToString()
|
|
|
|
text := fmt.Sprintf("%s", m.selected)
|
|
s += fmt.Sprintf("%s", frontText.Width(len(text)).Render(text))
|
|
|
|
view := fmt.Sprintf("[%s]", hotPinkText.Width(7).Render(viewText))
|
|
if m.drawSeen {
|
|
correct = fmt.Sprintf("[%s]", hotPinkText.Width(10).Render(correctText))
|
|
incorrect = fmt.Sprintf("[%s]", hotPinkText.Width(12).Render(incorrectText))
|
|
}
|
|
if !m.drawSeen {
|
|
skip = fmt.Sprintf("[%s]", hotPinkText.Width(7).Render(skipText))
|
|
}
|
|
|
|
s += fmt.Sprintf("%s %s %s %s\n",
|
|
view,
|
|
correct,
|
|
incorrect,
|
|
skip)
|
|
|
|
s += "\nPress [s] to go back to select\nPress [q] to quit."
|
|
|
|
return s
|
|
}
|
|
|
|
func (m *model) cardListToString() string {
|
|
s := ""
|
|
for i, card := range m.deck {
|
|
if _, ok := m.selected[i]; ok {
|
|
s += fmt.Sprintf("%d %s [%s]\n", i, card.Front, card.Back)
|
|
}
|
|
}
|
|
return s
|
|
}
|