dracosh 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +25 -17
  2. package/locales/de.json +1098 -0
  3. package/locales/en.json +1081 -0
  4. package/locales/fr.json +1148 -0
  5. package/locales/pl.json +1173 -0
  6. package/locales/uk.json +1174 -0
  7. package/package.json +2 -2
  8. package/src/alerts.js +71 -4
  9. package/src/backup.js +2 -1
  10. package/src/cardline.js +71 -0
  11. package/src/cli.js +41 -54
  12. package/src/commands.js +14 -12
  13. package/src/demo.js +11 -0
  14. package/src/diff.js +20 -10
  15. package/src/i18n.js +68 -0
  16. package/src/judge.js +164 -13
  17. package/src/language.js +355 -0
  18. package/src/library.js +91 -38
  19. package/src/lock.js +2 -1
  20. package/src/manage.js +193 -58
  21. package/src/pause.js +1 -2
  22. package/src/progress.js +119 -63
  23. package/src/quiet.js +3 -2
  24. package/src/scheduler.js +26 -9
  25. package/src/session.js +118 -36
  26. package/src/settings.js +14 -6
  27. package/src/starter.js +36 -27
  28. package/src/store.js +11 -8
  29. package/src/tips.js +12 -3
  30. package/src/ui/AddCard.js +449 -81
  31. package/src/ui/AnswerInput.js +22 -10
  32. package/src/ui/App.js +209 -57
  33. package/src/ui/BadgeUnlock.js +5 -4
  34. package/src/ui/Badges.js +9 -8
  35. package/src/ui/Choice.js +14 -9
  36. package/src/ui/Companion.js +13 -13
  37. package/src/ui/Confetti.js +2 -2
  38. package/src/ui/Decks.js +167 -9
  39. package/src/ui/DieRoll.js +9 -9
  40. package/src/ui/Evolution.js +7 -7
  41. package/src/ui/Hatch.js +7 -6
  42. package/src/ui/Header.js +58 -16
  43. package/src/ui/Help.js +43 -25
  44. package/src/ui/Languages.js +167 -0
  45. package/src/ui/Mascot.js +1 -2
  46. package/src/ui/Missed.js +13 -12
  47. package/src/ui/Preview.js +48 -29
  48. package/src/ui/Reset.js +13 -14
  49. package/src/ui/Settings.js +27 -19
  50. package/src/ui/Stats.js +24 -23
  51. package/src/ui/Summary.js +30 -15
  52. package/src/ui/TheOne.js +7 -6
  53. package/src/ui/icons.js +1 -2
  54. package/src/ui/kit.js +34 -6
  55. package/src/vacation.js +2 -1
  56. package/src/words.js +8 -2
  57. package/data/tips.json +0 -32
package/src/ui/Badges.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment, useEffect, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
3
+ import { Box, useInput } from "ink";
4
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
4
5
  import { badgeColor, BadgeIcon, ICON_WIDTH } from "./icons.js";
5
6
 
6
7
  const COLUMNS = 3;
@@ -14,8 +15,8 @@ const LIT_FROM = 5;
14
15
  const GREY = "#4a5058";
15
16
 
16
17
  // a hidden badge reveals nothing until it's won
17
- const SECRET = { name: "???", desc: "a secret, keep playing" };
18
- const display = (badge) => (badge.hidden && !badge.unlockedOn ? { ...badge, ...SECRET } : badge);
18
+ const secret = () => ({ name: t("badgesScreen.secretName"), desc: t("badgesScreen.secretDesc") });
19
+ const display = (badge) => (badge.hidden && !badge.unlockedOn ? { ...badge, ...secret() } : badge);
19
20
  const WHITE = "#ffffff";
20
21
 
21
22
  // where a fresh badge is in its little animation: "waiting" (still looks locked), "flash", or "lit"
@@ -74,9 +75,9 @@ export function Badges({ badges, fresh = [], onClose }) {
74
75
  <${Fragment}>
75
76
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
76
77
  <${Box}>
77
- <${Text} bold color=${theme.accent}>Badges<//>
78
+ <${Text} bold color=${theme.accent}>${t("badgesScreen.title")}<//>
78
79
  <${Text} dimColor> ${unlocked}/${badges.length}<//>
79
- ${fresh.length > 0 && html`<${Text} color=${theme.warn}> ${fresh.length} new<//>`}
80
+ ${fresh.length > 0 && html`<${Text} color=${theme.warn}>${t("badgesScreen.new", { count: fresh.length })}<//>`}
80
81
  <//>
81
82
 
82
83
  <${Box} marginTop=${1}>
@@ -86,7 +87,7 @@ export function Badges({ badges, fresh = [], onClose }) {
86
87
  <${Box} flexDirection="column" justifyContent="center">
87
88
  <${Box}><${Text} bold color=${shownUnlocked ? badgeColor(badge.id) : undefined} dimColor=${!shownUnlocked}>${badge.name}<//><//>
88
89
  <${Box}><${Text}>${badge.desc}<//><//>
89
- <${Box}><${Text} dimColor>${badge.unlockedOn ? `unlocked ${badge.unlockedOn}` : "still locked"}<//><//>
90
+ <${Box}><${Text} dimColor>${badge.unlockedOn ? t("badgesScreen.unlocked", { day: badge.unlockedOn }) : t("badgesScreen.locked")}<//><//>
90
91
  <//>
91
92
  <//>
92
93
 
@@ -116,7 +117,7 @@ export function Badges({ badges, fresh = [], onClose }) {
116
117
  )}
117
118
  <//>
118
119
  <//>
119
- <${Box} paddingX=${1}><${KeyHints} text="↑/↓ browse · ←/→ column · esc back" /><//>
120
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.badges")} /><//>
120
121
  <//>
121
122
  `;
122
123
  }
package/src/ui/Choice.js CHANGED
@@ -1,7 +1,8 @@
1
- import { Box, Text, useInput } from "ink";
2
- import { html, theme } from "./kit.js";
1
+ import { Box, useInput } from "ink";
2
+ import { t } from "../i18n.js";
3
+ import { cellWidth, html, Text, theme, usePanelWidth } from "./kit.js";
3
4
 
4
- // A question's answers as a list: ↑/↓ and Enter, a number, or an option's own key ("y", "n").
5
+ // A question's answers as a list: ↑/↓ and Enter, a number, or an option's own keys ("t|y" in Polish).
5
6
  // Each option: { label, note?, key?, danger? }; `danger` paints it red while it's chosen.
6
7
  export function Choice({ options, selected, onMove, onPick, onCancel }) {
7
8
  useInput((input, key) => {
@@ -9,20 +10,23 @@ export function Choice({ options, selected, onMove, onPick, onCancel }) {
9
10
  if (key.upArrow) return onMove(Math.max(0, selected - 1));
10
11
  if (key.downArrow) return onMove(Math.min(options.length - 1, selected + 1));
11
12
  if (key.return) return onPick(selected);
12
- const index = options.findIndex((o, i) => input === String(i + 1) || (o.key && input.toLowerCase() === o.key));
13
+ const index = options.findIndex((o, i) => input === String(i + 1) || (o.key && o.key.split("|").includes(input.toLowerCase())));
13
14
  if (index >= 0) onPick(index);
14
15
  });
15
16
 
16
- const width = Math.max(...options.map((o) => o.label.length)) + 2;
17
+ const panel = usePanelWidth();
18
+ const width = Math.max(...options.map((o) => cellWidth(o.label))) + 2;
19
+ // in a narrow pane the notes go under their labels instead of wrapping into a thin column
20
+ const stacked = options.some((o) => o.note && 5 + width + cellWidth(o.note) > panel - 6);
17
21
  return html`
18
22
  <${Box} flexDirection="column">
19
23
  ${options.map((o, i) => {
20
24
  const on = i === selected;
21
25
  const color = on ? (o.danger ? theme.bad : theme.accent) : undefined;
22
26
  return html`
23
- <${Box} key=${o.label}>
24
- <${Box} flexShrink=${0}><${Text} color=${color} bold=${on}>${on ? "❯" : " "} ${i + 1}. ${o.label.padEnd(width)}<//><//>
25
- ${o.note && html`<${Text} dimColor>${o.note}<//>`}
27
+ <${Box} key=${o.label} flexDirection=${stacked ? "column" : "row"}>
28
+ <${Box} flexShrink=${0}><${Text} color=${color} bold=${on}>${on ? "❯" : " "} ${i + 1}. ${stacked ? o.label : o.label + " ".repeat(width - cellWidth(o.label))}<//><//>
29
+ ${o.note && html`<${Box} marginLeft=${stacked ? 5 : 0}><${Text} dimColor>${o.note}<//><//>`}
26
30
  <//>
27
31
  `;
28
32
  })}
@@ -30,4 +34,5 @@ export function Choice({ options, selected, onMove, onPick, onCancel }) {
30
34
  `;
31
35
  }
32
36
 
33
- export const CHOICE_KEYS = "↑/↓ choose · enter confirm";
37
+ // the footer under a list of choices; `end` is what Esc does there ("back" or "cancel")
38
+ export const choiceHints = (end = "back") => t(end === "cancel" ? "keyHints.choiceCancel" : "keyHints.choiceBack", { choose: t("choice.keys") });
@@ -1,10 +1,11 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { ELEMENT_ADJECTIVE, STAGES } from "../progress.js";
4
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
3
+ import { Box, useInput } from "ink";
4
+ import { dragonName, elementName, STAGES } from "../progress.js";
5
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
5
6
  import { ELEMENT_COLOR, Mascot } from "./Mascot.js";
6
7
 
7
- const requirement = (stage, locked) => (stage.from === 0 ? "from the start" : `${locked ? "needs " : ""}${stage.from} days`);
8
+ const requirement = (stage, locked) => (stage.from === 0 ? t("companion.fromStart") : t(locked ? "companion.needsDays" : "companion.days", { count: stage.from }));
8
9
 
9
10
  // Every form of the companion. Forms you haven't reached are flat silhouettes named "???".
10
11
  // Its moods aren't listed here on purpose: you find them out by playing.
@@ -17,29 +18,28 @@ export function Companion({ current, best, element = null, roll = null, onClose
17
18
  return html`
18
19
  <${Fragment}>
19
20
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
20
- <${Text} bold color=${theme.accent}>Companion<//>
21
+ <${Text} bold color=${theme.accent}>${t("companion.title")}<//>
21
22
  <${Box} marginTop=${1}>
22
- <${Text}>Your dragon: <//>
23
- ${element && html`<${Text} bold color=${ELEMENT_COLOR[element]}>${ELEMENT_ADJECTIVE[element]} <//>`}
24
- <${Text} bold>${STAGES[current].name}<//>
23
+ <${Text}>${t("companion.yourDragon")}<//>
24
+ <${Text} bold color=${element ? ELEMENT_COLOR[element] : undefined}>${dragonName(current, element)}<//>
25
25
  <//>
26
- <${Text} dimColor>${element ? `Element: ${element}${roll ? ` · rolled a ${roll.face} on Dragon's die, ${roll.on}` : ""}` : "No element yet. Some say a die decides it…"}<//>
27
- <${Box} marginTop=${1}><${Text} dimColor>Evolves with your best streak (${best} days) and never loses a form.<//><//>
26
+ <${Text} dimColor>${element ? `${t("companion.element", { element: elementName(element) })}${roll ? t("companion.rolled", { face: roll.face, day: roll.on }) : ""}` : t("companion.noElement")}<//>
27
+ <${Box} marginTop=${1}><${Text} dimColor>${t("companion.evolves", { count: best })}<//><//>
28
28
 
29
29
  <${Box} marginTop=${1} flexWrap="wrap">
30
30
  ${STAGES.map((stage, i) => {
31
31
  const locked = i > current;
32
32
  return html`
33
- <${Box} key=${stage.name} width=${22} flexDirection="column" marginBottom=${1}>
33
+ <${Box} key=${stage.id} width=${22} flexDirection="column" marginBottom=${1}>
34
34
  <${Box} flexDirection="column"><${Mascot} stage=${i} locked=${locked} face=${locked ? "idle" : "smile"} element=${element} /><//>
35
- <${Text} bold=${i === current} color=${i === current ? theme.accent : undefined} dimColor=${locked}>${locked ? "???" : stage.name}${i === current ? " ← now" : ""}<//>
35
+ <${Text} bold=${i === current} color=${i === current ? theme.accent : undefined} dimColor=${locked}>${locked ? t("companion.unknown") : stage.name}${i === current ? t("companion.now") : ""}<//>
36
36
  <${Text} dimColor>${requirement(stage, locked)}<//>
37
37
  <//>
38
38
  `;
39
39
  })}
40
40
  <//>
41
41
  <//>
42
- <${Box} paddingX=${1}><${KeyHints} text="esc back" /><//>
42
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.back")} /><//>
43
43
  <//>
44
44
  `;
45
45
  }
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useMemo, useState } from "react";
2
- import { Box, Text } from "ink";
3
- import { html, theme } from "./kit.js";
2
+ import { Box } from "ink";
3
+ import { html, Text, theme } from "./kit.js";
4
4
 
5
5
  const ROWS = 4;
6
6
  const FRAME_MS = 100;
package/src/ui/Decks.js CHANGED
@@ -1,15 +1,26 @@
1
- import { Fragment, useEffect, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { Choice, CHOICE_KEYS } from "./Choice.js";
4
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
1
+ import { Fragment, useEffect, useRef, useState } from "react";
2
+ import { Box, useInput } from "ink";
3
+ import { t } from "../i18n.js";
4
+ import { Choice, choiceHints } from "./Choice.js";
5
+ import { LanguagePicker, pairText } from "./Languages.js";
6
+ import { isKnown, languageName } from "../language.js";
7
+ import { cutToWidth, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
8
+
9
+ const DIRECTIONS = ["forward", "backward", "both"];
5
10
 
6
11
  // /decks: your decks with their card counts; Enter quizzes the chosen one from now on, and
7
- // "+ New deck" starts one (`onNew`). Renaming and deleting decks come later.
8
- export function Decks({ current, actions, onPick, onNew, onClose }) {
12
+ // "+ New deck" starts one (`onNew`). → on a deck of yours: which way it's asked and its languages.
13
+ // Renaming and deleting decks come later.
14
+ export function Decks({ current, actions, onPick, onNew, onClose, onDirections, onLanguages }) {
9
15
  const panel = usePanelWidth();
10
16
  const [decks, setDecks] = useState(null);
11
17
  const [picked, setPicked] = useState(0);
12
18
  const [error, setError] = useState("");
19
+ const [menu, setMenu] = useState(null); // { deck, selected }: a deck's settings
20
+ const [setting, setSetting] = useState(null); // { deck, selected }: the direction being picked
21
+ const [naming, setNaming] = useState(null); // the deck whose languages are being picked
22
+ const saving = useRef(false);
23
+ const [message, setMessage] = useState("");
13
24
 
14
25
  useEffect(() => {
15
26
  actions.allDecks().then(
@@ -23,17 +34,163 @@ export function Decks({ current, actions, onPick, onNew, onClose }) {
23
34
 
24
35
  useInput((input, key) => {
25
36
  if (!decks?.length && (key.escape || input === "q")) onClose();
37
+ const deck = decks?.[picked];
38
+ // → into a deck's settings, ← back out of them (Esc works too)
39
+ if (key.leftArrow && !naming) {
40
+ if (setting) return setSetting(null);
41
+ if (menu) return setMenu(null);
42
+ }
43
+ // not while a change is still being saved: the menu would show the deck as it was
44
+ if (key.rightArrow && !menu && !setting && !naming && !saving.current && deck && !deck.tour) {
45
+ setMessage("");
46
+ setMenu({ deck, selected: 0 });
47
+ }
26
48
  });
27
49
 
50
+ // progress of a direction turned off stays: turning it back on picks up where it was
51
+ async function setDirections(index) {
52
+ const { deck } = setting;
53
+ setSetting(null);
54
+ setMenu(null);
55
+ if (DIRECTIONS[index] === deck.directions) return; // nothing changed, nothing to say
56
+ saving.current = true;
57
+ try {
58
+ const { cardIds } = await actions.setDirections(deck.name, DIRECTIONS[index]);
59
+ await onDirections?.(cardIds, DIRECTIONS[index]);
60
+ setDecks((all) => all.map((d) => (d.name === deck.name ? { ...d, directions: DIRECTIONS[index] } : d)));
61
+ setMessage(t("decks.directionSaved", { deck: deck.name }));
62
+ } catch (err) {
63
+ setError(err.message);
64
+ } finally {
65
+ saving.current = false;
66
+ }
67
+ }
68
+
69
+ // the menu stays underneath: Esc in the direction or language picker comes back to it
70
+ function openSetting(index) {
71
+ const { deck } = menu;
72
+ setMenu((m) => ({ ...m, selected: index })); // coming back, the cursor is on the row you opened
73
+ const rows = ["ask", "languages", ...(deck.learning ? ["learning"] : []), ...(deck.languages.guessed ? [] : ["detect"])];
74
+ if (rows[index] === "ask") return setSetting({ deck, selected: Math.max(0, DIRECTIONS.indexOf(deck.directions)) });
75
+ if (rows[index] === "languages") return setNaming(deck);
76
+ if (rows[index] === "learning") return setNaming({ ...deck, only: "learning" });
77
+ setLanguages(null, deck); // detect them from the cards again
78
+ }
79
+
80
+ // the language you're learning in the deck (pronunciation reads it, "almost" applies to it)
81
+ async function saveLearning(deck, lang) {
82
+ setNaming(null);
83
+ setMenu(null);
84
+ saving.current = true;
85
+ try {
86
+ const learning = await actions.setLearning(deck.name, lang);
87
+ setDecks((all) => all.map((d) => (d.name === deck.name ? { ...d, learning } : d)));
88
+ setMessage(t("languages.learningSaved", { deck: deck.name, language: languageName(learning?.lang) }));
89
+ onLanguages?.(deck.name);
90
+ } catch (err) {
91
+ setError(err.message);
92
+ } finally {
93
+ saving.current = false;
94
+ }
95
+ }
96
+
97
+ async function setLanguages(languages, deck = naming) {
98
+ setNaming(null);
99
+ setMenu(null);
100
+ saving.current = true;
101
+ try {
102
+ const saved = await actions.setLanguages(deck.name, languages);
103
+ setDecks((all) => all.map((d) => (d.name === deck.name ? { ...d, languages: saved, learning: saved.learning } : d)));
104
+ setMessage(
105
+ !languages ? t("languages.detecting", { deck: deck.name }) : saved.learning ? t("languages.savedWithLearning", { deck: deck.name, pair: pairText(saved), language: languageName(saved.learning.lang) }) : t("languages.saved", { deck: deck.name, pair: pairText(saved) })
106
+ );
107
+ onLanguages?.(deck.name);
108
+ } catch (err) {
109
+ setError(err.message);
110
+ } finally {
111
+ saving.current = false;
112
+ }
113
+ }
114
+
115
+ const short = (text) => cutToWidth(text, Math.max(12, Math.floor(panel / 2) - 8));
116
+ const directionOptions = (deck) => {
117
+ const [front, back] = deck.sample ? [short(deck.sample.front), short(deck.sample.back.join(" / "))] : [t("decks.front"), t("decks.back")];
118
+ return [
119
+ { label: `${front} → ?`, note: deck.directions === "forward" ? t("languages.current") : "" },
120
+ { label: `${back} → ?`, note: deck.directions === "backward" ? t("languages.current") : "" },
121
+ { label: t("add.bothWays"), note: deck.directions === "both" ? t("languages.current") : "" }
122
+ ];
123
+ };
124
+
125
+ if (naming)
126
+ return html`<${LanguagePicker}
127
+ deck=${naming.name}
128
+ sample=${naming.sample}
129
+ languages=${naming.languages}
130
+ learning=${naming.learning}
131
+ home=${naming.home}
132
+ start=${naming.only ?? "front"}
133
+ onDone=${(picked) => (naming.only ? saveLearning(naming, picked.learning) : setLanguages(picked))}
134
+ onCancel=${() => setNaming(null)}
135
+ />`;
136
+
137
+ if (setting) return directionPicker();
138
+
139
+ if (menu) {
140
+ const { deck } = menu;
141
+ const guessedNote = deck.languages.guessed && deck.cards > 0 && (isKnown(deck.languages.front) || isKnown(deck.languages.back)) ? ` · ${t("languages.guessed")}` : "";
142
+ const how = directionOptions(deck)[Math.max(0, DIRECTIONS.indexOf(deck.directions))].label;
143
+ return html`
144
+ <${Fragment}>
145
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
146
+ <${Text} bold color=${theme.accent}>${deck.name}<//>
147
+ <${Box} marginTop=${1}>
148
+ <${Choice}
149
+ options=${[
150
+ { label: t("decks.askRow"), note: deck.directions === "both" ? t("add.bothWays") : how },
151
+ { label: t("decks.languagesRow"), note: pairText(deck.languages) + guessedNote },
152
+ ...(deck.learning ? [{ label: t("decks.learningRow"), note: languageName(deck.learning.lang) + (deck.learning.sure ? "" : ` · ${t("languages.guessShort")}`) }] : []),
153
+ ...(deck.languages.guessed ? [] : [{ label: t("decks.detectRow") }])
154
+ ]}
155
+ selected=${menu.selected}
156
+ onMove=${(selected) => setMenu((m) => ({ ...m, selected }))}
157
+ onPick=${openSetting}
158
+ onCancel=${() => setMenu(null)}
159
+ />
160
+ <//>
161
+ <//>
162
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.choiceLeft", { choose: t("choice.keys") })} /><//>
163
+ <//>
164
+ `;
165
+ }
166
+
167
+ function directionPicker() {
168
+ return html`
169
+ <${Fragment}>
170
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
171
+ <${Text} bold color=${theme.accent}>${t("add.directionQuestion", { deck: setting.deck.name })}<//>
172
+ <${Box} marginTop=${1}>
173
+ <${Choice} options=${directionOptions(setting.deck)} selected=${setting.selected} onMove=${(selected) => setSetting((s) => ({ ...s, selected }))} onPick=${setDirections} onCancel=${() => setSetting(null)} />
174
+ <//>
175
+ <${Box} marginTop=${1}><${Text} dimColor>${t("decks.progressKept")}<//><//>
176
+ <//>
177
+ <${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.choiceLeft", { choose: t("choice.keys") })} /><//>
178
+ <//>
179
+ `;
180
+ }
181
+
182
+ // a deck's languages show in the list once the cards tell at least one
183
+ const languagesNote = (d) => (d.tour || !d.cards ? "" : d.learning ? t("decks.learningShort", { language: languageName(d.learning.lang) }) : isKnown(d.languages.front) && isKnown(d.languages.back) ? pairText(d.languages) : "");
184
+
28
185
  return html`
29
186
  <${Fragment}>
30
187
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
31
- <${Text} bold color=${theme.accent}>Decks<//>
188
+ <${Text} bold color=${theme.accent}>${t("decks.title")}<//>
32
189
  ${decks?.length > 0 &&
33
190
  html`
34
191
  <${Box} marginTop=${1}>
35
192
  <${Choice}
36
- options=${[...decks.map((d) => ({ label: d.name, note: `${d.cards} card${d.cards === 1 ? "" : "s"}${d.tour ? " · the tour" : ""}${d.name === current ? " · now" : ""}` })), { label: "+ New deck" }]}
193
+ options=${[...decks.map((d) => ({ label: d.name, note: [t("count.cards", { count: d.cards }), languagesNote(d), d.tour && t("decks.tour"), d.name === current && t("decks.now")].filter(Boolean).join(" · ") })), { label: t("decks.newDeck") }]}
37
194
  selected=${picked}
38
195
  onMove=${setPicked}
39
196
  onPick=${(i) => (i === decks.length ? onNew() : onPick(decks[i].name))}
@@ -41,9 +198,10 @@ export function Decks({ current, actions, onPick, onNew, onClose }) {
41
198
  />
42
199
  <//>
43
200
  `}
201
+ ${message && html`<${Box} marginTop=${1}><${Text} color=${theme.good}>${message}<//><//>`}
44
202
  ${error && html`<${Box} marginTop=${1}><${Text} color=${theme.bad}>${error}<//><//>`}
45
203
  <//>
46
- <${Box} paddingX=${1}><${KeyHints} text=${`${CHOICE_KEYS} · esc back`} /><//>
204
+ <${Box} paddingX=${1}><${KeyHints} text=${decks?.[picked] && !decks[picked].tour ? t("keyHints.decks", { choose: choiceHints() }) : choiceHints()} /><//>
47
205
  <//>
48
206
  `;
49
207
  }
package/src/ui/DieRoll.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { t } from "../i18n.js";
1
2
  import React, { Fragment, useEffect, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { ELEMENTS } from "../progress.js";
4
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
3
+ import { Box, useInput } from "ink";
4
+ import { elementName, ELEMENTS } from "../progress.js";
5
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
5
6
  import { ELEMENT_COLOR, Mascot } from "./Mascot.js";
6
7
 
7
8
  const FRAME_MS = 80;
@@ -16,7 +17,6 @@ const FACES = {
16
17
  5: ["tl", "tr", "c", "bl", "br"],
17
18
  6: ["tl", "tr", "ml", "mr", "bl", "br"]
18
19
  };
19
- const ELEMENT_NAME = { earth: "Earth", wind: "Wind", water: "Water", ice: "Ice", fire: "Fire", cosmos: "Cosmos" };
20
20
 
21
21
  // timeline, in frames: tumbling (faces change, slower and slower, bouncing lower) → landed → the dragon changes
22
22
  const LAND_AT = 30;
@@ -78,7 +78,7 @@ export function DieRoll({ element, stage = 0, onClose, play = () => {} }) {
78
78
  return html`
79
79
  <${Fragment}>
80
80
  <${Box} flexDirection="column" borderStyle="round" borderColor=${landed ? color : theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
81
- <${Text} bold color=${theme.warn}>Dragon's die<//>
81
+ <${Text} bold color=${theme.warn}>${t("die.title")}<//>
82
82
  <${Box} marginTop=${1} alignItems="flex-end">
83
83
  <${Box} flexDirection="column" marginBottom=${bounce} marginRight=${4}>
84
84
  <${BigGrid} grid=${dieGrid(face, landed ? color : "#2a2440")} />
@@ -91,14 +91,14 @@ export function DieRoll({ element, stage = 0, onClose, play = () => {} }) {
91
91
  ${revealed
92
92
  ? html`
93
93
  <${Fragment}>
94
- <${Text} bold color=${color}>${result} · ${ELEMENT_NAME[element]}<//>
95
- <${Text} dimColor>Your dragon awakened the power of ${element}. It's yours for good.<//>
94
+ <${Text} bold color=${color}>${t("die.result", { face: result, element: elementName(element) })}<//>
95
+ <${Text} dimColor>${t("die.awakened", { element: elementName(element) })}<//>
96
96
  <//>
97
97
  `
98
- : html`<${Text} dimColor>${landed ? `${result} · ${ELEMENT_NAME[element]}` : "the die is rolling…"}<//>`}
98
+ : html`<${Text} dimColor>${landed ? t("die.result", { face: result, element: elementName(element) }) : t("die.rolling")}<//>`}
99
99
  <//>
100
100
  <//>
101
- <${Box} paddingX=${1}><${KeyHints} text=${revealed ? "any key to continue" : "any key to skip"} /><//>
101
+ <${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "die.keysContinue" : "die.keysSkip")} /><//>
102
102
  <//>
103
103
  `;
104
104
  }
@@ -1,6 +1,7 @@
1
+ import { t } from "../i18n.js";
1
2
  import { Fragment, useEffect, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
3
+ import { Box, useInput } from "ink";
4
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
4
5
  import { Mascot } from "./Mascot.js";
5
6
 
6
7
  const FRAME_MS = 120;
@@ -8,7 +9,6 @@ const FLASH_FROM = 6; // frames 0..5: the old form, wondering
8
9
  const REVEAL_AT = 16; // frames 6..15: white-out flashing, then the new form
9
10
  const SPARKS = ["✦", "·", "✧", "*"];
10
11
 
11
- const article = (name) => (/^[aeiou]/i.test(name) ? "an" : "a");
12
12
 
13
13
  // a loose ring of sparkles around the sprite; which ones show varies per frame
14
14
  function sparkleRow(frame, seed, width) {
@@ -41,7 +41,7 @@ export function Evolution({ from, to, name, element = null, onClose }) {
41
41
  return html`
42
42
  <${Fragment}>
43
43
  <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
44
- <${Text} bold color=${theme.warn}>✦ Evolution ✦<//>
44
+ <${Text} bold color=${theme.warn}>✦ ${t("evolution.title")} ✦<//>
45
45
  <${Box} flexDirection="column" marginTop=${1} alignItems="center">
46
46
  <${Text} color=${theme.warn}>${sparks ? sparkleRow(frame, 1, 30) : " "}<//>
47
47
  <${Mascot} stage=${stage} face=${revealed ? "happy" : "idle"} flash=${flashing && frame % 2 === 0} scale=${2} element=${element} />
@@ -49,11 +49,11 @@ export function Evolution({ from, to, name, element = null, onClose }) {
49
49
  <//>
50
50
  <${Box} marginTop=${1} flexDirection="column" alignItems="center">
51
51
  ${revealed
52
- ? html`<${Text} bold color=${theme.accent}>Your companion evolved into ${article(name)} ${name}!<//>`
53
- : html`<${Text} dimColor>Something is happening…<//>`}
52
+ ? html`<${Text} bold color=${theme.accent}>${t("evolution.evolved", { name })}<//>`
53
+ : html`<${Text} dimColor>${t("evolution.happening")}<//>`}
54
54
  <//>
55
55
  <//>
56
- <${Box} paddingX=${1}><${KeyHints} text=${revealed ? "enter continue" : "any key to hurry it up"} /><//>
56
+ <${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "evolution.keysContinue" : "evolution.keysHurry")} /><//>
57
57
  <//>
58
58
  `;
59
59
  }
package/src/ui/Hatch.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { t } from "../i18n.js";
1
2
  import React, { Fragment, useEffect, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
3
+ import { Box, useInput } from "ink";
4
+ import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
4
5
  import { Mascot } from "./Mascot.js";
5
6
 
6
7
  const FRAME_MS = 110;
@@ -72,7 +73,7 @@ export function Hatch({ onDone, play = () => {} }) {
72
73
  useInput(() => (revealed ? onDone() : setFrame(REVEAL_AT)));
73
74
 
74
75
  const flashing = frame >= FLASH_AT && !revealed;
75
- const caption = revealed ? "" : frame >= CRACK_AT[0] ? "it's hatching…" : "something stirs inside…";
76
+ const caption = revealed ? "" : t(frame >= CRACK_AT[0] ? "hatch.hatching" : "hatch.stirs");
76
77
 
77
78
  return html`
78
79
  <${Fragment}>
@@ -87,14 +88,14 @@ export function Hatch({ onDone, play = () => {} }) {
87
88
  ${revealed
88
89
  ? html`
89
90
  <${Fragment}>
90
- <${Text} bold color=${theme.good}>Your dragon has hatched!<//>
91
- <${Text} dimColor>Answer cards to keep it happy. It grows with your streak.<//>
91
+ <${Text} bold color=${theme.good}>${t("hatch.hatched")}<//>
92
+ <${Text} dimColor>${t("hatch.line")}<//>
92
93
  <//>
93
94
  `
94
95
  : html`<${Text} dimColor>${caption}<//>`}
95
96
  <//>
96
97
  <//>
97
- <${Box} paddingX=${1}><${KeyHints} text=${revealed ? "any key to start" : "any key to skip"} /><//>
98
+ <${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "hatch.keysStart" : "hatch.keysSkip")} /><//>
98
99
  <//>
99
100
  `;
100
101
  }
package/src/ui/Header.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { useEffect, useState } from "react";
2
- import { Box, Text } from "ink";
2
+ import { t } from "../i18n.js";
3
+ import { Box, useStdout } from "ink";
3
4
  import { formatInterval } from "../settings.js";
4
5
  import { formatDay } from "../vacation.js";
5
- import { AnimatedBar, html, theme } from "./kit.js";
6
+ import { AnimatedBar, cellWidth, cutToWidth, html, Text, theme } from "./kit.js";
6
7
  import { Flame } from "./icons.js";
7
8
  import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
8
9
 
@@ -77,11 +78,52 @@ export function Snore({ tick }) {
77
78
  `;
78
79
  }
79
80
 
80
- export function Header({ deck, everyMs, wordCount, stats, combo, face, event, tick = 0, asleep = false }) {
81
+ // "Polish · 50 cards · every 10 min", shortened from the end in a narrow pane: the interval goes
82
+ // first, then the card count, and only then is the deck's name cut. A study session has no interval.
83
+ function deckLine({ deck, wordCount, pace, room }) {
84
+ const cards = wordCount ? t("header.cards", { cards: t("count.cards", { count: wordCount }) }) : "";
85
+ const tries = [pace && t("header.deckLine", { deck, cards, interval: pace }), ` ${deck}${cards}`, ` ${deck}`].filter(Boolean);
86
+ return tries.find((line) => cellWidth(line) <= room) ?? ` ${cutToWidth(deck, Math.max(4, room - 2))}`;
87
+ }
88
+
89
+ // The extras that fit beside what a row always shows, most important first: `[[name, text], …]` → Set of names
90
+ function fitting(base, extras, room) {
91
+ let used = base;
92
+ const shown = new Set();
93
+ for (const [name, text] of extras) {
94
+ if (!text) continue;
95
+ if (used + cellWidth(text) > room) break; // a smaller extra never jumps the queue
96
+ used += cellWidth(text);
97
+ shown.add(name);
98
+ }
99
+ return shown;
100
+ }
101
+
102
+ const BAR_WIDTH = 12;
103
+ const MIN_BAR_WIDTH = 4;
104
+
105
+ export function Header({ deck, everyMs, rhythm = "minutes", wordCount, stats, combo, face, event, tick = 0, asleep = false }) {
106
+ const { stdout } = useStdout();
107
+ const rowRoom = (stdout?.columns || 80) - MASCOT_WIDTH - 3 - 2;
108
+ const room = rowRoom - "Dracosh".length;
109
+ const pace = rhythm === "minutes" ? formatInterval(everyMs) : null;
81
110
  const { streak, today, goal, companion } = stats;
82
111
  const move = useMove(event);
83
112
  const blinking = useBlink();
84
113
  const hot = combo >= 3 && !asleep;
114
+ // a narrow pane keeps the streak and today's count; the extras beside them go when they don't fit
115
+ const streakText = streak.days > 0 ? t("header.streak", { count: streak.days }) : t("header.noStreak");
116
+ const second = fitting(cellWidth(streakText) + (streak.days > 0 ? 1 : 0), [
117
+ ["atRisk", streak.atRisk && t("header.atRisk")],
118
+ ["daysOff", stats.vacation.activeUntil && t("header.daysOffUntil", { day: formatDay(stats.vacation.activeUntil) })],
119
+ ["freezes", streak.freezes > 0 && t("header.freezes", { count: streak.freezes })]
120
+ ], rowRoom);
121
+ const count = ` ${Math.min(today.correct, goal)}/${goal}`;
122
+ const barWidth = Math.min(BAR_WIDTH, rowRoom - cellWidth(t("header.today")) - cellWidth(count));
123
+ const third = fitting(cellWidth(t("header.today")) + Math.max(0, barWidth) + cellWidth(count), [
124
+ ["combo", combo >= 2 && t("header.combo", { count: combo })],
125
+ ["goal", today.goalMet && t("header.goalReached")]
126
+ ], rowRoom);
85
127
  const shown = asleep ? "sleep" : blinking && BLINKABLE.has(face) ? "blink" : face;
86
128
  return html`
87
129
  <${Box} paddingX=${1}>
@@ -94,22 +136,22 @@ export function Header({ deck, everyMs, wordCount, stats, combo, face, event, ti
94
136
  <${Box} flexDirection="column" justifyContent="center">
95
137
  <${Box}>
96
138
  <${Box} flexShrink=${0}><${Text} bold color=${theme.accent}>Dracosh<//><//>
97
- <${Text} dimColor wrap="truncate-end"> ${deck}${wordCount ? ` · ${wordCount} card${wordCount === 1 ? "" : "s"}` : ""} · every ${formatInterval(everyMs)}<//>
139
+ <${Text} dimColor wrap="truncate-end">${deckLine({ deck, wordCount, pace, room })}<//>
98
140
  <//>
99
- <${Box}>
141
+ <${Box} height=${1} overflow="hidden">
100
142
  ${streak.days > 0
101
- ? html`<${Box}><${Flame} /><${Text} color=${theme.warn} bold> ${streak.days}-day streak<//><//>`
102
- : html`<${Text} dimColor>no streak yet<//>`}
103
- ${streak.atRisk && html`<${Text} color=${theme.warn}> · at risk today<//>`}
104
- ${stats.vacation.activeUntil && html`<${Text} color=${theme.accent}> · days off until ${formatDay(stats.vacation.activeUntil)}<//>`}
105
- ${streak.freezes > 0 && html`<${Text} dimColor> · ${streak.freezes} freeze${streak.freezes > 1 ? "s" : ""}<//>`}
143
+ ? html`<${Box}><${Flame} /><${Text} color=${theme.warn} bold wrap="truncate-end">${streakText}<//><//>`
144
+ : html`<${Text} dimColor wrap="truncate-end">${streakText}<//>`}
145
+ ${second.has("atRisk") && html`<${Text} color=${theme.warn}>${t("header.atRisk")}<//>`}
146
+ ${second.has("daysOff") && html`<${Text} color=${theme.accent}>${t("header.daysOffUntil", { day: formatDay(stats.vacation.activeUntil) })}<//>`}
147
+ ${second.has("freezes") && html`<${Text} dimColor>${t("header.freezes", { count: streak.freezes })}<//>`}
106
148
  <//>
107
- <${Box}>
108
- <${Text} dimColor>today <//>
109
- <${AnimatedBar} value=${today.correct} max=${goal} width=${12} color=${today.goalMet ? theme.good : theme.accent} />
110
- <${Text} dimColor> ${Math.min(today.correct, goal)}/${goal}<//>
111
- ${today.goalMet && html`<${Text} color=${theme.good}> goal reached<//>`}
112
- ${combo >= 2 && html`<${Text} color=${theme.warn} bold> combo ×${combo}<//>`}
149
+ <${Box} height=${1} overflow="hidden">
150
+ <${Text} dimColor>${t("header.today")}<//>
151
+ ${barWidth >= MIN_BAR_WIDTH && html`<${AnimatedBar} value=${today.correct} max=${goal} width=${barWidth} color=${today.goalMet ? theme.good : theme.accent} />`}
152
+ <${Text} dimColor>${count}<//>
153
+ ${third.has("goal") && html`<${Text} color=${theme.good}>${t("header.goalReached")}<//>`}
154
+ ${third.has("combo") && html`<${Text} color=${theme.warn} bold>${t("header.combo", { count: combo })}<//>`}
113
155
  <//>
114
156
  <//>
115
157
  <//>