selectedCardIndexes
This commit is contained in:
parent
c1a547f033
commit
5965b3300a
66
gui/draw.go
66
gui/draw.go
@ -2,21 +2,43 @@ package gui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
const hotPink = lipgloss.Color("#FF06B7")
|
||||
var hotPinkText = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF06B7"))
|
||||
var frontText = lipgloss.NewStyle().Foreground(lipgloss.Color("#268bd2"))
|
||||
var backText = lipgloss.NewStyle().Foreground(lipgloss.Color("#6c71c4"))
|
||||
|
||||
var hotPinkInput = lipgloss.NewStyle().Foreground(hotPink)
|
||||
func (m *model) nextCard() {
|
||||
m.drawSeen = false
|
||||
}
|
||||
|
||||
func (m *model) updateDraw(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
|
||||
// Is it a key press?
|
||||
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":
|
||||
@ -27,14 +49,36 @@ func (m *model) updateDraw(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
func (m *model) viewDraw() string {
|
||||
s := fmt.Sprintf("Draw Mode (%d cards):\n\n", len(m.selected))
|
||||
// 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("[%s] [%s] [%s] [%s]\n",
|
||||
hotPinkInput.Width(7).Render("1: View"),
|
||||
hotPinkInput.Width(10).Render("2: Correct"),
|
||||
hotPinkInput.Width(12).Render("3: Incorrect"),
|
||||
hotPinkInput.Width(7).Render("4: Skip"),
|
||||
)
|
||||
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."
|
||||
|
||||
@ -45,7 +89,7 @@ func (m *model) cardListToString() string {
|
||||
s := ""
|
||||
for i, card := range m.deck {
|
||||
if _, ok := m.selected[i]; ok {
|
||||
s += fmt.Sprintf("%s [%s]\n", card.Front, card.Back)
|
||||
s += fmt.Sprintf("%d %s [%s]\n", i, card.Front, card.Back)
|
||||
}
|
||||
}
|
||||
return s
|
||||
|
12
gui/model.go
12
gui/model.go
@ -4,6 +4,7 @@ import (
|
||||
"gitea.tyrel.dev/tyrel/itor/models"
|
||||
"github.com/charmbracelet/bubbles/list"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type model struct {
|
||||
@ -16,10 +17,21 @@ type model struct {
|
||||
createInputs []textinput.Model // Inputs for front and back, is an array because we change position by an index
|
||||
createdInputIndex int // holds an index for which input is active editing in create mode
|
||||
|
||||
drawSeen bool
|
||||
drawCardIndex int
|
||||
|
||||
mode Mode
|
||||
err error
|
||||
}
|
||||
|
||||
func (m *model) selectedCardIndexes() []int {
|
||||
var keys []int
|
||||
for _, key := range reflect.ValueOf(m.selected).MapKeys() {
|
||||
keys = append(keys, int(key.Int()))
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func initialModel() model {
|
||||
front := textinput.New()
|
||||
front.Placeholder = "Front..."
|
||||
|
Loading…
Reference in New Issue
Block a user