dracosh 0.2.0 → 0.3.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 (55) hide show
  1. package/README.md +16 -11
  2. package/locales/de.json +1046 -0
  3. package/locales/en.json +1029 -0
  4. package/locales/fr.json +1094 -0
  5. package/locales/pl.json +1117 -0
  6. package/locales/uk.json +1118 -0
  7. package/package.json +2 -2
  8. package/src/alerts.js +3 -1
  9. package/src/backup.js +2 -1
  10. package/src/cardline.js +71 -0
  11. package/src/cli.js +39 -52
  12. package/src/commands.js +14 -12
  13. package/src/demo.js +11 -0
  14. package/src/diff.js +13 -7
  15. package/src/i18n.js +68 -0
  16. package/src/judge.js +24 -6
  17. package/src/library.js +62 -35
  18. package/src/lock.js +2 -1
  19. package/src/manage.js +150 -60
  20. package/src/pause.js +1 -2
  21. package/src/progress.js +76 -59
  22. package/src/quiet.js +3 -2
  23. package/src/scheduler.js +3 -6
  24. package/src/session.js +69 -19
  25. package/src/settings.js +13 -6
  26. package/src/starter.js +36 -27
  27. package/src/store.js +9 -7
  28. package/src/tips.js +12 -3
  29. package/src/ui/AddCard.js +405 -81
  30. package/src/ui/AnswerInput.js +22 -10
  31. package/src/ui/App.js +181 -50
  32. package/src/ui/BadgeUnlock.js +4 -3
  33. package/src/ui/Badges.js +9 -8
  34. package/src/ui/Choice.js +14 -9
  35. package/src/ui/Companion.js +13 -13
  36. package/src/ui/Confetti.js +2 -2
  37. package/src/ui/Decks.js +58 -8
  38. package/src/ui/DieRoll.js +9 -9
  39. package/src/ui/Evolution.js +7 -7
  40. package/src/ui/Hatch.js +7 -6
  41. package/src/ui/Header.js +58 -16
  42. package/src/ui/Help.js +31 -25
  43. package/src/ui/Mascot.js +1 -2
  44. package/src/ui/Missed.js +13 -12
  45. package/src/ui/Preview.js +48 -29
  46. package/src/ui/Reset.js +13 -14
  47. package/src/ui/Settings.js +26 -19
  48. package/src/ui/Stats.js +24 -23
  49. package/src/ui/Summary.js +10 -9
  50. package/src/ui/TheOne.js +7 -6
  51. package/src/ui/icons.js +1 -2
  52. package/src/ui/kit.js +34 -6
  53. package/src/vacation.js +2 -1
  54. package/src/words.js +2 -1
  55. package/data/tips.json +0 -32
@@ -1,7 +1,8 @@
1
+ import { t } from "../i18n.js";
1
2
  import { useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
+ import { Box, useInput, usePaste } from "ink";
3
4
  import { COMMANDS, matchCommands } from "../commands.js";
4
- import { html, theme } from "./kit.js";
5
+ import { html, Text, theme } from "./kit.js";
5
6
 
6
7
  function Palette({ matches, selected }) {
7
8
  return html`
@@ -9,7 +10,7 @@ function Palette({ matches, selected }) {
9
10
  ${matches.map(
10
11
  (command, i) => html`
11
12
  <${Box} key=${command.name}>
12
- <${Text} color=${i === selected ? theme.accent : undefined} bold=${i === selected} dimColor=${i !== selected}>${i === selected ? "❯" : " "} ${command.name.padEnd(12)}<//>
13
+ <${Box} flexShrink=${0}><${Text} color=${i === selected ? theme.accent : undefined} bold=${i === selected} dimColor=${i !== selected}>${i === selected ? "❯" : " "} ${command.name.padEnd(12)}<//><//>
13
14
  <${Text} dimColor>${command.hint}<//>
14
15
  <//>
15
16
  `
@@ -25,7 +26,9 @@ const args = (value) => value.trim().split(/\s+/).slice(1).join(" ");
25
26
  // ↑/↓ choose, Tab completes, Enter runs.
26
27
  // `commandOnly` is the between-questions variant: it starts at "/" and Esc or erasing the "/" closes it.
27
28
  // `plain` is a text field with no commands at all ("and/or" is just text there).
28
- export function AnswerInput({ onSubmit, onCommand, onExit, onEdit, onCancel, commands = COMMANDS, initial = "", commandOnly = false, plain = false }) {
29
+ // `onChange` hears every edit; `onRecall` is ↑ on an empty plain field (/add brings back the last card);
30
+ // `onPaste` takes a paste of several lines (/add reviews them as cards), anything else is typed in.
31
+ export function AnswerInput({ onSubmit, onCommand, onExit, onEdit, onCancel, onChange, onRecall, onPaste, commands = COMMANDS, initial = "", commandOnly = false, plain = false }) {
29
32
  const [value, setValue] = useState(initial);
30
33
  const [cursor, setCursor] = useState(initial.length);
31
34
  const [selected, setSelected] = useState(0);
@@ -38,8 +41,18 @@ export function AnswerInput({ onSubmit, onCommand, onExit, onEdit, onCancel, com
38
41
  setCursor(Math.max(0, Math.min(at, next.length)));
39
42
  setSelected(0);
40
43
  onEdit?.();
44
+ onChange?.(next);
41
45
  };
42
46
 
47
+ // pasted text arrives whole (bracketed paste); lines become spaces unless /add takes them as cards
48
+ const paste = (text) => {
49
+ const lines = /[\r\n]/.test(text) ? text.split(/\r\n|\r|\n/).filter((line) => line.trim()) : [text];
50
+ if (onPaste && lines.length > 1) return onPaste(lines);
51
+ const typed = lines.join(" ");
52
+ edit(value.slice(0, cursor) + typed + value.slice(cursor), cursor + typed.length);
53
+ };
54
+ usePaste(paste);
55
+
43
56
  useInput((input, key) => {
44
57
  if (key.escape) return commandOnly ? onCancel() : value ? edit("") : onExit();
45
58
  if (key.return) {
@@ -50,6 +63,7 @@ export function AnswerInput({ onSubmit, onCommand, onExit, onEdit, onCancel, com
50
63
  return onCommand(matches[pick]?.name ?? token, rest.join(" "));
51
64
  }
52
65
  if (key.tab) return matches.length ? edit(`${matches[pick].name}${args(value) ? ` ${args(value)}` : ""}`) : undefined;
66
+ if (key.upArrow && !value && onRecall) return onRecall();
53
67
  if (key.upArrow) return setSelected(Math.max(0, pick - 1));
54
68
  if (key.downArrow) return setSelected(Math.min(matches.length - 1, pick + 1));
55
69
  if (key.leftArrow) return setCursor((c) => Math.max(0, c - 1));
@@ -63,10 +77,8 @@ export function AnswerInput({ onSubmit, onCommand, onExit, onEdit, onCancel, com
63
77
  if (key.ctrl && input === "a") return setCursor(0);
64
78
  if (key.ctrl && input === "e") return setCursor(value.length);
65
79
  if (key.ctrl || key.meta || key.pageUp || key.pageDown) return;
66
- if (input) {
67
- const typed = input.replace(/[\r\n]+/g, " ");
68
- edit(value.slice(0, cursor) + typed + value.slice(cursor), cursor + typed.length);
69
- }
80
+ // a terminal without bracketed paste sends a paste as typed text, line breaks and all
81
+ if (input) paste(input);
70
82
  });
71
83
 
72
84
  const before = value.slice(0, cursor);
@@ -75,11 +87,11 @@ export function AnswerInput({ onSubmit, onCommand, onExit, onEdit, onCancel, com
75
87
  return html`
76
88
  <${Box} flexDirection="column">
77
89
  <${Box}>
78
- <${Text} color=${theme.accent}>❯ <//>
90
+ <${Box} flexShrink=${0}><${Text} color=${theme.accent}>❯ <//><//>
79
91
  <${Text}>${before}<${Text} inverse>${at}<//>${after}<//>
80
92
  <//>
81
93
  ${matches.length > 0 && html`<${Palette} matches=${matches} selected=${pick} />`}
82
- ${isCommand && matches.length === 0 && html`<${Box} marginTop=${1}>${commandOnly ? html`<${Text} color=${theme.bad}>unknown command<//>` : html`<${Text} dimColor>no command like that · enter sends it as your answer<//>`}<//>`}
94
+ ${isCommand && matches.length === 0 && html`<${Box} marginTop=${1}>${commandOnly ? html`<${Text} color=${theme.bad}>${t("input.unknownCommand")}<//>` : html`<${Text} dimColor>${t("input.notACommand")}<//>`}<//>`}
83
95
  <//>
84
96
  `;
85
97
  }
package/src/ui/App.js CHANGED
@@ -1,16 +1,18 @@
1
1
  import { Fragment, useCallback, useEffect, useRef, useState } from "react";
2
- import { Box, Text, useApp, useInput, useStdout } from "ink";
2
+ import { Box, useApp, useInput, useStdout } from "ink";
3
3
  import { commandsFor } from "../commands.js";
4
- import { diffChars } from "../diff.js";
4
+ import { accentMarks, diffChars } from "../diff.js";
5
5
  import { AnswerInput } from "./AnswerInput.js";
6
6
  import { Header } from "./Header.js";
7
- import { Bar, cellWidth, cutToWidth, html, KeyHints, Marked, theme, Typewriter, usePanelWidth } from "./kit.js";
7
+ import { setLanguage, t } from "../i18n.js";
8
+ import { Bar, cellWidth, cutToWidth, html, KeyHints, Marked, Text, theme, Typewriter, usePanelWidth } from "./kit.js";
8
9
  import { hintTarget, makeHint } from "../hint.js";
9
10
  import { formatClock, inQuietHours, quietEnd } from "../quiet.js";
10
11
  import { startOfTomorrow } from "../scheduler.js";
11
12
  import { formatDay } from "../vacation.js";
12
13
  import { dayKey } from "../dates.js";
13
14
  import { shouldShowTip } from "../tips.js";
15
+ import { sessionLength } from "../settings.js";
14
16
  import { Badges } from "./Badges.js";
15
17
  import { Companion } from "./Companion.js";
16
18
  import { Confetti } from "./Confetti.js";
@@ -32,6 +34,7 @@ const SPINNER = ["⠚", "⠓", "⠋", "⠙"]; // the old braille dots on a 2×2
32
34
  const TICK_MS = 250; // the steady redraw: slow enough to stay idle for hours, fast enough for the spinner
33
35
  const SLEEP_AFTER_MS = 3 * 60_000; // no key pressed for this long while waiting → the dragon dozes off
34
36
  const PAUSED_SLEEP_AFTER_MS = 15_000; // during a pause or quiet hours it nods off again much sooner
37
+ const SETTLE_MS = 400; // keys right after a card appears or its answer is revealed are a double press, not a choice
35
38
  const CHEER_STYLE = {
36
39
  goal: { icon: "▪", color: theme.good },
37
40
  evolve: { icon: "▴", color: theme.accent },
@@ -49,31 +52,57 @@ function AnswerDiff({ given, closest }) {
49
52
  const parts = diffChars(given, closest);
50
53
  return html`
51
54
  <${Text}>
52
- <${Text} dimColor>you wrote <//>
55
+ <${Text} dimColor>${t("quiz.youWrote")}<//>
53
56
  ${parts.map((p, i) => html`<${Text} key=${i} color=${p.ok ? theme.good : theme.text} underline=${!p.ok}>${p.ch}<//>`)}
54
57
  <//>
55
58
  `;
56
59
  }
57
60
 
61
+ // the right answers after one written without its accents, the letters you wrote plain underlined: jabłko
62
+ function AccentedAnswers({ expected, given, closest }) {
63
+ return expected.map((answer, i) => {
64
+ const marks = answer === closest ? accentMarks(given, answer) : null;
65
+ return html`
66
+ <${Text} key=${i}>
67
+ ${i > 0 ? " / " : ""}${marks ? marks.map((p, k) => html`<${Text} key=${k} underline=${!p.ok}>${p.ch}<//>`) : answer}
68
+ <//>
69
+ `;
70
+ });
71
+ }
72
+
58
73
  function Verdict({ outcome, question }) {
59
74
  const wrong = outcome.result === "wrong";
60
75
  const showDiff = outcome.closest && outcome.given && !outcome.overruled && (wrong || outcome.result === "typo");
61
76
  return html`
62
77
  <${Box} flexDirection="column">
63
- <${Text} color=${wrong ? theme.bad : theme.good} bold>${wrong ? "✗" : "✓"} ${question.expected.join(", ")}${outcome.result === "typo" ? " (close enough)" : ""}<//>
78
+ <${Text} color=${wrong ? theme.bad : theme.good} bold>${wrong ? "✗" : "✓"} ${outcome.result === "accent" ? html`<${AccentedAnswers} expected=${question.expected} given=${outcome.given} closest=${outcome.closest} />` : question.expected.join(" / ")}${outcome.result === "typo" ? t("quiz.closeEnough") : ""}<//>
64
79
  ${showDiff && html`<${AnswerDiff} given=${outcome.given} closest=${outcome.closest} />`}
65
80
  ${question.word.example && html`<${Box} marginTop=${1}>${question.tour ? html`<${Marked} dimColor text=${question.word.example} />` : html`<${Text} dimColor italic>“${question.word.example}”<//>`}<//>`}
66
81
  ${(outcome.hinted || outcome.overruled) &&
67
82
  html`
68
83
  <${Box} marginTop=${1} flexDirection="column">
69
- ${outcome.hinted && html`<${Text} dimColor>hint used · the card stays in its box<//>`}
70
- ${outcome.overruled && html`<${Text} color=${theme.good}>counted as correct${question.tour ? "" : ` · "${outcome.accepted}" is accepted from now on`}<//>`}
84
+ ${outcome.hinted && html`<${Text} dimColor>${t("quiz.hintUsed")}<//>`}
85
+ ${outcome.overruled && html`<${Text} color=${theme.good}>${t("quiz.countedCorrect")}${question.tour ? "" : t("quiz.acceptedFromNow", { answer: outcome.accepted })}<//>`}
71
86
  <//>
72
87
  `}
73
88
  <//>
74
89
  `;
75
90
  }
76
91
 
92
+ // the answer shown after an empty Enter, and the question that follows: did you know it?
93
+ function Revealed({ question, nudge }) {
94
+ return html`
95
+ <${Box} flexDirection="column">
96
+ <${Text} color=${theme.accent} bold>${question.expected.join(" / ")}<//>
97
+ ${question.word.example && html`<${Box} marginTop=${1}>${question.tour ? html`<${Marked} dimColor text=${question.word.example} />` : html`<${Text} dimColor italic>“${question.word.example}”<//>`}<//>`}
98
+ <${Box} marginTop=${1}>
99
+ <${Text} bold>${t("quiz.didYouKnow")} <//>
100
+ <${Text} color=${nudge ? theme.warn : theme.text} bold=${nudge}>${t("quiz.gradeKeys")}<//>
101
+ <//>
102
+ <//>
103
+ `;
104
+ }
105
+
77
106
  const BADGE_FIRST_MS = 400; // after the answer's own sound
78
107
  const BADGE_STAGGER_MS = 700; // several badges at once light up one after another
79
108
 
@@ -109,21 +138,21 @@ function CardTop({ label, width, color }) {
109
138
  // "at 14:30", "tomorrow", "on 14 Oct"
110
139
  function whenDue(at, now) {
111
140
  const tomorrow = startOfTomorrow(now);
112
- if (at < tomorrow) return `at ${formatClock(at)}`;
113
- return at < startOfTomorrow(tomorrow) ? "tomorrow" : `on ${formatDay(dayKey(at))}`;
141
+ if (at < tomorrow) return t("quiz.when.at", { time: formatClock(at) });
142
+ return at < startOfTomorrow(tomorrow) ? t("quiz.when.tomorrow") : t("quiz.when.on", { day: formatDay(dayKey(at)) });
114
143
  }
115
144
 
116
145
  // what the quiz shows when the deck has nothing to ask: no countdown, just the way on
117
146
  function EmptyDeck({ deck, tour, count, nextDue, dayDone, now, width }) {
118
147
  const [title, next] = tour
119
- ? ["You've finished the tour.", "Now make it yours: type /add to start your own deck."]
148
+ ? [t("quiz.empty.tourTitle"), t("quiz.empty.tourNext")]
120
149
  : !count
121
- ? [`"${deck}" has no cards yet.`, "Type /add to add the first one."]
150
+ ? [t("quiz.empty.noCardsTitle", { deck }), t("quiz.empty.noCardsNext")]
122
151
  : nextDue >= startOfTomorrow(now) && !dayDone
123
- ? [`Nothing more in "${deck}" today.`, `Its cards come back ${whenDue(nextDue, now)}. Other decks still have cards: /decks`]
152
+ ? [t("quiz.empty.deckDoneTitle", { deck }), t("quiz.empty.deckDoneNext", { when: whenDue(nextDue, now) })]
124
153
  : nextDue >= startOfTomorrow(now)
125
- ? ["All done for today.", `Your cards come back ${whenDue(nextDue, now)}. Want more today? /add some new ones.`]
126
- : ["Nothing to practise right now.", `The next card is due ${whenDue(nextDue, now)}. It will come by itself.`];
154
+ ? [t("quiz.empty.dayDoneTitle"), t("quiz.empty.dayDoneNext", { when: whenDue(nextDue, now) })]
155
+ : [t("quiz.empty.laterTitle"), t("quiz.empty.laterNext", { when: whenDue(nextDue, now) })];
127
156
  return html`
128
157
  <${Box} flexDirection="column" width=${width}>
129
158
  <${CardTop} label=${deck} width=${width} color=${theme.accent} />
@@ -138,7 +167,7 @@ function EmptyDeck({ deck, tour, count, nextDue, dayDone, now, width }) {
138
167
  function TipBox({ tip, width }) {
139
168
  return html`
140
169
  <${Box} flexDirection="column" paddingX=${1} marginTop=${2} width=${width}>
141
- <${Box} marginBottom=${1}><${Text} color=${theme.accent}>tip · ${tip.cat}<//><//>
170
+ <${Box} marginBottom=${1}><${Text} color=${theme.accent}>${t("quiz.tip", { cat: tip.cat })}<//><//>
142
171
  <${Typewriter} text=${tip.text} dimColor />
143
172
  <//>
144
173
  `;
@@ -158,7 +187,9 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
158
187
  // quiz | settings | reset | add | decks | stats | badges | companion | help | missed | evolve | the-one | die | summary | hatch
159
188
  const [screen, setScreen] = useState(() => (session.isFirstRun() ? "hatch" : "quiz"));
160
189
  const [tip, setTip] = useState(null);
161
- const [phase, setPhase] = useState("loading"); // loading | asking | waiting | empty
190
+ const [phase, setPhase] = useState("loading"); // loading | asking | grading (answer revealed) | waiting | empty
191
+ const [nudge, setNudge] = useState(false); // Enter while grading: the 1/2 keys light up
192
+ const [confirming, setConfirming] = useState(false); // /correct waits for yes or no
162
193
  const [question, setQuestion] = useState(null);
163
194
  const [outcome, setOutcome] = useState(null);
164
195
  const [problem, setProblem] = useState("");
@@ -175,9 +206,15 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
175
206
  const [ceremonies, setCeremonies] = useState([]); // full-screen moments still to show: "evolve", "the-one"
176
207
  const [lastActive, setLastActive] = useState(Date.now()); // last key press or new question: the dragon sleeps after a long gap
177
208
  const busy = useRef(false);
209
+ const shownAt = useRef(0); // when the card or its revealed answer appeared (SETTLE_MS)
210
+ const sessionDone = useRef(0); // cards answered in this study session (the "session" rhythm)
211
+ const [sessionWait, setSessionWait] = useState(false); // waiting for Enter, not for the clock
178
212
  const asleepRef = useRef(false);
179
213
  const bestCombo = useRef(0);
180
214
  const settingsRef = useRef(settings);
215
+ const tourSync = useRef(Promise.resolve());
216
+ const deckRef = useRef(deck);
217
+ deckRef.current = deck;
181
218
  settingsRef.current = settings;
182
219
  const snoozeRef = useRef(0);
183
220
  snoozeRef.current = snoozeUntil;
@@ -188,10 +225,14 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
188
225
  return Math.max(snoozeRef.current > t ? snoozeRef.current : 0, inQuietHours(t, quiet) ? quietEnd(t, quiet) : 0);
189
226
  };
190
227
 
191
- // `nextDue`: nothing is waiting until then, so the next question waits for it (never sooner than usual)
228
+ // `nextDue`: nothing is waiting until then, so the next question waits for it (never sooner than usual).
229
+ // In a study session Enter asks the next card instead of the clock, until the set number is done.
192
230
  const waitForNext = useCallback((nextDue = null) => {
193
231
  const usual = Date.now() + settingsRef.current.everyMs;
194
- setNextAt(nextDue ? Math.max(nextDue, usual) : usual);
232
+ const length = sessionLength(settingsRef.current.rhythm);
233
+ const studying = settingsRef.current.rhythm !== "minutes" && !nextDue && (length === null || sessionDone.current < length);
234
+ setSessionWait(studying);
235
+ setNextAt(studying ? Infinity : nextDue ? Math.max(nextDue, usual) : usual);
195
236
  setRestUntil(nextDue);
196
237
  setPhase("waiting");
197
238
  setTip(!session.inTour() && shouldShowTip(settingsRef.current.tips) ? session.nextTip() : null);
@@ -204,11 +245,13 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
204
245
  setNotice("");
205
246
  setHintLevel(0);
206
247
  setCommandMode(false);
248
+ setConfirming(false);
207
249
  try {
208
250
  const next = await session.next();
209
251
  setQuestion(next);
210
252
  setOutcome(null);
211
253
  setEmpty(null);
254
+ shownAt.current = Date.now();
212
255
  setPhase("asking");
213
256
  } catch (err) {
214
257
  if (!err.empty) {
@@ -235,18 +278,27 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
235
278
 
236
279
  // with nothing to practise, the quiz picks up again by itself once the next card is due
237
280
  useEffect(() => {
238
- if (phase !== "empty" || !empty?.nextDue || screen !== "quiz" || now < empty.nextDue || pauseEnd(now)) return;
281
+ if (phase !== "empty" || !empty?.nextDue || screen !== "quiz" || confirming || now < empty.nextDue || pauseEnd(now)) return;
239
282
  alerts.ask();
240
283
  ask();
241
- }, [now, phase, empty, screen, ask, alerts]);
284
+ }, [now, phase, empty, screen, confirming, ask, alerts]);
242
285
 
243
286
  useEffect(() => {
244
- if (phase !== "waiting" || screen === "summary" || screen === "evolve" || screen === "the-one" || screen === "die") return;
287
+ // a /correct question stays open: the next card waits for its answer
288
+ if (phase !== "waiting" || confirming || screen === "summary" || screen === "evolve" || screen === "the-one" || screen === "die") return;
245
289
  if (now >= nextAt && !pauseEnd(now)) {
246
290
  alerts.ask();
247
291
  ask();
248
292
  }
249
- }, [now, phase, nextAt, screen, ask, alerts]);
293
+ }, [now, phase, nextAt, screen, confirming, ask, alerts]);
294
+
295
+ // Esc on an empty line is easy to press by habit: it quits only when pressed twice in a row
296
+ const escArmed = useRef(0);
297
+ const escapeExit = () => {
298
+ if (Date.now() - escArmed.current < 3000) return requestExit();
299
+ escArmed.current = Date.now();
300
+ setNotice(t("quiz.escAgain"));
301
+ };
250
302
 
251
303
  // quitting goes through the session summary when there is anything to sum up
252
304
  const requestExit = useCallback(() => {
@@ -260,11 +312,29 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
260
312
  setLastActive(Date.now());
261
313
  });
262
314
 
315
+ // the answer is revealed: you say whether you knew it. 1/2 or ←/→ (AZERTY's digits need Shift, so
316
+ // & and é too); Esc is "didn't know"; Enter never grades, it only shows the keys again
263
317
  useInput((input, key) => {
264
- if (screen !== "quiz" || (phase !== "waiting" && phase !== "empty") || commandMode) return;
318
+ if (screen !== "quiz" || phase !== "grading" || asleepRef.current || Date.now() - shownAt.current < SETTLE_MS) return;
319
+ if (input === "1" || input === "&" || key.leftArrow || key.escape) return gradeSelf(false);
320
+ if (input === "2" || input === "é" || key.rightArrow) return gradeSelf(true);
321
+ if (key.return) setNudge(true);
322
+ });
323
+
324
+ useInput((input, key) => {
325
+ // only the yes key accepts: Enter is too easy to press twice after "/correct" from the menu
326
+ if (screen !== "quiz" || !confirming || asleepRef.current) return;
327
+ const is = (keys) => t(keys).split("|").includes(input.toLowerCase());
328
+ if (is("choice.yesKey")) return overrule();
329
+ if (is("choice.noKey") || key.escape) setConfirming(false);
330
+ });
331
+
332
+ useInput((input, key) => {
333
+ if (screen !== "quiz" || (phase !== "waiting" && phase !== "empty") || commandMode || confirming) return;
265
334
  if (input === "/") return setCommandMode(true);
266
- if (key.escape || input === "q") return requestExit();
267
- if (key.return && phase === "waiting") ask();
335
+ if (input === "q") return requestExit();
336
+ if (key.escape) return escapeExit();
337
+ if (key.return && phase === "waiting" && !busy.current) ask();
268
338
  });
269
339
 
270
340
  const clearProblem = useCallback(() => {
@@ -316,8 +386,8 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
316
386
  if (name === "/companion") return setScreen("companion");
317
387
  if (name === "/missed") return setScreen("missed");
318
388
  if (name === "/help") return setScreen("help");
319
- if (name === "/add") return library ? (setAddNew(false), setScreen("add")) : setNotice("The preview can't add cards; run dracosh for that.");
320
- if (name === "/decks") return library ? setScreen("decks") : setNotice("The preview has one demo deck; run dracosh for yours.");
389
+ if (name === "/add") return library ? (setAddNew(false), setScreen("add")) : setNotice(t("quiz.previewNoAdd"));
390
+ if (name === "/decks") return library ? setScreen("decks") : setNotice(t("quiz.previewNoDecks"));
321
391
  if (name === "/hint" && phase === "asking") return setHintLevel((level) => level + 1);
322
392
  if (name === "/pause") {
323
393
  return session
@@ -326,15 +396,23 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
326
396
  if (snooze === "off") setSnoozeUntil(0);
327
397
  if (typeof snooze === "number") {
328
398
  setSnoozeUntil(Date.now() + snooze);
329
- return phase === "asking" ? setNotice(`Paused until ${formatClock(Date.now() + snooze)}`) : undefined; // while waiting, the status line says it
399
+ return phase === "asking" ? setNotice(t("quiz.pausedUntilNotice", { time: formatClock(Date.now() + snooze) })) : undefined; // while waiting, the status line says it
330
400
  }
331
- const paused = list && snoozeRef.current > Date.now() ? `Paused until ${formatClock(snoozeRef.current)}. ` : "";
401
+ const paused = list && snoozeRef.current > Date.now() ? t("quiz.pausedUntilList", { time: formatClock(snoozeRef.current) }) : "";
332
402
  setNotice(paused + message);
333
403
  })
334
404
  .catch((err) => setProblem(err.message));
335
405
  }
336
- if (name === "/correct" && session.canOverrule()) {
337
- return session
406
+ if (name === "/correct" && session.canOverrule()) return setConfirming(true); // asked first: a misclick would accept the answer for good
407
+ setProblem(t("quiz.unknownCommand", { name }));
408
+ }
409
+
410
+ // /correct, confirmed: the last answer counts as right and is accepted from now on
411
+ function overrule() {
412
+ setConfirming(false);
413
+ if (busy.current) return;
414
+ busy.current = true;
415
+ return session
338
416
  .overrule()
339
417
  .then((result) => {
340
418
  setOutcome(result);
@@ -342,9 +420,10 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
342
420
  if (phase === "empty") return ask(); // the card's next date changed: look again
343
421
  waitForNext(result.nextDue);
344
422
  })
345
- .catch((err) => setProblem(`Couldn't save progress: ${err.message}`));
346
- }
347
- setProblem(`Unknown command ${name}`);
423
+ .catch((err) => setProblem(t("quiz.saveFailed", { error: err.message })))
424
+ .finally(() => {
425
+ busy.current = false;
426
+ });
348
427
  }
349
428
 
350
429
  function changeSettings(patch) {
@@ -355,22 +434,65 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
355
434
  alerts.configure({ sound: next.sound, volume: next.volume });
356
435
  persistSettings(patch).catch(() => {});
357
436
  if (patch.everyMs && phase === "waiting") setNextAt((at) => at - previous.everyMs + patch.everyMs);
437
+ if (patch.rhythm) {
438
+ sessionDone.current = 0;
439
+ if (phase === "waiting" && !restUntil) waitForNext(); // the wait follows the new rhythm right away
440
+ }
358
441
  if (patch.volume !== undefined || patch.sound === true) alerts.play("correct-0"); // audible preview
442
+ if (patch.language) changeLanguage(patch.language);
443
+ }
444
+
445
+ // Every text follows at the next render; the tour is translated too, and asked again in the new
446
+ // language. One translation at a time, so flicking through languages ends on the last one.
447
+ function changeLanguage(lang) {
448
+ setLanguage(lang);
449
+ if (!library) return;
450
+ tourSync.current = tourSync.current
451
+ .then(() => library.matchTourLanguage())
452
+ .then((renamed) => {
453
+ if (!renamed) return;
454
+ if (deckRef.current === renamed.from) {
455
+ deckRef.current = renamed.to;
456
+ onSwitchDeck?.(renamed.to);
457
+ setDeck(renamed.to);
458
+ }
459
+ if (phase === "asking" && question?.tour) ask();
460
+ })
461
+ .catch(() => {});
359
462
  }
360
463
 
361
- // an empty answer means "I don't know": the answer is shown and the card counts as missed
464
+ // An empty answer reveals the card, and you grade yourself (gradeSelf). An empty Enter right after the
465
+ // card appeared is the second half of the Enter that asked it: ignored.
362
466
  async function submit(raw) {
363
467
  const text = raw.trim();
468
+ if (busy.current) return;
469
+ if (!text) {
470
+ if (Date.now() - shownAt.current < SETTLE_MS) return;
471
+ session.reveal(question);
472
+ shownAt.current = Date.now();
473
+ setNudge(false);
474
+ return setPhase("grading");
475
+ }
476
+ await settle(() => session.answer(question, text, { hinted: hintLevel > 0 }));
477
+ }
478
+
479
+ const gradeSelf = (knew) => settle(() => session.selfGrade(question, knew, { hinted: hintLevel > 0 }));
480
+
481
+ // a graded answer: the verdict, the celebration, then the wait for the next card
482
+ async function settle(grading) {
364
483
  if (busy.current) return;
365
484
  busy.current = true;
366
485
  let nextDue = null;
367
486
  try {
368
- const result = await session.answer(question, text, { hinted: hintLevel > 0 });
487
+ const result = await grading();
369
488
  nextDue = result.nextDue;
489
+ sessionDone.current += 1;
490
+ const length = sessionLength(settingsRef.current.rhythm);
491
+ if (length !== null && sessionDone.current === length) setNotice(t("quiz.sessionDone", { count: length }));
370
492
  setOutcome(result);
371
493
  celebrate(result);
372
494
  } catch (err) {
373
- setProblem(`Couldn't save progress: ${err.message}`);
495
+ setProblem(t("quiz.saveFailed", { error: err.message }));
374
496
  } finally {
375
497
  busy.current = false;
376
498
  waitForNext(nextDue);
@@ -394,7 +516,7 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
394
516
  setFreshBadges([]);
395
517
  if (scope === "progress") {
396
518
  setScreen("quiz");
397
- return setNotice("Your progress starts over. Your cards are all still here.");
519
+ return setNotice(t("quiz.progressReset"));
398
520
  }
399
521
  const tour = await library.resetLibrary();
400
522
  onSwitchDeck?.(tour);
@@ -406,13 +528,14 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
406
528
 
407
529
  // after /add: a first deck of your own replaces the tour; a deck started from /decks (or in place
408
530
  // of an empty one) becomes the one you practise; new cards end an empty state
409
- function addDone({ deck: started, removed, added, dropped }) {
531
+ function addDone({ deck: started, removed, stale = [], added, dropped }) {
410
532
  setScreen("quiz");
411
533
  if (removed.length) session.forget(removed).catch(() => {});
534
+ if (stale.length) session.forgetKeys(stale).catch(() => {});
412
535
  const switching = started && (removed.length || phase === "empty" || addNew);
413
536
  if (switching) switchDeck(started);
414
537
  else if (phase === "empty" && added) ask();
415
- const notes = [dropped && "The card you were writing wasn't saved.", started && !switching && `"${started}" is ready; you're still practising "${deck}". Switch with /decks.`];
538
+ const notes = [dropped && t("quiz.cardNotSaved"), started && !switching && t("quiz.deckReadyElsewhere", { deck: started, current: deck })];
416
539
  setNotice(notes.filter(Boolean).join(" ")); // after ask(), which clears the notice
417
540
  }
418
541
 
@@ -455,12 +578,15 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
455
578
 
456
579
  return html`
457
580
  <${Box} flexDirection="column" marginY=${1}>
458
- <${Header} deck=${deck} everyMs=${settings.everyMs} wordCount=${question?.wordCount ?? empty?.count} stats=${stats} combo=${session.totals.combo} face=${face} event=${petEvent} tick=${tick} asleep=${asleep} />
581
+ <${Header} deck=${deck} everyMs=${settings.everyMs} rhythm=${settings.rhythm} wordCount=${question?.wordCount ?? empty?.count} stats=${stats} combo=${session.totals.combo} face=${face} event=${petEvent} tick=${tick} asleep=${asleep} />
459
582
  <${Box} marginTop=${1} flexDirection="column">
460
583
  ${screen === "settings" && html`<${Settings} settings=${settings} onChange=${changeSettings} onClose=${() => setScreen("quiz")} onAction=${library ? () => setScreen("reset") : null} />`}
461
584
  ${screen === "reset" && html`<${Reset} stats=${stats} actions=${library} onConfirm=${reset} onClose=${() => setScreen("settings")} />`}
462
585
  ${screen === "add" && html`<${AddCard} current=${deck} actions=${library} onDone=${addDone} startNew=${addNew} />`}
463
- ${screen === "decks" && html`<${Decks} current=${deck} actions=${library} onPick=${switchDeck} onNew=${() => (setAddNew(true), setScreen("add"))} onClose=${() => setScreen("quiz")} />`}
586
+ ${screen === "decks" && html`<${Decks} current=${deck} actions=${library} onDirections=${async (cardIds, directions) => {
587
+ await session.setDirections(cardIds, directions);
588
+ if (phase === "asking" && question && cardIds.includes(question.word.noteId)) ask(); // the open card follows the new way at once
589
+ }} onPick=${switchDeck} onNew=${() => (setAddNew(true), setScreen("add"))} onClose=${() => setScreen("quiz")} />`}
464
590
  ${!["settings", "reset", "add", "decks"].includes(screen) &&
465
591
  html`
466
592
  <${Fragment}>
@@ -470,10 +596,12 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
470
596
  <${CardTop} label=${question.label} width=${width} color=${border} />
471
597
  <${Box} flexDirection="column" borderStyle="round" borderTop=${false} borderColor=${border} paddingX=${2} paddingTop=${1}>
472
598
  <${Marked} bold text=${question.prompt} plain=${!question.tour} />
473
- ${phase === "asking" && hintLevel > 0 && html`<${Text} dimColor>hint ${makeHint(hintTarget(question.expected), hintLevel)}<//>`}
599
+ ${question.context && html`<${Text} dimColor>(${question.context})<//>`}
600
+ ${phase === "asking" && hintLevel > 0 && html`<${Text} dimColor>${t("quiz.hintLabel")} ${makeHint(hintTarget(question.expected), hintLevel)}<//>`}
474
601
  <${Box} marginTop=${1} flexDirection="column">
475
- ${phase === "asking" && html`<${AnswerInput} key=${question.word.noteId + question.direction} onSubmit=${submit} onCommand=${runCommand} onExit=${requestExit} onEdit=${clearProblem} commands=${commandsFor({ phase: "asking" })} />`}
476
- ${phase !== "asking" && outcome && html`<${Verdict} outcome=${outcome} question=${question} />`}
602
+ ${phase === "asking" && html`<${AnswerInput} key=${question.word.noteId + question.direction} onSubmit=${submit} onCommand=${runCommand} onExit=${escapeExit} onEdit=${clearProblem} commands=${commandsFor({ phase: "asking" })} />`}
603
+ ${phase === "grading" && html`<${Revealed} question=${question} nudge=${nudge} />`}
604
+ ${phase !== "asking" && phase !== "grading" && outcome && html`<${Verdict} outcome=${outcome} question=${question} />`}
477
605
  <//>
478
606
  <//>
479
607
  <//>
@@ -484,22 +612,25 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
484
612
  ${phase === "waiting" && tip && html`<${TipBox} tip=${tip} width=${width} />`}
485
613
  <${Box} paddingX=${1} marginTop=${1} flexDirection="column">
486
614
  ${problem && html`<${Text} color=${theme.bad}>${problem}<//>`}
487
- ${phase === "loading" && html`<${Text}><${Text} color=${theme.accent}>${frame}<//><${Text} dimColor> loading…<//><//>`}
615
+ ${phase === "loading" && html`<${Text}><${Text} color=${theme.accent}>${frame}<//><${Text} dimColor>${t("quiz.loading")}<//><//>`}
488
616
  ${notice && html`<${Text} color=${theme.accent}>${notice}<//>`}
489
- ${phase === "waiting" && paused && html`<${Text} dimColor>paused until ${formatClock(pausedUntil)}${inQuietHours(now, settings.quiet) ? " (quiet hours)" : ""}<//>`}
490
- ${phase === "waiting" && !paused && restUntil && nextAt - now > settings.everyMs && html`<${Text} dimColor>nothing waiting · next card ${whenDue(restUntil, now)}<//>`}
617
+ ${confirming && html`<${Text} color=${theme.warn}>${t("quiz.correctConfirm", { answer: session.wrongAnswer() })}<//>`}
618
+ ${phase === "waiting" && paused && html`<${Text} dimColor>${t("quiz.pausedUntil", { time: formatClock(pausedUntil) })}${inQuietHours(now, settings.quiet) ? t("quiz.quietHours") : ""}<//>`}
619
+ ${phase === "waiting" && !paused && restUntil && nextAt - now > settings.everyMs && html`<${Text} dimColor>${t("quiz.nothingWaiting", { when: whenDue(restUntil, now) })}<//>`}
620
+ ${phase === "waiting" && !paused && sessionWait && sessionLength(settings.rhythm) && html`<${Text} dimColor>${t("quiz.sessionProgress", { done: sessionDone.current, count: sessionLength(settings.rhythm) })}<//>`}
491
621
  ${phase === "waiting" &&
492
622
  !paused &&
623
+ !sessionWait &&
493
624
  !(restUntil && nextAt - now > settings.everyMs) &&
494
625
  html`
495
626
  <${Text}>
496
627
  <${Text} color=${theme.accent}>${frame} <//>
497
628
  <${Bar} value=${Math.max(0, nextAt - now)} max=${settings.everyMs} width=${14} color="#6b5e8a" />
498
- <${Text} dimColor> next card in ${clock(nextAt - now)}<//>
629
+ <${Text} dimColor>${t("quiz.nextCardIn", { time: clock(nextAt - now) })}<//>
499
630
  <//>
500
631
  `}
501
632
  ${(phase === "waiting" || phase === "empty") && commandMode && html`<${AnswerInput} commandOnly initial="/" commands=${commandsFor({ phase: "waiting", canOverrule: session.canOverrule() })} onCommand=${runCommand} onCancel=${() => setCommandMode(false)} onEdit=${clearProblem} />`}
502
- ${phase !== "loading" && !commandMode && html`<${KeyHints} text=${phase === "asking" ? "enter submit (empty: reveal) · / commands · esc quit" : phase === "empty" ? "/add · / commands · q quit" : `${session.canOverrule() ? "/correct if you were right · " : ""}enter ask now · / commands · q quit`} />`}
633
+ ${phase !== "loading" && !commandMode && html`<${KeyHints} text=${confirming ? t("keyHints.confirm", { yes: t("choice.yesKey").split("|")[0], no: t("choice.noKey").split("|")[0] }) : phase === "grading" ? t("keyHints.grading") : phase === "asking" ? t("keyHints.asking") : phase === "empty" ? t("keyHints.empty") : session.canOverrule() ? t("keyHints.correctFirst", { rest: t(sessionWait ? "keyHints.sessionWaiting" : "keyHints.waiting") }) : t(sessionWait ? "keyHints.sessionWaiting" : "keyHints.waiting")} />`}
503
634
  <//>
504
635
  <//>
505
636
  `}
@@ -1,7 +1,8 @@
1
+ import { t } from "../i18n.js";
1
2
  import { useEffect, useState } from "react";
2
- import { Box, Text } from "ink";
3
+ import { Box } from "ink";
3
4
  import { badgeColor } from "./icons.js";
4
- import { html, theme } from "./kit.js";
5
+ import { html, Text, theme } from "./kit.js";
5
6
 
6
7
  const FRAME_MS = 90;
7
8
  const FLASH_FRAMES = [5, 7]; // white-out frames before the name lights up in its rank color
@@ -41,7 +42,7 @@ export function BadgeUnlock({ id, name, desc, delay = 0, sound = badgeSound(0),
41
42
  return html`
42
43
  <${Box}>
43
44
  <${Text} color=${color}>✦ <//>
44
- <${Text} color=${theme.warn}>Badge unlocked: <//>
45
+ <${Text} color=${theme.warn}>${t("badgeUnlock.label")}<//>
45
46
  <${Text} bold color=${color}>${name}<//>
46
47
  <${Text} dimColor> · ${desc}<//>
47
48
  <${Text} color=${theme.warn}>${sparks}<//>
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
  }