spec-driven-agility 0.6.0 → 0.6.1
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 +3 -1
- package/package.json +1 -1
- package/src/animation.js +158 -39
package/README.md
CHANGED
|
@@ -64,7 +64,9 @@ help Muestra la ayuda.
|
|
|
64
64
|
|
|
65
65
|
`sda init` muestra una **planta pixel-art en verdes oscuros** hecha con bloques de mosaico
|
|
66
66
|
(`█▓▒░`); el patrón de sombra se desplaza suavemente en bucle, **sin apagarse**, hasta que presionas
|
|
67
|
-
ENTER.
|
|
67
|
+
ENTER. La intro es responsiva: si la terminal no alcanza el ancho para la planta, muestra solo el
|
|
68
|
+
texto de bienvenida y los comandos; si es demasiado pequeña, se omite y la instalación continúa
|
|
69
|
+
directamente. En CI o scripts se omite sola; también puedes forzarlo con `sda init --no-animation`.
|
|
68
70
|
|
|
69
71
|
## Filosofía
|
|
70
72
|
|
package/package.json
CHANGED
package/src/animation.js
CHANGED
|
@@ -81,7 +81,9 @@ const RESET = '\x1b[0m';
|
|
|
81
81
|
const HIDE = '\x1b[?25l';
|
|
82
82
|
const SHOW = '\x1b[?25h';
|
|
83
83
|
const CLEAR = '\x1b[2K';
|
|
84
|
-
const BLOCK_HEIGHT = H; //
|
|
84
|
+
const BLOCK_HEIGHT = H; // alto del bloque en modo frames (pruebas)
|
|
85
|
+
const ENTER_ALT = '\x1b[?1049h';
|
|
86
|
+
const LEAVE_ALT = '\x1b[?1049l';
|
|
85
87
|
|
|
86
88
|
// Verdes oscuros: cuerpo siempre visible (40/34), borde más oscuro (28/22).
|
|
87
89
|
const COLOR = {
|
|
@@ -125,6 +127,28 @@ const PANEL = {
|
|
|
125
127
|
14: [{ text: 'Press Enter to continue...', color: PROMPT_COLOR }],
|
|
126
128
|
};
|
|
127
129
|
|
|
130
|
+
// Layouts responsivos: full (planta + panel), compact (solo texto) o skip.
|
|
131
|
+
const PANEL_WIDTH = Math.max(
|
|
132
|
+
...Object.values(PANEL).map((row) => row.reduce((width, part) => width + part.text.length, 0)),
|
|
133
|
+
);
|
|
134
|
+
const COMPACT_ROWS = Object.keys(PANEL)
|
|
135
|
+
.map(Number)
|
|
136
|
+
.sort((a, b) => a - b);
|
|
137
|
+
|
|
138
|
+
const FULL_MIN_COLUMNS = W + PANEL_GAP.length + PANEL_WIDTH + 1;
|
|
139
|
+
const FULL_MIN_ROWS = H;
|
|
140
|
+
const COMPACT_MIN_COLUMNS = PANEL_WIDTH + 1;
|
|
141
|
+
const COMPACT_MIN_ROWS = COMPACT_ROWS.length + 1;
|
|
142
|
+
|
|
143
|
+
function detectLayout(stream) {
|
|
144
|
+
const columns = stream && stream.columns;
|
|
145
|
+
const rows = stream && stream.rows;
|
|
146
|
+
if (!columns || !rows) return 'skip';
|
|
147
|
+
if (columns >= FULL_MIN_COLUMNS && rows >= FULL_MIN_ROWS) return 'full';
|
|
148
|
+
if (columns >= COMPACT_MIN_COLUMNS && rows >= COMPACT_MIN_ROWS) return 'compact';
|
|
149
|
+
return 'skip';
|
|
150
|
+
}
|
|
151
|
+
|
|
128
152
|
function sleep(ms) {
|
|
129
153
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
130
154
|
}
|
|
@@ -136,6 +160,16 @@ function canAnimate(stream) {
|
|
|
136
160
|
return true;
|
|
137
161
|
}
|
|
138
162
|
|
|
163
|
+
function formatPanelRow(y) {
|
|
164
|
+
const row = PANEL[y];
|
|
165
|
+
if (!row) return '';
|
|
166
|
+
let out = '';
|
|
167
|
+
for (const part of row) {
|
|
168
|
+
out += part.color ? `${part.color}${part.text}${RESET}` : part.text;
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
|
|
139
173
|
function lineFor(y, phase) {
|
|
140
174
|
let out = '';
|
|
141
175
|
for (let x = 0; x < W; x += 1) {
|
|
@@ -151,18 +185,22 @@ function lineFor(y, phase) {
|
|
|
151
185
|
out += COLOR[ch] + ch + RESET;
|
|
152
186
|
}
|
|
153
187
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
out += PANEL_GAP;
|
|
157
|
-
for (const part of panel) {
|
|
158
|
-
out += part.color ? `${part.color}${part.text}${RESET}` : part.text;
|
|
159
|
-
}
|
|
188
|
+
if (PANEL[y]) {
|
|
189
|
+
out += `${PANEL_GAP}${formatPanelRow(y)}`;
|
|
160
190
|
}
|
|
161
191
|
|
|
162
192
|
return out;
|
|
163
193
|
}
|
|
164
194
|
|
|
165
|
-
|
|
195
|
+
// Modo full: posicionamiento absoluto dentro del buffer alternativo.
|
|
196
|
+
function drawFrameAbsolute(stream, phase) {
|
|
197
|
+
for (let y = 0; y < H; y += 1) {
|
|
198
|
+
stream.write(`\x1b[${y + 1};1H${CLEAR}${lineFor(y, phase)}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Modo frames (pruebas): salida secuencial reutilizando el borrado por cursor.
|
|
203
|
+
function drawFrameSequential(stream, phase) {
|
|
166
204
|
for (let y = 0; y < H; y += 1) {
|
|
167
205
|
stream.write(`\r${CLEAR}${lineFor(y, phase)}\n`);
|
|
168
206
|
}
|
|
@@ -176,38 +214,49 @@ function erase(stream) {
|
|
|
176
214
|
stream.write(`\x1b[${BLOCK_HEIGHT}A`);
|
|
177
215
|
}
|
|
178
216
|
|
|
179
|
-
async function drawLoop(
|
|
217
|
+
async function drawLoop(
|
|
218
|
+
stream,
|
|
219
|
+
{ frames, delay = 110, stopWhen, render, cursorUp = false, checkLayout = false } = {},
|
|
220
|
+
) {
|
|
180
221
|
let first = true;
|
|
181
222
|
let frame = 0;
|
|
182
223
|
|
|
183
224
|
while (true) {
|
|
184
225
|
if (stopWhen && stopWhen()) break;
|
|
185
226
|
if (frames !== undefined && frame >= frames) break;
|
|
227
|
+
if (checkLayout && detectLayout(stream) !== 'full') return { aborted: true };
|
|
186
228
|
|
|
187
|
-
if (!first) stream.write(`\x1b[${BLOCK_HEIGHT}A`);
|
|
229
|
+
if (!first && cursorUp) stream.write(`\x1b[${BLOCK_HEIGHT}A`);
|
|
188
230
|
// La sombra se desplaza cada 3 frames: movimiento lento y continuo.
|
|
189
231
|
const phase = Math.floor(frame / 3) % 2;
|
|
190
|
-
|
|
232
|
+
render(stream, phase);
|
|
191
233
|
first = false;
|
|
192
234
|
frame += 1;
|
|
193
235
|
await sleep(delay);
|
|
194
236
|
}
|
|
237
|
+
|
|
238
|
+
return { aborted: false };
|
|
195
239
|
}
|
|
196
240
|
|
|
197
|
-
function
|
|
241
|
+
function restoreTerminalOnAbort(stream, cleanup, fromAltScreen = false) {
|
|
242
|
+
cleanup();
|
|
243
|
+
stream.write(`${fromAltScreen ? LEAVE_ALT : ''}${SHOW}`);
|
|
244
|
+
process.exit(130);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Modo compact: texto estático y espera de ENTER.
|
|
248
|
+
function waitForKey(stdin, stream) {
|
|
198
249
|
return new Promise((resolve) => {
|
|
250
|
+
const cleanup = () => {
|
|
251
|
+
stdin.setRawMode(false);
|
|
252
|
+
stdin.pause();
|
|
253
|
+
stdin.removeListener('data', onData);
|
|
254
|
+
};
|
|
255
|
+
|
|
199
256
|
const onData = (key) => {
|
|
200
|
-
if (key === '\u0003')
|
|
201
|
-
stdin.setRawMode(false);
|
|
202
|
-
stdin.pause();
|
|
203
|
-
stdin.removeListener('data', onData);
|
|
204
|
-
process.stdout.write(SHOW);
|
|
205
|
-
process.exit(130);
|
|
206
|
-
}
|
|
257
|
+
if (key === '\u0003') restoreTerminalOnAbort(stream, cleanup);
|
|
207
258
|
if (key === '\r' || key === '\n') {
|
|
208
|
-
|
|
209
|
-
stdin.pause();
|
|
210
|
-
stdin.removeListener('data', onData);
|
|
259
|
+
cleanup();
|
|
211
260
|
resolve();
|
|
212
261
|
}
|
|
213
262
|
};
|
|
@@ -219,9 +268,59 @@ function waitForKey(stdin) {
|
|
|
219
268
|
});
|
|
220
269
|
}
|
|
221
270
|
|
|
271
|
+
// Modo full: espera ENTER, Ctrl+C o un resize que ya no permita el layout full.
|
|
272
|
+
function waitForExit(stdin, stream) {
|
|
273
|
+
return new Promise((resolve) => {
|
|
274
|
+
let poll;
|
|
275
|
+
|
|
276
|
+
const cleanup = () => {
|
|
277
|
+
clearInterval(poll);
|
|
278
|
+
stdin.setRawMode(false);
|
|
279
|
+
stdin.pause();
|
|
280
|
+
stdin.removeListener('data', onData);
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const onData = (key) => {
|
|
284
|
+
if (key === '\u0003') restoreTerminalOnAbort(stream, cleanup, true);
|
|
285
|
+
if (key === '\r' || key === '\n') {
|
|
286
|
+
cleanup();
|
|
287
|
+
resolve('enter');
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
poll = setInterval(() => {
|
|
292
|
+
if (detectLayout(stream) !== 'full') {
|
|
293
|
+
cleanup();
|
|
294
|
+
resolve('resize');
|
|
295
|
+
}
|
|
296
|
+
}, 250);
|
|
297
|
+
|
|
298
|
+
stdin.setRawMode(true);
|
|
299
|
+
stdin.resume();
|
|
300
|
+
stdin.setEncoding('utf8');
|
|
301
|
+
stdin.on('data', onData);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async function runCompact(stream, stdin) {
|
|
306
|
+
for (const y of COMPACT_ROWS) {
|
|
307
|
+
stream.write(`${formatPanelRow(y)}\n`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (stdin.isTTY) {
|
|
311
|
+
await waitForKey(stdin, stream);
|
|
312
|
+
} else {
|
|
313
|
+
await sleep(1500);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
|
|
222
319
|
/**
|
|
223
320
|
* Intro animada: planta pixel-art con sombra en movimiento hasta ENTER.
|
|
224
|
-
*
|
|
321
|
+
* Responsiva: sin ancho suficiente muestra solo el texto; si es demasiado
|
|
322
|
+
* pequeña se omite y la instalación continúa directamente. También se omite
|
|
323
|
+
* en CI, salidas no interactivas o con `--no-animation`.
|
|
225
324
|
*/
|
|
226
325
|
export async function playIntro({
|
|
227
326
|
enabled = true,
|
|
@@ -231,32 +330,52 @@ export async function playIntro({
|
|
|
231
330
|
} = {}) {
|
|
232
331
|
if (!enabled || !canAnimate(stream)) return false;
|
|
233
332
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
333
|
+
if (frames !== undefined) {
|
|
334
|
+
stream.write(HIDE);
|
|
335
|
+
try {
|
|
336
|
+
await drawLoop(stream, {
|
|
337
|
+
frames,
|
|
338
|
+
delay: 80,
|
|
339
|
+
render: drawFrameSequential,
|
|
340
|
+
cursorUp: true,
|
|
341
|
+
});
|
|
239
342
|
erase(stream);
|
|
240
343
|
stream.write(SHOW);
|
|
241
344
|
return true;
|
|
345
|
+
} catch {
|
|
346
|
+
stream.write(SHOW);
|
|
347
|
+
return false;
|
|
242
348
|
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const layout = detectLayout(stream);
|
|
352
|
+
if (layout === 'skip') return false;
|
|
353
|
+
if (layout === 'compact') return runCompact(stream, stdin);
|
|
243
354
|
|
|
355
|
+
stream.write(`${ENTER_ALT}${HIDE}\x1b[2J`);
|
|
356
|
+
|
|
357
|
+
try {
|
|
244
358
|
let stop = false;
|
|
245
|
-
const loop = drawLoop(stream, {
|
|
359
|
+
const loop = drawLoop(stream, {
|
|
360
|
+
stopWhen: () => stop,
|
|
361
|
+
render: drawFrameAbsolute,
|
|
362
|
+
checkLayout: true,
|
|
363
|
+
});
|
|
246
364
|
|
|
247
|
-
|
|
248
|
-
await
|
|
249
|
-
|
|
250
|
-
await sleep(2000);
|
|
251
|
-
}
|
|
365
|
+
const outcome = stdin.isTTY
|
|
366
|
+
? await waitForExit(stdin, stream)
|
|
367
|
+
: await sleep(2000).then(() => 'timeout');
|
|
252
368
|
|
|
253
369
|
stop = true;
|
|
254
|
-
await loop;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return true;
|
|
370
|
+
const { aborted } = await loop;
|
|
371
|
+
stream.write(LEAVE_ALT + SHOW);
|
|
372
|
+
|
|
373
|
+
if (!aborted && outcome !== 'resize') return true;
|
|
374
|
+
|
|
375
|
+
if (detectLayout(stream) === 'compact') return runCompact(stream, stdin);
|
|
376
|
+
return false;
|
|
258
377
|
} catch {
|
|
259
|
-
stream.write(SHOW);
|
|
378
|
+
stream.write(LEAVE_ALT + SHOW);
|
|
260
379
|
return false;
|
|
261
380
|
}
|
|
262
381
|
}
|