spec-driven-agility 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 +3 -2
- package/package.json +1 -1
- package/src/animation.js +176 -90
package/README.md
CHANGED
|
@@ -59,8 +59,9 @@ version Muestra la versión.
|
|
|
59
59
|
help Muestra la ayuda.
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
`sda init`
|
|
63
|
-
|
|
62
|
+
`sda init` muestra una **planta pixel-art en verdes oscuros** hecha con bloques de mosaico
|
|
63
|
+
(`█▓▒░`); el patrón de sombra se desplaza suavemente en bucle, **sin apagarse**, hasta que presionas
|
|
64
|
+
ENTER. En CI o scripts se omite sola; también puedes forzarlo con `sda init --no-animation`.
|
|
64
65
|
|
|
65
66
|
## Filosofía
|
|
66
67
|
|
package/package.json
CHANGED
package/src/animation.js
CHANGED
|
@@ -1,72 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
hide: '\x1b[?25l',
|
|
64
|
-
show: '\x1b[?25h',
|
|
65
|
-
up: (n) => `\x1b[${n}A`,
|
|
66
|
-
clear: '\x1b[2K',
|
|
67
|
-
};
|
|
1
|
+
// Planta pixel-art en verdes oscuros. El mosaico de sombras se desplaza
|
|
2
|
+
// suavemente en bucle continuo hasta que el usuario presiona ENTER.
|
|
3
|
+
// La planta NUNCA se apaga ni se vuelve transparente: el cuerpo siempre
|
|
4
|
+
// queda visible (verde medio/oscuro) y solo cambia el patrón de sombra.
|
|
5
|
+
// Sin dependencias.
|
|
6
|
+
|
|
7
|
+
const W = 27;
|
|
8
|
+
const H = 15;
|
|
9
|
+
|
|
10
|
+
// Niveles: 0 = vacío, 1 = borde, 2 = anillo, 3 = interior.
|
|
11
|
+
function buildLevels() {
|
|
12
|
+
const filled = Array.from({ length: H }, () => Array(W).fill(false));
|
|
13
|
+
|
|
14
|
+
const ell = (cx, cy, rx, ry, on) => {
|
|
15
|
+
for (let y = 0; y < H; y += 1) {
|
|
16
|
+
for (let x = 0; x < W; x += 1) {
|
|
17
|
+
const dx = (x - cx) / rx;
|
|
18
|
+
const dy = (y - cy) / ry;
|
|
19
|
+
if (dx * dx + dy * dy <= 1) filled[y][x] = on;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Dos hojas.
|
|
25
|
+
ell(7.5, 6, 7.5, 5.5, true);
|
|
26
|
+
ell(19.5, 6, 7.5, 5.5, true);
|
|
27
|
+
|
|
28
|
+
// V central entre las hojas.
|
|
29
|
+
for (let y = 2; y <= 9; y += 1) {
|
|
30
|
+
const half = Math.max(0, (9 - y) * 0.7);
|
|
31
|
+
for (let x = Math.floor(13.5 - half); x <= Math.ceil(13.5 + half); x += 1) {
|
|
32
|
+
if (filled[y] && filled[y][x] !== undefined) filled[y][x] = false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Tallo.
|
|
37
|
+
for (let y = 9; y <= 12; y += 1) {
|
|
38
|
+
for (let x = 13; x <= 14; x += 1) filled[y][x] = true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Montículo.
|
|
42
|
+
ell(13.5, 17, 12, 5, true);
|
|
43
|
+
|
|
44
|
+
const isFilled = (x, y) => x >= 0 && x < W && y >= 0 && y < H && filled[y][x];
|
|
45
|
+
const isEdge = (x, y) =>
|
|
46
|
+
[[1, 0], [-1, 0], [0, 1], [0, -1]].some(([dx, dy]) => !isFilled(x + dx, y + dy));
|
|
47
|
+
|
|
48
|
+
const levels = Array.from({ length: H }, () => Array(W).fill(0));
|
|
49
|
+
for (let y = 0; y < H; y += 1) {
|
|
50
|
+
for (let x = 0; x < W; x += 1) {
|
|
51
|
+
if (!filled[y][x]) continue;
|
|
52
|
+
if (isEdge(x, y)) {
|
|
53
|
+
levels[y][x] = 1;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const nearEdge = [[1, 0], [-1, 0], [0, 1], [0, -1]].some(([dx, dy]) => isEdge(x + dx, y + dy));
|
|
57
|
+
levels[y][x] = nearEdge ? 2 : 3;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return levels;
|
|
62
|
+
}
|
|
68
63
|
|
|
69
|
-
const
|
|
64
|
+
const LEVELS = buildLevels();
|
|
65
|
+
|
|
66
|
+
const RESET = '\x1b[0m';
|
|
67
|
+
const HIDE = '\x1b[?25l';
|
|
68
|
+
const SHOW = '\x1b[?25h';
|
|
69
|
+
const CLEAR = '\x1b[2K';
|
|
70
|
+
const BLOCK_HEIGHT = H + 1; // sprite + línea del prompt
|
|
71
|
+
|
|
72
|
+
// Verdes oscuros: cuerpo siempre visible (40/34), borde más oscuro (28/22).
|
|
73
|
+
const COLOR = {
|
|
74
|
+
'░': '\x1b[38;5;22m',
|
|
75
|
+
'▒': '\x1b[38;5;28m',
|
|
76
|
+
'▓': '\x1b[38;5;34m',
|
|
77
|
+
'█': '\x1b[38;5;40m',
|
|
78
|
+
};
|
|
79
|
+
const PROMPT_COLOR = '\x1b[38;5;28m';
|
|
80
|
+
const PROMPT = ' Presiona ENTER para continuar... ';
|
|
70
81
|
|
|
71
82
|
function sleep(ms) {
|
|
72
83
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -79,44 +90,119 @@ function canAnimate(stream) {
|
|
|
79
90
|
return true;
|
|
80
91
|
}
|
|
81
92
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
for (let line = 0; line < HEIGHT; line += 1) {
|
|
90
|
-
stream.write(`\r${ESC.clear}${FRAMES[frame][line]}\n`);
|
|
93
|
+
function lineFor(y, phase) {
|
|
94
|
+
let out = '';
|
|
95
|
+
for (let x = 0; x < W; x += 1) {
|
|
96
|
+
const level = LEVELS[y][x];
|
|
97
|
+
if (level === 0) {
|
|
98
|
+
out += ' ';
|
|
99
|
+
continue;
|
|
91
100
|
}
|
|
101
|
+
let ch;
|
|
102
|
+
if (level === 1) ch = '░';
|
|
103
|
+
else if (level === 2) ch = '▒';
|
|
104
|
+
else ch = (x + y + phase) % 2 === 0 ? '█' : '▓';
|
|
105
|
+
out += COLOR[ch] + ch + RESET;
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function drawFrame(stream, phase) {
|
|
111
|
+
for (let y = 0; y < H; y += 1) {
|
|
112
|
+
stream.write(`\r${CLEAR}${lineFor(y, phase)}\n`);
|
|
92
113
|
}
|
|
114
|
+
stream.write(`\r${CLEAR}${PROMPT_COLOR}${PROMPT}${RESET}\n`);
|
|
115
|
+
}
|
|
93
116
|
|
|
94
|
-
|
|
117
|
+
function erase(stream) {
|
|
118
|
+
stream.write(`\x1b[${BLOCK_HEIGHT}A`);
|
|
119
|
+
for (let i = 0; i < BLOCK_HEIGHT; i += 1) {
|
|
120
|
+
stream.write(`\r${CLEAR}\n`);
|
|
121
|
+
}
|
|
122
|
+
stream.write(`\x1b[${BLOCK_HEIGHT}A`);
|
|
95
123
|
}
|
|
96
124
|
|
|
97
|
-
function
|
|
125
|
+
async function drawLoop(stream, { frames, delay = 110, stopWhen } = {}) {
|
|
126
|
+
let first = true;
|
|
127
|
+
let frame = 0;
|
|
128
|
+
|
|
129
|
+
while (true) {
|
|
130
|
+
if (stopWhen && stopWhen()) break;
|
|
131
|
+
if (frames !== undefined && frame >= frames) break;
|
|
132
|
+
|
|
133
|
+
if (!first) stream.write(`\x1b[${BLOCK_HEIGHT}A`);
|
|
134
|
+
// La sombra se desplaza cada 3 frames: movimiento lento y continuo.
|
|
135
|
+
const phase = Math.floor(frame / 3) % 2;
|
|
136
|
+
drawFrame(stream, phase);
|
|
137
|
+
first = false;
|
|
138
|
+
frame += 1;
|
|
139
|
+
await sleep(delay);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function waitForKey(stdin) {
|
|
98
144
|
return new Promise((resolve) => {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
145
|
+
const onData = (key) => {
|
|
146
|
+
if (key === '\u0003') {
|
|
147
|
+
stdin.setRawMode(false);
|
|
148
|
+
stdin.pause();
|
|
149
|
+
stdin.removeListener('data', onData);
|
|
150
|
+
process.stdout.write(SHOW);
|
|
151
|
+
process.exit(130);
|
|
152
|
+
}
|
|
153
|
+
if (key === '\r' || key === '\n') {
|
|
154
|
+
stdin.setRawMode(false);
|
|
155
|
+
stdin.pause();
|
|
156
|
+
stdin.removeListener('data', onData);
|
|
157
|
+
resolve();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
stdin.setRawMode(true);
|
|
162
|
+
stdin.resume();
|
|
163
|
+
stdin.setEncoding('utf8');
|
|
164
|
+
stdin.on('data', onData);
|
|
104
165
|
});
|
|
105
166
|
}
|
|
106
167
|
|
|
107
168
|
/**
|
|
108
|
-
*
|
|
109
|
-
* Se omite
|
|
169
|
+
* Intro animada: planta pixel-art con sombra en movimiento hasta ENTER.
|
|
170
|
+
* Se omite en CI, salidas no interactivas o con `--no-animation`.
|
|
110
171
|
*/
|
|
111
|
-
export async function playIntro({
|
|
172
|
+
export async function playIntro({
|
|
173
|
+
enabled = true,
|
|
174
|
+
stream = process.stdout,
|
|
175
|
+
stdin = process.stdin,
|
|
176
|
+
frames,
|
|
177
|
+
} = {}) {
|
|
112
178
|
if (!enabled || !canAnimate(stream)) return false;
|
|
113
179
|
|
|
180
|
+
stream.write(HIDE);
|
|
181
|
+
|
|
114
182
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
183
|
+
if (frames !== undefined) {
|
|
184
|
+
await drawLoop(stream, { frames, delay: 80 });
|
|
185
|
+
erase(stream);
|
|
186
|
+
stream.write(SHOW);
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let stop = false;
|
|
191
|
+
const loop = drawLoop(stream, { stopWhen: () => stop });
|
|
192
|
+
|
|
193
|
+
if (stdin.isTTY) {
|
|
194
|
+
await waitForKey(stdin);
|
|
195
|
+
} else {
|
|
196
|
+
await sleep(2000);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
stop = true;
|
|
200
|
+
await loop;
|
|
201
|
+
erase(stream);
|
|
202
|
+
stream.write(SHOW);
|
|
117
203
|
return true;
|
|
118
204
|
} catch {
|
|
119
|
-
stream.write(
|
|
205
|
+
stream.write(SHOW);
|
|
120
206
|
return false;
|
|
121
207
|
}
|
|
122
208
|
}
|