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.
- package/README.md +25 -17
- package/locales/de.json +1098 -0
- package/locales/en.json +1081 -0
- package/locales/fr.json +1148 -0
- package/locales/pl.json +1173 -0
- package/locales/uk.json +1174 -0
- package/package.json +2 -2
- package/src/alerts.js +71 -4
- package/src/backup.js +2 -1
- package/src/cardline.js +71 -0
- package/src/cli.js +41 -54
- package/src/commands.js +14 -12
- package/src/demo.js +11 -0
- package/src/diff.js +20 -10
- package/src/i18n.js +68 -0
- package/src/judge.js +164 -13
- package/src/language.js +355 -0
- package/src/library.js +91 -38
- package/src/lock.js +2 -1
- package/src/manage.js +193 -58
- package/src/pause.js +1 -2
- package/src/progress.js +119 -63
- package/src/quiet.js +3 -2
- package/src/scheduler.js +26 -9
- package/src/session.js +118 -36
- package/src/settings.js +14 -6
- package/src/starter.js +36 -27
- package/src/store.js +11 -8
- package/src/tips.js +12 -3
- package/src/ui/AddCard.js +449 -81
- package/src/ui/AnswerInput.js +22 -10
- package/src/ui/App.js +209 -57
- package/src/ui/BadgeUnlock.js +5 -4
- package/src/ui/Badges.js +9 -8
- package/src/ui/Choice.js +14 -9
- package/src/ui/Companion.js +13 -13
- package/src/ui/Confetti.js +2 -2
- package/src/ui/Decks.js +167 -9
- package/src/ui/DieRoll.js +9 -9
- package/src/ui/Evolution.js +7 -7
- package/src/ui/Hatch.js +7 -6
- package/src/ui/Header.js +58 -16
- package/src/ui/Help.js +43 -25
- package/src/ui/Languages.js +167 -0
- package/src/ui/Mascot.js +1 -2
- package/src/ui/Missed.js +13 -12
- package/src/ui/Preview.js +48 -29
- package/src/ui/Reset.js +13 -14
- package/src/ui/Settings.js +27 -19
- package/src/ui/Stats.js +24 -23
- package/src/ui/Summary.js +30 -15
- package/src/ui/TheOne.js +7 -6
- package/src/ui/icons.js +1 -2
- package/src/ui/kit.js +34 -6
- package/src/vacation.js +2 -1
- package/src/words.js +8 -2
- package/data/tips.json +0 -32
package/src/ui/Settings.js
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import { Fragment, useState } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
-
import {
|
|
2
|
+
import { Box, useInput } from "ink";
|
|
3
|
+
import { language, LANGUAGES, t } from "../i18n.js";
|
|
4
|
+
import { GOALS, INTERVALS, QUIET_PRESETS, RHYTHMS, TIP_MODES, VOLUMES, formatInterval } from "../settings.js";
|
|
4
5
|
import { formatQuiet } from "../quiet.js";
|
|
5
|
-
import { Bar, html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
6
|
+
import { Bar, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
6
7
|
|
|
7
8
|
function VolumeValue({ value }) {
|
|
8
9
|
return html`<${Text}><${Bar} value=${value} max=${1} width=${10} /> ${Math.round(value * 100)}%<//>`;
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
// label and hint come from settings.rows.<key> in the locale
|
|
11
13
|
const ALL_ROWS = [
|
|
12
|
-
{ key: "
|
|
13
|
-
{ key: "
|
|
14
|
-
{ key: "
|
|
15
|
-
{ key: "
|
|
16
|
-
{ key: "
|
|
17
|
-
{ key: "
|
|
18
|
-
{ key: "
|
|
19
|
-
{ key: "
|
|
14
|
+
{ key: "language", options: Object.keys(LANGUAGES), format: (code) => LANGUAGES[code] },
|
|
15
|
+
{ key: "rhythm", options: RHYTHMS, format: (v) => t(`settings.rhythms.${v}`) },
|
|
16
|
+
{ key: "everyMs", options: INTERVALS, format: formatInterval },
|
|
17
|
+
{ key: "sound", options: [true, false], format: (v) => t(v ? "settings.on" : "settings.off"), toggle: true },
|
|
18
|
+
{ key: "speak", options: [false, true], format: (v) => t(v ? "settings.on" : "settings.off"), toggle: true },
|
|
19
|
+
{ key: "volume", options: VOLUMES, format: (v) => html`<${VolumeValue} value=${v} />` },
|
|
20
|
+
{ key: "dailyGoal", options: GOALS, format: (n) => t("settings.goal", { n }) },
|
|
21
|
+
{ key: "tips", options: TIP_MODES, format: (v) => t(`settings.tipModes.${v}`) },
|
|
22
|
+
{ key: "skipWeekends", options: [true, false], format: (v) => t(v ? "settings.weekendsRest" : "settings.weekendsCount"), toggle: true },
|
|
23
|
+
{ key: "quiet", options: QUIET_PRESETS, format: formatQuiet },
|
|
24
|
+
{ key: "reset", action: true, format: () => t("settings.pressEnter") }
|
|
20
25
|
];
|
|
26
|
+
const label = (row) => t(`settings.rows.${row.key}.label`);
|
|
21
27
|
|
|
22
28
|
const nearestIndex = (options, value) => {
|
|
23
29
|
const exact = options.findIndex((option) => JSON.stringify(option) === JSON.stringify(value));
|
|
@@ -31,6 +37,8 @@ export function Settings({ settings, onChange, onClose, onAction }) {
|
|
|
31
37
|
const panel = usePanelWidth();
|
|
32
38
|
const [row, setRow] = useState(0);
|
|
33
39
|
const ROWS = onAction ? ALL_ROWS : ALL_ROWS.filter((item) => !item.action);
|
|
40
|
+
const values = { ...settings, language: settings.language ?? language() };
|
|
41
|
+
const labelWidth = Math.max(...ROWS.map((item) => label(item).length)) + 2;
|
|
34
42
|
|
|
35
43
|
useInput((input, key) => {
|
|
36
44
|
if (key.escape || input === "q") return onClose();
|
|
@@ -40,30 +48,30 @@ export function Settings({ settings, onChange, onClose, onAction }) {
|
|
|
40
48
|
const current = ROWS[row];
|
|
41
49
|
if (current.action) return key.return ? onAction(current.key) : undefined;
|
|
42
50
|
const direction = key.leftArrow ? -1 : key.rightArrow ? 1 : 0;
|
|
43
|
-
if (current.toggle && (direction || key.return || input === " ")) return onChange({ [current.key]: !
|
|
51
|
+
if (current.toggle && (direction || key.return || input === " ")) return onChange({ [current.key]: !values[current.key] });
|
|
44
52
|
if (!direction) return;
|
|
45
|
-
const index = nearestIndex(current.options,
|
|
53
|
+
const index = nearestIndex(current.options, values[current.key]);
|
|
46
54
|
const next = current.options[Math.min(current.options.length - 1, Math.max(0, index + direction))];
|
|
47
|
-
if (JSON.stringify(next) !== JSON.stringify(
|
|
55
|
+
if (JSON.stringify(next) !== JSON.stringify(values[current.key])) onChange({ [current.key]: next });
|
|
48
56
|
});
|
|
49
57
|
|
|
50
58
|
return html`
|
|
51
59
|
<${Fragment}>
|
|
52
60
|
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
53
|
-
<${Text} bold color=${theme.accent}
|
|
61
|
+
<${Text} bold color=${theme.accent}>${t("settings.title")}<//>
|
|
54
62
|
<${Box} flexDirection="column" marginTop=${1}>
|
|
55
63
|
${ROWS.map(
|
|
56
64
|
(item, i) => html`
|
|
57
65
|
<${Box} key=${item.key}>
|
|
58
|
-
<${Text} color=${i === row ? theme.accent : undefined} bold=${i === row}>${i === row ? "❯" : " "} ${item.
|
|
59
|
-
<${Text} color=${i === row ? theme.accent : undefined}>${i === row && !item.action ? "❮ " : " "}${item.format(
|
|
66
|
+
<${Box} flexShrink=${0}><${Text} color=${i === row ? theme.accent : undefined} bold=${i === row}>${i === row ? "❯" : " "} ${label(item).padEnd(labelWidth)}<//><//>
|
|
67
|
+
<${Text} color=${i === row ? theme.accent : undefined}>${i === row && !item.action ? "❮ " : " "}${item.format(values[item.key])}${i === row && !item.action ? " ❯" : ""}<//>
|
|
60
68
|
<//>
|
|
61
69
|
`
|
|
62
70
|
)}
|
|
63
71
|
<//>
|
|
64
|
-
<${Box} marginTop=${1}><${Text} dimColor>${ROWS[row].hint}<//><//>
|
|
72
|
+
<${Box} marginTop=${1}><${Text} dimColor>${t(`settings.rows.${ROWS[row].key}.hint`)}<//><//>
|
|
65
73
|
<//>
|
|
66
|
-
<${Box} paddingX=${1}><${KeyHints} text
|
|
74
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.settings")} /><//>
|
|
67
75
|
<//>
|
|
68
76
|
`;
|
|
69
77
|
}
|
package/src/ui/Stats.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
1
2
|
import { Fragment, useState } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
+
import { Box, useInput } from "ink";
|
|
3
4
|
import { dragonName } from "../progress.js";
|
|
4
5
|
import { formatRange } from "../vacation.js";
|
|
5
|
-
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
6
|
+
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
6
7
|
|
|
7
|
-
const DAY_LETTERS = ["M", "T", "W", "T", "F", "S", "S"];
|
|
8
8
|
// One shape for every day; only the color tells them apart, GitHub-contribution style.
|
|
9
9
|
const TILE = {
|
|
10
10
|
goal: theme.good,
|
|
@@ -31,7 +31,7 @@ function Calendar({ month, goal }) {
|
|
|
31
31
|
return html`
|
|
32
32
|
<${Box} flexDirection="column">
|
|
33
33
|
<${Box}>
|
|
34
|
-
${
|
|
34
|
+
${t("stats.weekdays").split(" ").map((letter, i) =>
|
|
35
35
|
i === todayColumn ? html`<${Text} key=${i} color=${theme.accent} bold>${letter} <//>` : html`<${Text} key=${i} dimColor>${letter} <//>`
|
|
36
36
|
)}
|
|
37
37
|
<//>
|
|
@@ -48,16 +48,17 @@ function Calendar({ month, goal }) {
|
|
|
48
48
|
|
|
49
49
|
function Legend({ goal }) {
|
|
50
50
|
const items = [
|
|
51
|
-
[TILE.goal,
|
|
52
|
-
[TILE.halfway, "halfway"],
|
|
53
|
-
[TILE.some, "some"],
|
|
54
|
-
[TILE.none, "none"],
|
|
55
|
-
[TILE.rest, "rest"],
|
|
56
|
-
[TILE.today, "today"]
|
|
51
|
+
[TILE.goal, t("stats.legend.goal", { goal })],
|
|
52
|
+
[TILE.halfway, t("stats.legend.halfway")],
|
|
53
|
+
[TILE.some, t("stats.legend.some")],
|
|
54
|
+
[TILE.none, t("stats.legend.none")],
|
|
55
|
+
[TILE.rest, t("stats.legend.rest")],
|
|
56
|
+
[TILE.today, t("stats.legend.today")]
|
|
57
57
|
];
|
|
58
|
+
// a box per item, so a longer language wraps whole items instead of splitting one
|
|
58
59
|
return html`
|
|
59
|
-
<${
|
|
60
|
-
${items.map(([color, label]) => html`<${Text} key=${label}><${Text} color=${color}>■<//><${Text} dimColor> ${label}
|
|
60
|
+
<${Box} flexWrap="wrap" columnGap=${2}>
|
|
61
|
+
${items.map(([color, label]) => html`<${Text} key=${label}><${Text} color=${color}>■<//><${Text} dimColor> ${label}<//><//>`)}
|
|
61
62
|
<//>
|
|
62
63
|
`;
|
|
63
64
|
}
|
|
@@ -75,37 +76,37 @@ export function Stats({ stats, getMonth, onClose }) {
|
|
|
75
76
|
const accuracy = today.asked ? Math.round((today.correct / today.asked) * 100) : null;
|
|
76
77
|
const unlocked = stats.badges.filter((b) => b.unlockedOn).length;
|
|
77
78
|
const month = getMonth(offset);
|
|
78
|
-
const next = companion.nextAt ?
|
|
79
|
+
const next = companion.nextAt ? t("stats.nextForm", { count: companion.nextAt }) : t("stats.fullyEvolved");
|
|
79
80
|
const title = dragonName(companion.index, companion.element);
|
|
80
81
|
|
|
81
82
|
return html`
|
|
82
83
|
<${Fragment}>
|
|
83
84
|
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
|
|
84
|
-
<${Text} bold color=${theme.accent}
|
|
85
|
+
<${Text} bold color=${theme.accent}>${t("stats.title")}<//>
|
|
85
86
|
|
|
86
87
|
<${Box} marginTop=${1} flexDirection="column">
|
|
87
88
|
<${Text}>
|
|
88
|
-
${streak.days > 0 ? html`<${Text} color=${theme.warn} bold>${streak.days}
|
|
89
|
-
<${Text} dimColor
|
|
89
|
+
${streak.days > 0 ? html`<${Text} color=${theme.warn} bold>${t("stats.streak", { count: streak.days })}<//>` : html`<${Text} dimColor>${t("stats.noStreak")}<//>`}
|
|
90
|
+
<${Text} dimColor>${t("stats.bestAndFreezes", { best: streak.best, count: streak.freezes })}<//>
|
|
90
91
|
<//>
|
|
91
|
-
<${Text} dimColor
|
|
92
|
-
<${Text} dimColor
|
|
93
|
-
<${Text} dimColor
|
|
94
|
-
<${Text} dimColor
|
|
92
|
+
<${Text} dimColor>${t("stats.today", { correct: today.correct, goal, accuracy: accuracy === null ? "" : t("stats.accuracy", { percent: accuracy }) })}<//>
|
|
93
|
+
<${Text} dimColor>${t("stats.cards", { mastered: stats.mastered, practised: stats.practiced, total: stats.totalCorrect })}<//>
|
|
94
|
+
<${Text} dimColor>${t("stats.companion", { name: title, stage: companion.index + 1, next })}<//>
|
|
95
|
+
<${Text} dimColor>${t("stats.restDays", { weekends: t(stats.skipWeekends ? "stats.weekends" : "stats.noWeekends"), daysOff: stats.vacation.upcoming.length ? t("stats.daysOff", { ranges: stats.vacation.upcoming.map((v) => formatRange(v.from, v.to)).join(", ") }) : "" })}<//>
|
|
95
96
|
<//>
|
|
96
97
|
|
|
97
98
|
<${Box} marginTop=${1} flexDirection="column">
|
|
98
99
|
<${Text} bold>${month.label}<//>
|
|
99
100
|
<${Box} marginTop=${1}><${Calendar} month=${month} goal=${goal} /><//>
|
|
100
101
|
<${Box} marginTop=${1} flexDirection="column">
|
|
101
|
-
<${Text} dimColor
|
|
102
|
+
<${Text} dimColor>${t("stats.month", { goalDays: month.goalDays, days: month.daysSoFar, correct: month.correct })}<//>
|
|
102
103
|
<${Legend} goal=${goal} />
|
|
103
104
|
<//>
|
|
104
105
|
<//>
|
|
105
106
|
|
|
106
|
-
<${Box} marginTop=${1}><${Text} dimColor>${unlocked
|
|
107
|
+
<${Box} marginTop=${1}><${Text} dimColor>${t("stats.badgesLine", { unlocked, total: stats.badges.length })}<//><//>
|
|
107
108
|
<//>
|
|
108
|
-
<${Box} paddingX=${1}><${KeyHints} text
|
|
109
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t("keyHints.stats")} /><//>
|
|
109
110
|
<//>
|
|
110
111
|
`;
|
|
111
112
|
}
|
package/src/ui/Summary.js
CHANGED
|
@@ -1,41 +1,56 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
1
2
|
import { Fragment } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
-
import { Bar, html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
3
|
+
import { Box, useInput } from "ink";
|
|
4
|
+
import { Bar, cellWidth, html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
4
5
|
import { dragonName } from "../progress.js";
|
|
5
6
|
import { Flame } from "./icons.js";
|
|
6
7
|
import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
|
|
7
8
|
|
|
9
|
+
const BAR = 12;
|
|
10
|
+
const MIN_BAR = 4;
|
|
11
|
+
|
|
8
12
|
// The end-of-session screen: how this run went, shown on quit. Any key leaves for real.
|
|
9
13
|
export function Summary({ stats, totals, bestCombo, onDone }) {
|
|
10
14
|
const panel = usePanelWidth();
|
|
11
|
-
useInput(() => onDone());
|
|
12
15
|
const { streak, today, goal, companion } = stats;
|
|
16
|
+
// the "today" row fits beside the dragon: the bar shrinks first, then "goal reached" goes
|
|
17
|
+
const room = panel - 6 - (MASCOT_WIDTH + 3);
|
|
18
|
+
const count = ` ${Math.min(today.correct, goal)}/${goal}`;
|
|
19
|
+
const reached = today.goalMet ? cellWidth(t("summary.goalReached")) : 0;
|
|
20
|
+
const fitBar = (extra) => Math.min(BAR, room - cellWidth(t("summary.today")) - cellWidth(count) - extra);
|
|
21
|
+
const showReached = reached > 0 && fitBar(reached) >= MIN_BAR;
|
|
22
|
+
const barWidth = fitBar(showReached ? reached : 0);
|
|
23
|
+
useInput(() => onDone());
|
|
13
24
|
const accuracy = totals.asked ? Math.round((totals.correct / totals.asked) * 100) : 0;
|
|
14
25
|
const face = today.goalMet ? "happy" : totals.correct > 0 ? "smile" : "idle";
|
|
15
26
|
|
|
16
27
|
return html`
|
|
17
28
|
<${Fragment}>
|
|
18
29
|
<${Box} borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${panel}>
|
|
19
|
-
<${Box} flexDirection="column" width=${MASCOT_WIDTH + 3}>
|
|
30
|
+
<${Box} flexDirection="column" width=${MASCOT_WIDTH + 3} flexShrink=${0}>
|
|
20
31
|
<${Mascot} face=${face} stage=${companion.index} element=${companion.element} />
|
|
21
32
|
<//>
|
|
22
33
|
<${Box} flexDirection="column" justifyContent="center">
|
|
23
|
-
<${Box}><${Text} bold color=${theme.accent}
|
|
24
|
-
<${Box}><${Text}>${totals.correct
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
<${Box}><${Text} bold color=${theme.accent}>${t("summary.title")}<//><//>
|
|
35
|
+
<${Box}><${Text}>${t("summary.result", { correct: totals.correct, asked: totals.asked, percent: accuracy })}${bestCombo >= 2 ? t("summary.bestCombo", { count: bestCombo }) : ""}<//><//>
|
|
36
|
+
${barWidth >= MIN_BAR
|
|
37
|
+
? html`
|
|
38
|
+
<${Box}>
|
|
39
|
+
<${Text} dimColor>${t("summary.today")}<//>
|
|
40
|
+
<${Bar} value=${today.correct} max=${goal} width=${barWidth} color=${today.goalMet ? theme.good : theme.accent} />
|
|
41
|
+
<${Text} dimColor>${count}<//>
|
|
42
|
+
${today.goalMet && showReached && html`<${Text} color=${theme.good}>${t("summary.goalReached")}<//>`}
|
|
43
|
+
<//>
|
|
44
|
+
`
|
|
45
|
+
: html`<${Text} dimColor>${t("summary.today").trim()} ${count.trim()}<//>`}
|
|
31
46
|
<${Box}>
|
|
32
47
|
${streak.days > 0 && html`<${Box}><${Flame} /><${Text}> <//><//>`}
|
|
33
|
-
<${Text} dimColor>${streak.days > 0 ?
|
|
48
|
+
<${Text} dimColor>${streak.days > 0 ? t("summary.streak", { count: streak.days }) : t("summary.noStreak")}${streak.atRisk ? t("summary.atRisk") : ""}<//>
|
|
34
49
|
<//>
|
|
35
|
-
<${Box}><${Text} dimColor
|
|
50
|
+
<${Box}><${Text} dimColor>${t("summary.waiting", { name: dragonName(companion.index, companion.element) })}<//><//>
|
|
36
51
|
<//>
|
|
37
52
|
<//>
|
|
38
|
-
<${Box} paddingX=${1}><${KeyHints} text
|
|
53
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t("summary.keys")} /><//>
|
|
39
54
|
<//>
|
|
40
55
|
`;
|
|
41
56
|
}
|
package/src/ui/TheOne.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
1
2
|
import React, { Fragment, useEffect, useState } from "react";
|
|
2
|
-
import { Box,
|
|
3
|
+
import { Box, useInput } from "ink";
|
|
3
4
|
import { RING } from "./icons.js";
|
|
4
|
-
import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
|
|
5
|
+
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
5
6
|
|
|
6
7
|
const FRAME_MS = 110;
|
|
7
8
|
const WIDTH = 16; // pixels; each is drawn two characters wide
|
|
@@ -95,7 +96,7 @@ export function TheOne({ onClose, play = () => {} }) {
|
|
|
95
96
|
|
|
96
97
|
const revealed = frame >= REVEAL_AT;
|
|
97
98
|
useInput(() => (revealed ? onClose() : setFrame(REVEAL_AT)));
|
|
98
|
-
const caption = frame < RISE_FROM ? "
|
|
99
|
+
const caption = t(frame < RISE_FROM ? "theOne.stirring" : "theOne.rises");
|
|
99
100
|
|
|
100
101
|
return html`
|
|
101
102
|
<${Fragment}>
|
|
@@ -108,14 +109,14 @@ export function TheOne({ onClose, play = () => {} }) {
|
|
|
108
109
|
${revealed
|
|
109
110
|
? html`
|
|
110
111
|
<${Fragment}>
|
|
111
|
-
<${Text} bold color=${RING.palette.G}
|
|
112
|
-
<${Text} dimColor
|
|
112
|
+
<${Text} bold color=${RING.palette.G}>${t("theOne.title")}<//>
|
|
113
|
+
<${Text} dimColor>${t("theOne.line")}<//>
|
|
113
114
|
<//>
|
|
114
115
|
`
|
|
115
116
|
: html`<${Text} dimColor>${caption}<//>`}
|
|
116
117
|
<//>
|
|
117
118
|
<//>
|
|
118
|
-
<${Box} paddingX=${1}><${KeyHints} text=${revealed ? "
|
|
119
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "theOne.keysContinue" : "theOne.keysSkip")} /><//>
|
|
119
120
|
<//>
|
|
120
121
|
`;
|
|
121
122
|
}
|
package/src/ui/icons.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Text } from "ink";
|
|
2
1
|
import { BADGES } from "../progress.js";
|
|
3
|
-
import { html } from "./kit.js";
|
|
2
|
+
import { html, Text } from "./kit.js";
|
|
4
3
|
import { PixelGrid } from "./Mascot.js";
|
|
5
4
|
|
|
6
5
|
// 8×8 pixel icons for the badge groups, drawn with the same half-block technique as the mascot.
|
package/src/ui/kit.js
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { Text, useStdout } from "ink";
|
|
1
|
+
import React, { createContext, useContext, useEffect, useState } from "react";
|
|
2
|
+
import { Text as InkText, Transform, useStdout } from "ink";
|
|
3
3
|
import htm from "htm";
|
|
4
|
+
import { t } from "../i18n.js";
|
|
4
5
|
|
|
5
6
|
export const html = htm.bind(React.createElement);
|
|
6
7
|
|
|
8
|
+
// Ink wraps with wrap-ansi and keeps the spaces, so when a word ends exactly at the edge, the space
|
|
9
|
+
// after it starts the next line (" elle viendra…"). In a text without line breaks of its own, any
|
|
10
|
+
// line after the first comes from wrapping, and a space at its start is that leftover: it goes.
|
|
11
|
+
// A space painted inverse or on a background (the answer line's cursor) is something to see: it stays.
|
|
12
|
+
const unspill = (line, index) => {
|
|
13
|
+
if (index === 0) return line;
|
|
14
|
+
const [, codes, space] = /^((?:\x1b\[[\d;]*m)*)(\s*)/.exec(line);
|
|
15
|
+
return !space || /\x1b\[(?:7|4\d|10\d)[;m]/.test(codes) ? line : codes + line.slice(codes.length + space.length);
|
|
16
|
+
};
|
|
17
|
+
const InsideText = createContext(false);
|
|
18
|
+
const hasLineBreak = (node) =>
|
|
19
|
+
typeof node === "string" ? node.includes("\n") : Array.isArray(node) ? node.some(hasLineBreak) : Boolean(node?.props) && hasLineBreak(node.props.children);
|
|
20
|
+
|
|
21
|
+
// Ink's Text, minus that space. Only the outermost Text wraps, so only it gets the fix; a Text that
|
|
22
|
+
// truncates instead of wrapping, or has line breaks of its own (indentation may follow them), is
|
|
23
|
+
// left as it is. Every UI file takes Text from here.
|
|
24
|
+
export function Text(props) {
|
|
25
|
+
const nested = useContext(InsideText);
|
|
26
|
+
const text = React.createElement(InkText, props);
|
|
27
|
+
if (nested || (props.wrap && props.wrap !== "wrap") || hasLineBreak(props.children)) return text;
|
|
28
|
+
return React.createElement(InsideText.Provider, { value: true }, React.createElement(Transform, { transform: unspill }, text));
|
|
29
|
+
}
|
|
30
|
+
|
|
7
31
|
// Dracosh palette: soft violet accents and a green dragon on dark, gold for fire and glory
|
|
8
32
|
export const theme = {
|
|
9
33
|
accent: "#9d7cd8",
|
|
@@ -27,13 +51,17 @@ export function Marked({ text, plain = false, ...props }) {
|
|
|
27
51
|
);
|
|
28
52
|
}
|
|
29
53
|
|
|
30
|
-
// the key at the start of a hint segment: "enter", "esc", "/add", "↑/↓", "any key", "q"
|
|
31
|
-
|
|
54
|
+
// the key at the start of a hint segment: "enter", "esc", "/add", "↑/↓", "any key", "q"…; the
|
|
55
|
+
// longer key names come from the locale ("échap", "dowolny klawisz")
|
|
56
|
+
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
57
|
+
const keyPattern = () => new RegExp(`^(${[...t("keyHints.keyNames").split("|").map((name) => escapeRegExp(name).replace(/ /g, "[ \u00a0]")), "↑/↓", "←/→", "\\/\\S*", "[\\p{L}\\d]"].join("|")})(?=[\\s,]|$)`, "u");
|
|
32
58
|
|
|
33
59
|
// A footer like "enter submit · / commands · esc quit": each key stands out, the words after it
|
|
34
|
-
// stay quiet, and the dots between them fade back.
|
|
60
|
+
// stay quiet, and the dots between them fade back. A narrow pane wraps it between hints, never
|
|
61
|
+
// between a key and what it does.
|
|
35
62
|
export function KeyHints({ text }) {
|
|
36
|
-
const parts = text.split(" · ");
|
|
63
|
+
const parts = text.split(" · ").map((part) => part.replace(/ /g, "\u00a0"));
|
|
64
|
+
const KEY = keyPattern();
|
|
37
65
|
return React.createElement(
|
|
38
66
|
Text,
|
|
39
67
|
null,
|
package/src/vacation.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { addDays, daysBetween } from "./dates.js";
|
|
2
|
+
import { dateLocale } from "./i18n.js";
|
|
2
3
|
|
|
3
4
|
const MAX_DAYS = 120; // a typo like "2062" shouldn't switch the streak off for years
|
|
4
5
|
|
|
5
|
-
export const formatDay = (key) => new Date(`${key}T12:00:00`).toLocaleDateString(
|
|
6
|
+
export const formatDay = (key) => new Date(`${key}T12:00:00`).toLocaleDateString(dateLocale(), { day: "numeric", month: "short" });
|
|
6
7
|
export const formatRange = (from, to) => (from === to ? formatDay(from) : `${formatDay(from)} – ${formatDay(to)}`);
|
|
7
8
|
|
|
8
9
|
// a real calendar date as "YYYY-MM-DD", or null ("31.02" and the like)
|
package/src/words.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { t } from "./i18n.js";
|
|
2
|
+
import { deckLanguages, homeLanguages, learningSide } from "./language.js";
|
|
1
3
|
import { cardsOf, findDeck, toWords } from "./library.js";
|
|
2
4
|
import { loadLibrary } from "./store.js";
|
|
3
5
|
|
|
@@ -6,14 +8,18 @@ import { loadLibrary } from "./store.js";
|
|
|
6
8
|
// deck, or the tour while you have none.
|
|
7
9
|
export function missingDeck(library, deckRef) {
|
|
8
10
|
const names = library.decks.map((d) => `"${d.name}"`).join(", ");
|
|
9
|
-
return new Error(deckRef ?
|
|
11
|
+
return new Error(deckRef ? t("errors.noDeck", { deck: deckRef, decks: names || t("errors.noDecksYet") }) : t("errors.emptyLibrary"));
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export async function loadWords(deckRef) {
|
|
13
15
|
const library = await loadLibrary();
|
|
14
16
|
const deck = deckRef ? findDeck(library, deckRef) : (library.decks.find((d) => !d.tour) ?? library.decks[0]);
|
|
15
17
|
if (!deck) throw missingDeck(library, deckRef);
|
|
16
|
-
|
|
18
|
+
const cards = cardsOf(library, deck.id);
|
|
19
|
+
// the tour is written in the UI's language on both sides: no pair to show or check by
|
|
20
|
+
const languages = deck.tour ? null : deckLanguages(deck, cards);
|
|
21
|
+
const home = homeLanguages({ others: library.decks.filter((d) => d !== deck && d.languages).map((d) => d.languages) });
|
|
22
|
+
return { words: toWords(cards), deck: { name: deck.name, languages, learning: deck.tour ? null : learningSide(languages, deck, home), directions: deck.directions, tour: Boolean(deck.tour) } };
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
// every deck of yours (not the tour), for "is anything still waiting today?"
|
package/data/tips.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{ "id": "keys-enter", "cat": "Keys", "text": "Don't want to wait? Press Enter between cards and the next one comes right away." },
|
|
3
|
-
{ "id": "keys-esc", "cat": "Keys", "text": "Esc clears what you typed. Press it on an empty line to quit." },
|
|
4
|
-
{ "id": "keys-wake", "cat": "Keys", "text": "Leave Dracosh alone for a few minutes and your dragon dozes off. Any key wakes it." },
|
|
5
|
-
{ "id": "keys-filter", "cat": "Keys", "text": "Type / and a letter or two to narrow the commands: /pa finds /pause." },
|
|
6
|
-
{ "id": "cards-decks", "cat": "Cards", "text": "/decks switches to another deck or starts a new one. Dracosh opens that deck next time too." },
|
|
7
|
-
{ "id": "cards-add", "cat": "Cards", "text": "/add puts new cards into the deck you're practising. Esc when you're done." },
|
|
8
|
-
{ "id": "cards-typo", "cat": "Cards", "text": "One wrong letter in a longer word still counts as right. Dracosh shows you the correct spelling." },
|
|
9
|
-
{ "id": "cards-boxes", "cat": "Cards", "text": "A right answer sends a card to a later box: it comes back in 1, 3, 7, 14, then 30 days." },
|
|
10
|
-
{ "id": "cards-miss", "cat": "Cards", "text": "A missed card goes back to the first box and comes back within minutes, until it sticks." },
|
|
11
|
-
{ "id": "cards-hint", "cat": "Cards", "text": "Stuck on a card? /hint reveals one more letter. The card still counts, but stays in its box." },
|
|
12
|
-
{ "id": "cards-correct", "cat": "Cards", "text": "Marked wrong although you were right? Type /correct before the next card and it counts." },
|
|
13
|
-
{ "id": "cards-dont-know", "cat": "Cards", "text": "Don't know it? Press Enter with nothing typed and the answer shows up. The card comes back soon." },
|
|
14
|
-
{ "id": "cards-missed", "cat": "Cards", "text": "/missed lists the cards you got wrong today. Use ← and → to look at earlier days." },
|
|
15
|
-
{ "id": "cards-new", "cat": "Cards", "text": "Dracosh mixes new cards in with your reviews, up to 20 new ones a day." },
|
|
16
|
-
{ "id": "streak-goal", "cat": "Streak", "text": "Reach your daily goal to keep your streak going. You can change the goal in /settings." },
|
|
17
|
-
{ "id": "streak-freeze", "cat": "Streak", "text": "A freeze saves your streak on a day you missed. You start with two and get one back each week." },
|
|
18
|
-
{ "id": "streak-weekends", "cat": "Streak", "text": "Weekends are rest days by default: skipping them never breaks your streak. Change it in /settings." },
|
|
19
|
-
{ "id": "streak-days-off", "cat": "Streak", "text": "Going away? /pause 7d keeps your streak safe for a week. /pause 24.12 2.01 takes dates." },
|
|
20
|
-
{ "id": "streak-stats", "cat": "Streak", "text": "/stats shows your streak and a calendar of the month. Use ← and → to see other months." },
|
|
21
|
-
{ "id": "dragon-forms", "cat": "Your dragon", "text": "Your dragon grows with your best streak: a new form at 7, 30, 90, 180 and 365 days." },
|
|
22
|
-
{ "id": "dragon-companion", "cat": "Your dragon", "text": "/companion shows your dragon and the forms still ahead of it." },
|
|
23
|
-
{ "id": "dragon-combo", "cat": "Your dragon", "text": "Three right answers in a row and your dragon starts to glow. Keep the combo going!" },
|
|
24
|
-
{ "id": "dragon-badges", "cat": "Your dragon", "text": "/badges shows every badge and what unlocks it. One of them stays secret until you win it." },
|
|
25
|
-
{ "id": "pause-break", "cat": "Breaks", "text": "Need some focus? /pause 30m or /pause 2h holds the cards. /pause off brings them back." },
|
|
26
|
-
{ "id": "pause-quiet", "cat": "Breaks", "text": "Set quiet hours in /settings and Dracosh stays silent while you sleep." },
|
|
27
|
-
{ "id": "settings-every", "cat": "Settings", "text": "Cards too often, or not often enough? Change the interval in /settings." },
|
|
28
|
-
{ "id": "settings-sound", "cat": "Settings", "text": "Sound and volume are in /settings. dracosh --no-sound turns sound off for one run." },
|
|
29
|
-
{ "id": "data-backup", "cat": "Your data", "text": "Dracosh backs up your cards and progress every day. dracosh restore brings a backup back." },
|
|
30
|
-
{ "id": "data-sync", "cat": "Your data", "text": "dracosh --data shows where your cards live. Point DRACOSH_HOME at a synced folder to use two computers." },
|
|
31
|
-
{ "id": "data-deck", "cat": "Your data", "text": "dracosh --deck \"Polish\" starts with another deck, for this run only." }
|
|
32
|
-
]
|