diff --git a/examples/pomodoro-timer/src/index.tsx b/examples/pomodoro-timer/src/index.tsx index 48d67424f..cad749f32 100644 --- a/examples/pomodoro-timer/src/index.tsx +++ b/examples/pomodoro-timer/src/index.tsx @@ -1,5 +1,5 @@ -import { App, type KeyEvent, type Screen } from '@termuijs/core'; -import { Widget, Box, Text, Center, ProgressBar } from '@termuijs/widgets'; +import { App, type KeyEvent, type Screen, type Style, styleToCellAttrs, type Color, caps } from '@termuijs/core'; +import { Widget, Box, Text, Center } from '@termuijs/widgets'; import { transition } from '@termuijs/motion'; // ── Constants ── @@ -7,11 +7,294 @@ import { transition } from '@termuijs/motion'; const WORK_SECONDS = 25 * 60; const BREAK_SECONDS = 5 * 60; - // ── Types ── type Phase = 'work' | 'break'; +// ── 3x5 Big Font Character Map ── + +const BIG_DIGITS: Record = { + '0': [ + '███', + '█ █', + '█ █', + '█ █', + '███' + ], + '1': [ + ' █ ', + ' █ ', + ' █ ', + ' █ ', + ' █ ' + ], + '2': [ + '███', + ' █', + '███', + '█ ', + '███' + ], + '3': [ + '███', + ' █', + '███', + ' █', + '███' + ], + '4': [ + '█ █', + '█ █', + '███', + ' █', + ' █' + ], + '5': [ + '███', + '█ ', + '███', + ' █', + '███' + ], + '6': [ + '███', + '█ ', + '███', + '█ █', + '███' + ], + '7': [ + '███', + ' █', + ' █', + ' █', + ' █' + ], + '8': [ + '███', + '█ █', + '███', + '█ █', + '███' + ], + '9': [ + '███', + '█ █', + '███', + ' █', + '███' + ], + ':': [ + ' ', + ' █ ', + ' ', + ' █ ', + ' ' + ] +}; + +function getBigDigitLines(char: string, useUnicode: boolean): string[] { + const lines = BIG_DIGITS[char] || BIG_DIGITS['0']; + return lines.map(line => useUnicode ? line : line.replace(/█/g, '#')); +} + +// ── Dynamic Color Logic ── + +function getDynamicColor(value: number): Color { + if (value <= 0.25) { + return { type: 'hex', hex: '#ef4444' }; // Red + } else if (value <= 0.50) { + return { type: 'hex', hex: '#f97316' }; // Orange + } else if (value <= 0.75) { + return { type: 'hex', hex: '#eab308' }; // Yellow + } else { + return { type: 'hex', hex: '#22c55e' }; // Green + } +} + +// ── BigTimer Widget ── + +class BigTimer extends Widget { + private _timeStr = '25:00'; + + constructor(style: Partial