@getparallel/parx 0.4.0 → 0.4.2

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/dist/ui.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { animacion, c, capacidades, SIMBOLOS } from "./marca.js";
2
- import { t } from "./textos.js";
2
+ import { cuantos, t } from "./textos.js";
3
3
  import { trozos } from "./diff.js";
4
4
  import { anchoDe, envolver, recortar, recortarMedio, rellenar, sinColor } from "./texto.js";
5
5
  import { anchoUtil, bloqueDeCierre, bloqueDeLinea, bloqueDeTexto, filaDeTrabajo, MARGEN, nuevoTrabajo, opcionesDePregunta, ponerTextoDeTrabajo, } from "./tui.js";
@@ -37,8 +37,11 @@ export function bloqueDeAccion(verbo, objeto, nota = '') {
37
37
  return [`${' '.repeat(MARGEN)}${punto} ${v}${obj}${conNota && nota ? ` ${c.gris(nota)}` : ''}`];
38
38
  };
39
39
  }
40
+ const RELLENO_DE_TESTS = /^[\s\W]*(skipped|todo|cancelled|suites|duration(_ms)?|start at|snapshots)\b[\s:]*[\d.]*\s*(ms|s)?\s*$/i;
40
41
  export class Pantalla {
41
42
  rl;
43
+ ultimoGrupo = null;
44
+ enBlanco = true;
42
45
  superficie = null;
43
46
  esperaActiva = null;
44
47
  trabajoEnLinea = null;
@@ -55,6 +58,9 @@ export class Pantalla {
55
58
  fijarSuperficie(s) {
56
59
  this.superficie = s;
57
60
  }
61
+ get conSuperficie() {
62
+ return this.superficie !== null;
63
+ }
58
64
  conCarril(b) {
59
65
  const k = this.carril;
60
66
  if (!k)
@@ -66,8 +72,24 @@ export class Pantalla {
66
72
  .map((l) => `${' '.repeat(MARGEN)}${marca} ${l.startsWith(' '.repeat(MARGEN)) ? l.slice(MARGEN) : l}`);
67
73
  };
68
74
  }
69
- bloque(b) {
70
- const bc = this.conCarril(b);
75
+ marcarGrupo(g) {
76
+ this.ultimoGrupo = g;
77
+ }
78
+ terminaEnBlanco() {
79
+ return this.superficie ? this.superficie.terminaEnBlanco() : this.enBlanco;
80
+ }
81
+ conAire(b, grupo) {
82
+ const cambia = this.ultimoGrupo !== null && this.ultimoGrupo !== grupo;
83
+ this.ultimoGrupo = grupo;
84
+ if (this.carril || !cambia || this.terminaEnBlanco())
85
+ return b;
86
+ return (ancho) => {
87
+ const l = b(ancho);
88
+ return l[0]?.trim() === '' ? l : ['', ...l];
89
+ };
90
+ }
91
+ bloque(b, grupo = 'otro') {
92
+ const bc = this.conCarril(this.conAire(b, grupo));
71
93
  if (this.superficie) {
72
94
  this.superficie.anadir(bc);
73
95
  return;
@@ -76,13 +98,21 @@ export class Pantalla {
76
98
  if (enLinea)
77
99
  process.stdout.write('\r\x1b[2K');
78
100
  const ancho = Math.max(20, process.stdout.columns || capacidades().ancho || 80);
79
- for (const l of bc(ancho))
101
+ const lineas = bc(ancho);
102
+ for (const l of lineas)
80
103
  process.stdout.write(`${l}\n`);
104
+ if (lineas.length)
105
+ this.enBlanco = lineas[lineas.length - 1].trim() === '';
81
106
  if (enLinea)
82
107
  this.pintarEnLinea();
83
108
  }
84
- escribir(linea = '') {
85
- this.bloque(bloqueDeTexto(linea.replace(/^ {1,2}/, '')));
109
+ escribir(linea = '', grupo = 'nota') {
110
+ if (!linea.trim()) {
111
+ if (!this.terminaEnBlanco() && !this.carril)
112
+ this.bloque(() => [''], this.ultimoGrupo ?? 'nota');
113
+ return;
114
+ }
115
+ this.bloque(bloqueDeTexto(linea.replace(/^ {1,2}/, '')), grupo);
86
116
  }
87
117
  lecturas = null;
88
118
  accion(verbo, objeto, nota = '') {
@@ -90,20 +120,27 @@ export class Pantalla {
90
120
  const l = this.lecturas;
91
121
  if (l && this.superficie.ultimoBloque() === l.bloque) {
92
122
  l.objetos.push(objeto);
93
- const b = this.conCarril(bloqueDeAccion(verbo, l.objetos.join(', '), `${l.objetos.length} files`));
123
+ const fila = bloqueDeAccion(verbo, l.objetos.join(', '), `${l.objetos.length} files`);
124
+ const b = this.conCarril(l.aire ? (ancho) => ['', ...fila(ancho)] : fila);
94
125
  l.bloque = b;
95
126
  this.superficie.reemplazarUltimo(b);
96
127
  return;
97
128
  }
98
- const b = this.conCarril(bloqueDeAccion(verbo, objeto, nota));
99
- this.lecturas = { bloque: b, objetos: [objeto] };
129
+ const fila = bloqueDeAccion(verbo, objeto, nota);
130
+ const conAire = this.conAire(fila, 'accion');
131
+ const b = this.conCarril(conAire);
132
+ this.lecturas = { bloque: b, objetos: [objeto], aire: conAire !== fila && !this.carril };
100
133
  this.superficie.anadir(b);
101
134
  return;
102
135
  }
103
- this.bloque(bloqueDeAccion(verbo, objeto, nota));
136
+ this.bloque(bloqueDeAccion(verbo, objeto, nota), 'accion');
104
137
  }
105
138
  salidaDeComando(salida, maxLineas = 3) {
106
- const lineas = salida.replace(/\r/g, '').trimEnd().split('\n').filter((l) => l.trim() !== '');
139
+ const lineas = salida
140
+ .replace(/\r/g, '')
141
+ .trimEnd()
142
+ .split('\n')
143
+ .filter((l) => l.trim() !== '' && !RELLENO_DE_TESTS.test(l));
107
144
  if (!lineas.length)
108
145
  return;
109
146
  const ultimas = lineas.slice(-maxLineas);
@@ -113,23 +150,23 @@ export class Pantalla {
113
150
  const util = anchoUtil(ancho) - s;
114
151
  const out = [];
115
152
  if (sobran > 0)
116
- out.push(`${' '.repeat(MARGEN + s)}${c.tenue(c.gris(`… ${sobran.toLocaleString('en-US')} +`))}`);
153
+ out.push(`${' '.repeat(MARGEN + s)}${c.tenue(c.gris(`… ${cuantos(sobran, 'more line', 'more lines')} above`))}`);
117
154
  for (const l of ultimas)
118
155
  out.push(`${' '.repeat(MARGEN + s)}${c.tenue(recortar(sinColor(l).replace(/\t/g, ' '), util))}`);
119
156
  return out;
120
- });
157
+ }, 'accion');
121
158
  }
122
159
  detalle(texto, error = false) {
123
- this.bloque((ancho) => [`${' '.repeat(MARGEN + sangriaDeDetalle())}${recortar(error ? c.error(`${SIMBOLOS.falla} ${texto}`) : c.gris(texto), anchoUtil(ancho) - sangriaDeDetalle())}`]);
160
+ this.bloque((ancho) => [`${' '.repeat(MARGEN + sangriaDeDetalle())}${recortar(error ? c.error(`${SIMBOLOS.falla} ${texto}`) : c.gris(texto), anchoUtil(ancho) - sangriaDeDetalle())}`], 'accion');
124
161
  }
125
162
  aviso(texto) {
126
- this.bloque(bloqueDeTexto(`${c.aviso('!')} ${texto}`, ' '));
163
+ this.bloque(bloqueDeTexto(`${c.aviso('!')} ${texto}`, ' '), 'aviso');
127
164
  }
128
165
  error(texto) {
129
- this.bloque(bloqueDeTexto(`${c.error(SIMBOLOS.falla)} ${texto}`, ' '));
166
+ this.bloque(bloqueDeTexto(`${c.error(SIMBOLOS.falla)} ${texto}`, ' '), 'error');
130
167
  }
131
168
  cierre(texto) {
132
- this.bloque(bloqueDeCierre(texto, c.ok(SIMBOLOS.hecho)));
169
+ this.bloque(bloqueDeCierre(texto, c.ok(SIMBOLOS.hecho)), 'cierre');
133
170
  }
134
171
  trabajoPropio() {
135
172
  return this.carril ? this.carril.trabajo : this.trabajoEnLinea;
@@ -204,7 +241,7 @@ export class Pantalla {
204
241
  let pintadas = 0;
205
242
  for (const l of visibles) {
206
243
  if (pintadas >= max) {
207
- out.push(`${pre}${c.tenue(`… ${visibles.length - max} +`)}`);
244
+ out.push(`${pre}${c.tenue(`… ${cuantos(visibles.length - max, 'more line', 'more lines')}`)}`);
208
245
  break;
209
246
  }
210
247
  pintadas++;
@@ -222,15 +259,22 @@ export class Pantalla {
222
259
  out.push(`${pre}${c.tenue(num)} ${c.tenue(texto)}`);
223
260
  }
224
261
  return out;
225
- });
262
+ }, 'accion');
226
263
  }
227
264
  async preguntar(pregunta, o = {}) {
228
265
  const tipo = o.tipo ?? 'normal';
229
266
  if (o.aviso)
230
267
  this.aviso(o.aviso);
231
268
  const texto = this.carril ? `${t('carriles.carril', { n: this.carril.numero })}: ${pregunta}` : pregunta;
232
- if (this.superficie)
233
- return this.superficie.preguntar(texto, tipo);
269
+ if (this.superficie) {
270
+ const r = await this.superficie.preguntar(texto, tipo);
271
+ if (r !== 'si' && tipo !== 'bypass') {
272
+ const o2 = opcionesDePregunta(tipo);
273
+ const etiqueta = o2.opciones[o2.valores.indexOf(r)] ?? t('tui.no');
274
+ this.bloque(bloqueDeTexto(`${c.gris('?')} ${texto} ${c.gris('→')} ${r === 'no' ? c.gris(etiqueta) : c.marca(etiqueta)}`, ' '), 'aviso');
275
+ }
276
+ return r;
277
+ }
234
278
  this.pausarLinea();
235
279
  if (!this.tty || !this.rl) {
236
280
  this.aviso(`${texto} → ${t('aviso.rechazado')}`);
@@ -281,7 +325,7 @@ export class Pantalla {
281
325
  out.push(`${pre}${p}`);
282
326
  }
283
327
  return out;
284
- });
328
+ }, 'texto');
285
329
  }
286
330
  }
287
331
  export { bloqueDeLinea };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getparallel/parx",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "parx: the coding agent of Parallel in your terminal. Reads and edits your project, runs commands and tests, and does coding tasks end to end. Mac, Windows and Linux.",
5
5
  "keywords": [
6
6
  "parx",