dracosh 0.1.0 → 0.2.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 (51) hide show
  1. package/README.md +42 -20
  2. package/assets/sounds/badge-1.wav +0 -0
  3. package/assets/sounds/badge-2.wav +0 -0
  4. package/assets/sounds/badge-3.wav +0 -0
  5. package/assets/sounds/badge-4.wav +0 -0
  6. package/data/tips.json +31 -1361
  7. package/package.json +1 -1
  8. package/src/alerts.js +4 -3
  9. package/src/backup.js +95 -0
  10. package/src/cli.js +97 -16
  11. package/src/commands.js +7 -7
  12. package/src/judge.js +33 -12
  13. package/src/library.js +127 -0
  14. package/src/lock.js +63 -0
  15. package/src/manage.js +75 -0
  16. package/src/pause.js +23 -0
  17. package/src/progress.js +145 -53
  18. package/src/quiet.js +1 -1
  19. package/src/scheduler.js +38 -26
  20. package/src/session.js +128 -30
  21. package/src/settings.js +4 -9
  22. package/src/starter.js +38 -0
  23. package/src/store.js +55 -16
  24. package/src/tips.js +7 -24
  25. package/src/ui/AddCard.js +172 -0
  26. package/src/ui/AnswerInput.js +8 -5
  27. package/src/ui/App.js +211 -71
  28. package/src/ui/BadgeUnlock.js +50 -0
  29. package/src/ui/Badges.js +75 -17
  30. package/src/ui/Choice.js +33 -0
  31. package/src/ui/Companion.js +20 -35
  32. package/src/ui/Decks.js +49 -0
  33. package/src/ui/DieRoll.js +104 -0
  34. package/src/ui/Evolution.js +6 -5
  35. package/src/ui/Hatch.js +5 -4
  36. package/src/ui/Header.js +7 -6
  37. package/src/ui/Help.js +68 -0
  38. package/src/ui/Mascot.js +88 -38
  39. package/src/ui/Missed.js +6 -5
  40. package/src/ui/Preview.js +92 -17
  41. package/src/ui/Reset.js +72 -0
  42. package/src/ui/Settings.js +15 -11
  43. package/src/ui/Stats.js +10 -7
  44. package/src/ui/Summary.js +12 -5
  45. package/src/ui/TheOne.js +121 -0
  46. package/src/ui/icons.js +156 -24
  47. package/src/ui/kit.js +58 -1
  48. package/src/vacation.js +7 -2
  49. package/src/words.js +21 -14
  50. package/assets/sounds/badge.wav +0 -0
  51. package/src/ui/Tip.js +0 -25
package/src/ui/Stats.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Fragment, useState } from "react";
2
2
  import { Box, Text, useInput } from "ink";
3
+ import { dragonName } from "../progress.js";
3
4
  import { formatRange } from "../vacation.js";
4
- import { html, PANEL_WIDTH, theme } from "./kit.js";
5
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
5
6
 
6
7
  const DAY_LETTERS = ["M", "T", "W", "T", "F", "S", "S"];
7
8
  // One shape for every day; only the color tells them apart, GitHub-contribution style.
@@ -62,6 +63,7 @@ function Legend({ goal }) {
62
63
  }
63
64
 
64
65
  export function Stats({ stats, getMonth, onClose }) {
66
+ const panel = usePanelWidth();
65
67
  const [offset, setOffset] = useState(0);
66
68
  useInput((input, key) => {
67
69
  if (key.escape || key.return || input === "q") return onClose();
@@ -73,11 +75,12 @@ export function Stats({ stats, getMonth, onClose }) {
73
75
  const accuracy = today.asked ? Math.round((today.correct / today.asked) * 100) : null;
74
76
  const unlocked = stats.badges.filter((b) => b.unlockedOn).length;
75
77
  const month = getMonth(offset);
76
- const next = companion.nextAt ? ` · ${companion.nextName} at a ${companion.nextAt}-day streak` : " · fully evolved";
78
+ const next = companion.nextAt ? ` · next form at a ${companion.nextAt}-day streak` : " · fully evolved";
79
+ const title = dragonName(companion.index, companion.element);
77
80
 
78
81
  return html`
79
82
  <${Fragment}>
80
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
83
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
81
84
  <${Text} bold color=${theme.accent}>Stats<//>
82
85
 
83
86
  <${Box} marginTop=${1} flexDirection="column">
@@ -86,9 +89,9 @@ export function Stats({ stats, getMonth, onClose }) {
86
89
  <${Text} dimColor> · best ${streak.best} · ${streak.freezes} freeze${streak.freezes === 1 ? "" : "s"} in stock<//>
87
90
  <//>
88
91
  <${Text} dimColor>today ${today.correct}/${goal} correct${accuracy === null ? "" : ` · ${accuracy}% accuracy`}<//>
89
- <${Text} dimColor>cards ${stats.mastered} mastered · ${stats.practiced} practiced · ${stats.totalCorrect} correct in total<//>
90
- <${Text} dimColor>companion ${companion.name} (${companion.index + 1}/6)${next}<//>
91
- <${Text} dimColor>rest days ${stats.skipWeekends ? "weekends" : "no weekends"}${stats.vacation.upcoming.length ? ` · vacation ${stats.vacation.upcoming.map((v) => formatRange(v.from, v.to)).join(", ")}` : ""}<//>
92
+ <${Text} dimColor>cards ${stats.mastered} mastered · ${stats.practiced} practised · ${stats.totalCorrect} correct in total<//>
93
+ <${Text} dimColor>companion ${title} (${companion.index + 1}/6)${next}<//>
94
+ <${Text} dimColor>rest days ${stats.skipWeekends ? "weekends" : "no weekends"}${stats.vacation.upcoming.length ? ` · days off ${stats.vacation.upcoming.map((v) => formatRange(v.from, v.to)).join(", ")}` : ""}<//>
92
95
  <//>
93
96
 
94
97
  <${Box} marginTop=${1} flexDirection="column">
@@ -102,7 +105,7 @@ export function Stats({ stats, getMonth, onClose }) {
102
105
 
103
106
  <${Box} marginTop=${1}><${Text} dimColor>${unlocked}/${stats.badges.length} badges · /badges lists them all<//><//>
104
107
  <//>
105
- <${Box} paddingX=${1}><${Text} dimColor>←/→ month · esc back<//><//>
108
+ <${Box} paddingX=${1}><${KeyHints} text="←/→ month · esc back" /><//>
106
109
  <//>
107
110
  `;
108
111
  }
package/src/ui/Summary.js CHANGED
@@ -1,10 +1,13 @@
1
1
  import { Fragment } from "react";
2
2
  import { Box, Text, useInput } from "ink";
3
- import { Bar, html, PANEL_WIDTH, theme } from "./kit.js";
3
+ import { Bar, html, KeyHints, theme, usePanelWidth } from "./kit.js";
4
+ import { dragonName } from "../progress.js";
5
+ import { Flame } from "./icons.js";
4
6
  import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
5
7
 
6
8
  // The end-of-session screen: how this run went, shown on quit. Any key leaves for real.
7
9
  export function Summary({ stats, totals, bestCombo, onDone }) {
10
+ const panel = usePanelWidth();
8
11
  useInput(() => onDone());
9
12
  const { streak, today, goal, companion } = stats;
10
13
  const accuracy = totals.asked ? Math.round((totals.correct / totals.asked) * 100) : 0;
@@ -12,9 +15,9 @@ export function Summary({ stats, totals, bestCombo, onDone }) {
12
15
 
13
16
  return html`
14
17
  <${Fragment}>
15
- <${Box} borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${PANEL_WIDTH}>
18
+ <${Box} borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${panel}>
16
19
  <${Box} flexDirection="column" width=${MASCOT_WIDTH + 3}>
17
- <${Mascot} face=${face} stage=${companion.index} />
20
+ <${Mascot} face=${face} stage=${companion.index} element=${companion.element} />
18
21
  <//>
19
22
  <${Box} flexDirection="column" justifyContent="center">
20
23
  <${Box}><${Text} bold color=${theme.accent}>Session over<//><//>
@@ -25,10 +28,14 @@ export function Summary({ stats, totals, bestCombo, onDone }) {
25
28
  <${Text} dimColor> ${Math.min(today.correct, goal)}/${goal}<//>
26
29
  ${today.goalMet && html`<${Text} color=${theme.good}> goal reached<//>`}
27
30
  <//>
28
- <${Box}><${Text} dimColor>${streak.days > 0 ? `🔥 ${streak.days}-day streak` : "no streak yet"}${streak.atRisk ? " · still at risk today" : ""}<//><//>
31
+ <${Box}>
32
+ ${streak.days > 0 && html`<${Box}><${Flame} /><${Text}> <//><//>`}
33
+ <${Text} dimColor>${streak.days > 0 ? `${streak.days}-day streak` : "no streak yet"}${streak.atRisk ? " · still at risk today" : ""}<//>
34
+ <//>
35
+ <${Box}><${Text} dimColor>Your ${dragonName(companion.index, companion.element)} will be waiting.<//><//>
29
36
  <//>
30
37
  <//>
31
- <${Box} paddingX=${1}><${Text} dimColor>see you later · any key to leave<//><//>
38
+ <${Box} paddingX=${1}><${KeyHints} text="see you later · any key to leave" /><//>
32
39
  <//>
33
40
  `;
34
41
  }
@@ -0,0 +1,121 @@
1
+ import React, { Fragment, useEffect, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { RING } from "./icons.js";
4
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
5
+
6
+ const FRAME_MS = 110;
7
+ const WIDTH = 16; // pixels; each is drawn two characters wide
8
+ const HEIGHT = 15;
9
+ const LAVA_TOP = 11; // first row of lava; the ring is hidden wherever it's below this
10
+ const RING_LEFT = 4;
11
+ const RING_REST = 2; // the ring's top row once it's fully out
12
+
13
+ // timeline, in frames: bubbling lava → the ring rises (one row every 2 frames) → it cools → reveal
14
+ const RISE_FROM = 10;
15
+ const RISE_TO = RISE_FROM + (LAVA_TOP - RING_REST) * 2;
16
+ const COOLED_AT = RISE_TO + 6;
17
+ const REVEAL_AT = COOLED_AT + 4;
18
+
19
+ const LAVA = { R: "#9f1d0d", O: "#ea580c", Y: "#fbbf24" };
20
+ // the ring glows while it comes out of the lava, then cools down to gold
21
+ const HEAT = [
22
+ { G: "#ff7a1a", D: "#c2410c", W: "#fde68a" },
23
+ { G: "#fbbf24", D: "#d97706", W: "#fef3c7" },
24
+ RING.palette
25
+ ];
26
+ const SPARKS = ["✦", "·", "✧", "*"];
27
+
28
+ function lavaColor(x, y, frame) {
29
+ const n = (x * 7 + y * 3 + Math.floor(frame / 2) * 5) % 9;
30
+ if (y === LAVA_TOP && (x + Math.floor(frame / 2)) % 5 === 0) return null; // a wavy surface
31
+ return n < 2 ? LAVA.Y : n < 6 ? LAVA.O : LAVA.R;
32
+ }
33
+
34
+ // a few bubbles popping just above the surface
35
+ function bubbleColor(x, y, frame) {
36
+ for (const [bx, offset] of [[3, 0], [9, 2], [13, 4]]) {
37
+ const t = (frame + offset) % 6;
38
+ if (x === bx && t < 3 && y === LAVA_TOP - 1 - t) return LAVA.O;
39
+ }
40
+ return null;
41
+ }
42
+
43
+ function ringTop(frame) {
44
+ if (frame < RISE_FROM) return LAVA_TOP + 1; // still fully submerged
45
+ return Math.max(RING_REST, LAVA_TOP - Math.floor((frame - RISE_FROM) / 2));
46
+ }
47
+
48
+ function heatOf(frame) {
49
+ if (frame < RISE_TO + 2) return HEAT[0];
50
+ return frame < COOLED_AT ? HEAT[1] : HEAT[2];
51
+ }
52
+
53
+ // → rows of colors (null = empty) for one frame
54
+ function scene(frame) {
55
+ const top = ringTop(frame);
56
+ const heat = heatOf(frame);
57
+ return Array.from({ length: HEIGHT }, (_, y) =>
58
+ Array.from({ length: WIDTH }, (_, x) => {
59
+ if (y >= LAVA_TOP) return lavaColor(x, y, frame);
60
+ const ry = y - top;
61
+ const rx = x - RING_LEFT;
62
+ const pixel = RING.grid[ry]?.[rx];
63
+ if (pixel && pixel !== ".") return heat[pixel];
64
+ return bubbleColor(x, y, frame);
65
+ })
66
+ );
67
+ }
68
+
69
+ function BigScene({ rows }) {
70
+ return html`
71
+ <${Fragment}>
72
+ ${rows.map(
73
+ (row, r) => html`<${Text} key=${r}>${row.map((color, c) => React.createElement(Text, { key: c, color }, color ? "██" : " "))}<//>`
74
+ )}
75
+ <//>
76
+ `;
77
+ }
78
+
79
+ const sparkleRow = (frame, seed) =>
80
+ Array.from({ length: 30 }, (_, i) => ((i * 7 + seed * 13 + frame * 3) % 11 === 0 ? SPARKS[(i + frame) % SPARKS.length] : " ")).join("");
81
+
82
+ // The ceremony for "The One", the badge for collecting every other badge: a ring rises from the lava.
83
+ // Any key skips to the end; after the reveal, any key closes it.
84
+ export function TheOne({ onClose, play = () => {} }) {
85
+ const panel = usePanelWidth();
86
+ const [frame, setFrame] = useState(0);
87
+ useEffect(() => {
88
+ const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
89
+ return () => clearInterval(id);
90
+ }, []);
91
+ useEffect(() => {
92
+ if (frame === RISE_FROM) play("close");
93
+ if (frame === REVEAL_AT) play("evolve");
94
+ }, [frame]);
95
+
96
+ const revealed = frame >= REVEAL_AT;
97
+ useInput(() => (revealed ? onClose() : setFrame(REVEAL_AT)));
98
+ const caption = frame < RISE_FROM ? "the lava is stirring…" : "something rises…";
99
+
100
+ return html`
101
+ <${Fragment}>
102
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
103
+ <${Text} color=${theme.warn}>${revealed ? sparkleRow(frame, 1) : " "}<//>
104
+ <${Box} flexDirection="column" alignItems="center">
105
+ <${BigScene} rows=${scene(frame)} />
106
+ <//>
107
+ <${Box} marginTop=${1} flexDirection="column" alignItems="center">
108
+ ${revealed
109
+ ? html`
110
+ <${Fragment}>
111
+ <${Text} bold color=${RING.palette.G}>The One...<//>
112
+ <${Text} dimColor>Every badge is yours. The hoard is complete.<//>
113
+ <//>
114
+ `
115
+ : html`<${Text} dimColor>${caption}<//>`}
116
+ <//>
117
+ <//>
118
+ <${Box} paddingX=${1}><${KeyHints} text=${revealed ? "any key to continue" : "any key to skip"} /><//>
119
+ <//>
120
+ `;
121
+ }
package/src/ui/icons.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { Text } from "ink";
2
+ import { BADGES } from "../progress.js";
1
3
  import { html } from "./kit.js";
2
4
  import { PixelGrid } from "./Mascot.js";
3
5
 
@@ -44,7 +46,7 @@ const ICONS = {
44
46
  ]
45
47
  },
46
48
  star: {
47
- palette: { S: "#fbbf24", W: "#fef3c7" },
49
+ palette: { S: "#fbbf24", W: "#fef3c7", R: "#60a5fa" },
48
50
  grid: [
49
51
  "...S....",
50
52
  "..SSS...",
@@ -89,10 +91,10 @@ const ICONS = {
89
91
  "..MM..W.",
90
92
  ".MM.....",
91
93
  ".MM.....",
92
- ".MM...W.",
93
- "..MM....",
94
- "...MMM..",
95
- "........"
94
+ ".MM.....",
95
+ ".MM.....",
96
+ "..MM..W.",
97
+ "...MMM.."
96
98
  ]
97
99
  },
98
100
  calendar: {
@@ -121,19 +123,6 @@ const ICONS = {
121
123
  "........"
122
124
  ]
123
125
  },
124
- arrows: {
125
- palette: { A: "#4ade80", B: "#9d7cd8" },
126
- grid: [
127
- "..A.....",
128
- ".AA.....",
129
- "AAAAAAA.",
130
- ".AA.....",
131
- ".....BB.",
132
- ".BBBBBBB",
133
- ".....BB.",
134
- "....B..."
135
- ]
136
- },
137
126
  heart: {
138
127
  palette: { H: "#f87171", W: "#fecaca" },
139
128
  grid: [
@@ -162,22 +151,72 @@ const ICONS = {
162
151
  }
163
152
  };
164
153
 
154
+ // the ring for the badge that needs every other one
155
+ ICONS.ring = {
156
+ palette: { G: "#fcd34d", D: "#b45309", W: "#fef9c3" },
157
+ grid: [
158
+ "..GGGG..",
159
+ ".GW..GG.",
160
+ "GW....DG",
161
+ "G......G",
162
+ "G......G",
163
+ "GG....DG",
164
+ ".GD..DG.",
165
+ "..DDDD.."
166
+ ]
167
+ };
168
+
169
+ export const RING = ICONS.ring;
170
+
171
+ // "Dragon's die": a die showing five
172
+ ICONS.die = {
173
+ palette: { W: "#f4f4f5", D: "#c7c9d1", P: "#2a2440" },
174
+ grid: [
175
+ ".WWWWWW.",
176
+ "WPPWWPPW",
177
+ "WPPWWPPW",
178
+ "WWWPPWWD",
179
+ "WWWPPWWD",
180
+ "WPPWWPPD",
181
+ "WPPWWPPD",
182
+ ".DDDDDD."
183
+ ]
184
+ };
185
+
186
+ // what a hidden badge shows until it's won
187
+ ICONS.secret = {
188
+ palette: { Q: "#6b7280" },
189
+ grid: [
190
+ "..QQQQ..",
191
+ ".QQ..QQ.",
192
+ ".....QQ.",
193
+ "....QQ..",
194
+ "...QQ...",
195
+ "...QQ...",
196
+ "........",
197
+ "...QQ..."
198
+ ]
199
+ };
200
+
165
201
  // which icon each badge gets, by badge id
166
202
  const ICON_FOR = {
167
203
  hello: "trophy",
168
204
  "first-steps": "trophy",
169
205
  century: "trophy",
170
- "five-hundred": "trophy",
171
206
  thousand: "trophy",
172
- "two-thousand": "trophy",
207
+ "five-thousand": "trophy",
208
+ "ten-thousand": "trophy",
209
+ "dragons-hoard": "trophy",
173
210
  "on-a-roll": "flame",
174
211
  week: "flame",
175
212
  fortnight: "flame",
176
213
  month: "flame",
177
214
  "hundred-days": "flame",
215
+ dragonheart: "flame",
178
216
  keeper: "book",
179
217
  collector: "book",
180
218
  dictionary: "book",
219
+ lexicon: "book",
181
220
  explorer: "compass",
182
221
  flawless: "star",
183
222
  overachiever: "star",
@@ -195,15 +234,108 @@ const ICON_FOR = {
195
234
  regular: "calendar",
196
235
  machine: "calendar",
197
236
  "hundred-club": "calendar",
198
- "both-ways": "arrows"
237
+ "one-ring": "ring",
238
+ "dragons-die": "die"
199
239
  };
200
240
 
201
241
  const LOCKED_COLOR = "#4a5058";
202
242
 
203
- export function BadgeIcon({ id, locked = false }) {
243
+ // Rank colors for the badge groups that climb (more answers, longer streaks…): the higher, the rarer.
244
+ const TIERS = [
245
+ { name: "bronze", main: "#d08a4e", shade: "#8a4f1c", light: "#f3c9a0" },
246
+ { name: "silver", main: "#c9d1d9", shade: "#7d8794", light: "#ffffff" },
247
+ { name: "gold", main: "#fcd34d", shade: "#b45309", light: "#fef3c7" },
248
+ { name: "emerald", main: "#34d399", shade: "#047857", light: "#d1fae5" },
249
+ { name: "diamond", main: "#7dd3fc", shade: "#2b6f99", light: "#e0f2fe" },
250
+ { name: "amethyst", main: "#c084fc", shade: "#6b21a8", light: "#f3e8ff" },
251
+ { name: "ruby", main: "#f87171", shade: "#991b1b", light: "#fee2e2" }
252
+ ];
253
+ // Badges that share an icon but need telling apart get their own grid: the calendars mark the days
254
+ // each one asks for, from a weekend to a month nearly full; the day badges are a star (no miss),
255
+ // a crown (double the goal) and a medal (a marathon); a heart with a mended crack is a mistake put right.
256
+ const CALENDAR_PAGE = (days) => [".C.CC.C.", "RRRRRRRR", ...days.map((row) => `C${row}C`), "CCCCCCCC", "........"];
257
+ const OWN_GRIDS = {
258
+ weekend: CALENDAR_PAGE(["WWWWWW", "WWWWGG", "WWWWWW", "WWWWGG"]),
259
+ "perfect-week": CALENDAR_PAGE(["WWWWWW", "GGGGGG", "WWWWWW", "WWWWWW"]),
260
+ regular: CALENDAR_PAGE(["GWGGWG", "GGWGGW", "WGGWGG", "WWWWWW"]),
261
+ machine: CALENDAR_PAGE(["GGGGGG", "GGGGWG", "GGGGGG", "GGWWWW"]),
262
+ "hundred-club": CALENDAR_PAGE(["GGGGGG", "GGGGGG", "GGGGGG", "GGGGGG"]),
263
+ overachiever: [
264
+ "........",
265
+ "W..W..W.",
266
+ "S..S..S.",
267
+ "SS.S.SS.",
268
+ "SSSSSSS.",
269
+ "SRSWSRS.",
270
+ "SSSSSSS.",
271
+ "........"
272
+ ],
273
+ marathon: [
274
+ "RR....RR",
275
+ ".RR..RR.",
276
+ "..RRRR..",
277
+ "..SSSS..",
278
+ ".SSWSSS.",
279
+ ".SWSSSS.",
280
+ ".SSSSSS.",
281
+ "..SSSS.."
282
+ ],
283
+ redemption: [
284
+ "........",
285
+ ".HH..HH.",
286
+ "HWH.HHHH",
287
+ "HWHH.HHH",
288
+ ".HH.HHH.",
289
+ "..HH.H..",
290
+ "...HH...",
291
+ "........"
292
+ ]
293
+ };
294
+
295
+ // which palette letters of a tiered icon take the tier's main / shade / light color
296
+ const TIER_ROLES = {
297
+ trophy: { G: "main", D: "shade", W: "light" },
298
+ flame: { Y: "main", R: "shade", W: "light" },
299
+ book: { B: "main", D: "shade" },
300
+ bolt: { Y: "main", W: "light" },
301
+ calendar: { R: "main" }
302
+ };
303
+
304
+ // the badge's rank within its group, in the order BADGES lists them (easiest first); null if the group isn't tiered
305
+ function tierOf(id) {
306
+ const icon = ICON_FOR[id];
307
+ if (!TIER_ROLES[icon]) return null;
308
+ const group = BADGES.filter((badge) => ICON_FOR[badge.id] === icon).map((badge) => badge.id);
309
+ return TIERS[Math.min(group.indexOf(id), TIERS.length - 1)];
310
+ }
311
+
312
+ function paletteFor(id, icon) {
313
+ const tier = tierOf(id);
314
+ if (!tier) return icon.palette;
315
+ const roles = TIER_ROLES[ICON_FOR[id]];
316
+ return Object.fromEntries(Object.entries(icon.palette).map(([key, color]) => [key, roles[key] ? tier[roles[key]] : color]));
317
+ }
318
+
319
+ // the color that stands for an unlocked badge in lists: its rank color, or gold for untiered ones
320
+ export const badgeColor = (id) => tierOf(id)?.main ?? TIERS[2].main;
321
+
322
+ const fillIn = (row) => row.replace(/(?<=[^.].*)\.(?=.*[^.])/g, "G");
323
+
324
+ // `locked` greys the icon out; `flash` whites it out (a frame of a badge lighting up in /badges);
325
+ // `secret` replaces a hidden badge that isn't won yet with a question mark
326
+ export function BadgeIcon({ id, locked = false, flash = false, secret = false }) {
327
+ if (secret) return html`<${PixelGrid} grid=${ICONS.secret.grid.map((row) => [...row])} palette=${ICONS.secret.palette} />`;
204
328
  const icon = ICONS[ICON_FOR[id]] ?? ICONS.star;
205
- const palette = locked ? Object.fromEntries(Object.keys(icon.palette).map((k) => [k, LOCKED_COLOR])) : icon.palette;
206
- return html`<${PixelGrid} grid=${icon.grid.map((row) => [...row])} palette=${palette} />`;
329
+ const flat = (color) => Object.fromEntries(Object.keys(icon.palette).map((k) => [k, color]));
330
+ const palette = flash ? flat("#ffffff") : locked ? flat(LOCKED_COLOR) : paletteFor(id, icon);
331
+ // a locked ring is drawn filled in, so its silhouette doesn't give away what it is
332
+ const own = OWN_GRIDS[id] ?? icon.grid;
333
+ const grid = locked && !flash && id === "one-ring" ? own.map(fillIn) : own;
334
+ return html`<${PixelGrid} grid=${grid.map((row) => [...row])} palette=${palette} />`;
207
335
  }
208
336
 
337
+ // The streak flame: a small triangle in fire orange, the height of the letters next to it.
338
+ // (Pixel blocks fill the whole line height and look too big beside text.)
339
+ export const Flame = () => html`<${Text} color="#f97316">▴<//>`;
340
+
209
341
  export const ICON_WIDTH = 8;
package/src/ui/kit.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState } from "react";
2
- import { Text } from "ink";
2
+ import { Text, useStdout } from "ink";
3
3
  import htm from "htm";
4
4
 
5
5
  export const html = htm.bind(React.createElement);
@@ -10,11 +10,68 @@ export const theme = {
10
10
  good: "#4ade80",
11
11
  bad: "#f87171",
12
12
  warn: "#fbbf24",
13
+ text: "#c9ccd3",
14
+ hint: "#8b919c", // the words in key hints: quieter than text, easier to read than dim
13
15
  track: "#3a3f47"
14
16
  };
15
17
 
18
+ // Text where `backticks` mark something to type: shown in the accent color on a faint violet
19
+ // background, like code in docs. Used for the tour's cards; `plain` shows the text as it is.
20
+ export function Marked({ text, plain = false, ...props }) {
21
+ if (plain) return React.createElement(Text, props, text);
22
+ const parts = text.split(/`([^`]+)`/);
23
+ return React.createElement(
24
+ Text,
25
+ props,
26
+ ...parts.map((part, i) => (i % 2 ? React.createElement(Text, { key: i, color: theme.accent, backgroundColor: "#2a2440", bold: true }, part) : part))
27
+ );
28
+ }
29
+
30
+ // the key at the start of a hint segment: "enter", "esc", "/add", "↑/↓", "any key", "q"…
31
+ const KEY = /^(any key|↑\/↓|←\/→|enter|esc|tab|\/\S*|[a-z0-9])(?=\s|$)/;
32
+
33
+ // 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.
35
+ export function KeyHints({ text }) {
36
+ const parts = text.split(" · ");
37
+ return React.createElement(
38
+ Text,
39
+ null,
40
+ ...parts.flatMap((part, i) => {
41
+ const key = KEY.exec(part)?.[0];
42
+ const rest = key ? part.slice(key.length) : part;
43
+ return [
44
+ i > 0 && React.createElement(Text, { key: `s${i}`, color: "#5a606b" }, " · "),
45
+ key && React.createElement(Text, { key: `k${i}`, color: theme.text }, key),
46
+ React.createElement(Text, { key: `r${i}`, color: theme.hint }, rest)
47
+ ].filter(Boolean);
48
+ })
49
+ );
50
+ }
51
+
16
52
  // every full-width panel (card, stats, settings…) shares this width
17
53
  export const PANEL_WIDTH = 72;
54
+ const MIN_PANEL_WIDTH = 30;
55
+
56
+ // How many terminal cells text takes: CJK characters and emoji take two. Close enough for labels
57
+ // and deck names; whole characters (not UTF-16 halves) are counted, so an emoji is never cut in two.
58
+ const WIDE = /[\u1100-\u115f\u2e80-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6\p{Extended_Pictographic}]/u;
59
+ export const cellWidth = (text) => Array.from(text).reduce((sum, ch) => sum + (WIDE.test(ch) ? 2 : 1), 0);
60
+ export function cutToWidth(text, cells) {
61
+ if (cellWidth(text) <= cells) return text;
62
+ let out = "";
63
+ for (const ch of text) {
64
+ if (cellWidth(out + ch) > cells - 1) break;
65
+ out += ch;
66
+ }
67
+ return `${out}…`;
68
+ }
69
+
70
+ // the panel width for this terminal: PANEL_WIDTH, or less in a narrow window (some terminals report 0)
71
+ export function usePanelWidth() {
72
+ const { stdout } = useStdout();
73
+ return Math.max(MIN_PANEL_WIDTH, Math.min((stdout?.columns || PANEL_WIDTH + 2) - 2, PANEL_WIDTH));
74
+ }
18
75
 
19
76
  // A thin line: the filled part in `color`, the rest as a dim track. Plain box-drawing characters render
20
77
  // at exactly one cell in every terminal font, unlike the geometric-shape glyphs a font may substitute.
package/src/vacation.js CHANGED
@@ -25,7 +25,7 @@ function parseDate(text, today) {
25
25
  return key && key < today ? valid(`${thisYear + 1}-${pad(month)}-${pad(day)}`) : key;
26
26
  }
27
27
 
28
- // "/vacation" arguments → { action: "list" } | { action: "off" } | { action: "add", from, to } | null (not understood)
28
+ // days-off arguments (see /pause in pause.js) → { action: "list" } | { action: "off" } | { action: "add", from, to } | null (not understood)
29
29
  // "" list what is planned
30
30
  // "off" cancel current and future vacations
31
31
  // "7" / "7d" 7 days starting today
@@ -46,6 +46,11 @@ export function parseVacation(args, today) {
46
46
  const dates = parts.map((part) => parseDate(part, today));
47
47
  if (dates.some((date) => !date)) return null;
48
48
  const [a, b = a] = dates;
49
- const [from, to] = a <= b ? [a, b] : [b, a];
49
+ // A day and month without a year means the next one to come, so a range that already started
50
+ // ("28.12 3.01" on 30 December, "24.12 2.01" on New Year's Day) gets its start back a year.
51
+ // Of the readings that make sense, the shortest wins; a reversed range is read the other way round.
52
+ const back = (key, part) => (/^\d{1,2}\.\d{1,2}$/.test(part) ? valid(`${Number(key.slice(0, 4)) - 1}${key.slice(4)}`) : null);
53
+ const readings = [[a, b], [back(a, parts[0]), b], [b, a]].filter(([x, y]) => x && y && x <= y);
54
+ const [from, to] = readings.sort(([x1, y1], [x2, y2]) => daysBetween(x1, y1) - daysBetween(x2, y2))[0];
50
55
  return daysBetween(from, to) < MAX_DAYS ? { action: "add", from, to } : null;
51
56
  }
package/src/words.js CHANGED
@@ -1,16 +1,23 @@
1
- import { fetchNotes } from "./anki.js";
2
- import { parseNotes } from "./parse.js";
3
- import { loadWordsCache, saveWordsCache } from "./store.js";
1
+ import { cardsOf, findDeck, toWords } from "./library.js";
2
+ import { loadLibrary } from "./store.js";
4
3
 
5
- // words come from Anki; if it's closed, fall back to the last successful read
6
- export async function loadWords(deck) {
7
- try {
8
- const { words, skipped } = parseNotes(await fetchNotes(deck));
9
- await saveWordsCache(deck, words);
10
- return { words, skipped, cached: false };
11
- } catch (err) {
12
- const cache = await loadWordsCache();
13
- if (cache?.deck === deck && cache.words.length) return { words: cache.words, skipped: 0, cached: true };
14
- throw err;
15
- }
4
+ // The words of one library deck, read fresh every time, so cards added from another terminal
5
+ // (with /add) show up at the next question. `deckRef` is a deck name or id; empty = your first own
6
+ // deck, or the tour while you have none.
7
+ export function missingDeck(library, deckRef) {
8
+ const names = library.decks.map((d) => `"${d.name}"`).join(", ");
9
+ return new Error(deckRef ? `There's no deck called "${deckRef}". Your decks: ${names || "none yet"}.` : "Your library has no decks yet.");
10
+ }
11
+
12
+ export async function loadWords(deckRef) {
13
+ const library = await loadLibrary();
14
+ const deck = deckRef ? findDeck(library, deckRef) : (library.decks.find((d) => !d.tour) ?? library.decks[0]);
15
+ if (!deck) throw missingDeck(library, deckRef);
16
+ return { words: toWords(cardsOf(library, deck.id)), deck: { name: deck.name, languages: deck.languages, directions: deck.directions, tour: Boolean(deck.tour) } };
17
+ }
18
+
19
+ // every deck of yours (not the tour), for "is anything still waiting today?"
20
+ export async function loadAllWords() {
21
+ const library = await loadLibrary();
22
+ return library.decks.filter((deck) => !deck.tour).map((deck) => ({ words: toWords(cardsOf(library, deck.id)), deck: { name: deck.name, directions: deck.directions } }));
16
23
  }
Binary file
package/src/ui/Tip.js DELETED
@@ -1,25 +0,0 @@
1
- import { Fragment, useState } from "react";
2
- import { Box, Text, useInput } from "ink";
3
- import { html, PANEL_WIDTH, theme } from "./kit.js";
4
-
5
- // A full-screen grammar tip; Enter or → shows another one.
6
- export function Tip({ nextTip, onClose }) {
7
- const [tip, setTip] = useState(() => nextTip());
8
- useInput((input, key) => {
9
- if (key.escape || input === "q") return onClose();
10
- if (key.return || key.rightArrow || input === " ") setTip(nextTip());
11
- });
12
-
13
- return html`
14
- <${Fragment}>
15
- <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
16
- <${Box}>
17
- <${Text} bold color=${theme.accent}>Grammar tip<//>
18
- <${Text} dimColor> ${tip.cat}<//>
19
- <//>
20
- <${Box} marginTop=${1}><${Text}>${tip.text}<//><//>
21
- <//>
22
- <${Box} paddingX=${1}><${Text} dimColor>enter or → another tip · esc back<//><//>
23
- <//>
24
- `;
25
- }