@valyrianjs/terminal 0.1.0 → 0.1.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.
@@ -1,20 +1,20 @@
1
1
  # Session Runtime
2
2
 
3
- Esta guia documenta el runtime interactivo de `valyrianjs-terminal`: cuando conviene usar `mountTerminal()`, como configurar una sesion y que capacidades expone `TerminalSession` durante su ciclo de vida.
3
+ This guide documents the interactive runtime of `valyrianjs-terminal`: when to use `mountTerminal()`, how to configure a session, and which capabilities `TerminalSession` exposes during its lifecycle.
4
4
 
5
- Si vienes desde cero, lee antes `docs/core-concepts.md`. Para el modelo general de interaccion por primitiva, consulta `docs/interaction-model.md`. Aqui el foco es operativo: montaje, rerender, streams, foco, teclado, clipboard y mouse.
5
+ If you are starting from scratch, read `docs/core-concepts.md` first. For the general per-primitive interaction model, see `docs/interaction-model.md`. The focus here is operational: mounting, rerendering, streams, focus, keyboard, clipboard, and mouse.
6
6
 
7
- ## Cuando usar `mountTerminal()`
7
+ ## When to use `mountTerminal()`
8
8
 
9
- Usa `mountTerminal()` cuando necesites una sesion viva que:
9
+ Use `mountTerminal()` when you need a live session that:
10
10
 
11
- - reevalua el arbol al cambiar estado externo
12
- - mantiene foco entre renders
13
- - despacha teclado por sesion
14
- - conecta `stdin` y `stdout`
15
- - responde a coordenadas y eventos de mouse
11
+ - reevaluates the tree when external state changes
12
+ - preserves focus across renders
13
+ - dispatches keyboard input per session
14
+ - connects `stdin` and `stdout`
15
+ - responds to coordinates and mouse events
16
16
 
17
- Si solo quieres inspeccionar layout, generar snapshots o producir una salida estatica, `renderTerminal()` sigue siendo la opcion mas simple.
17
+ If you only want to inspect layout, generate snapshots, or produce static output, `renderTerminal()` is still the simplest option.
18
18
 
19
19
  ```tsx
20
20
  /** @jsx v */
@@ -47,17 +47,17 @@ console.log(session.output());
47
47
 
48
48
  ## `TerminalMountOptions`
49
49
 
50
- `mountTerminal(input, options?)` acepta un `TerminalMountOptions` con cuatro puntos de integracion:
50
+ `mountTerminal(input, options?)` accepts `TerminalMountOptions` with four integration points:
51
51
 
52
52
  ### `ansi?: boolean`
53
53
 
54
- Activa salida ANSI incremental hacia `stdout`. `session.ansiOutput()` sigue disponible aunque no actives esta opcion; lo que cambia es la escritura automatica de la sesion cuando hace rerender. Si no lo activas, la salida principal enviada a `stdout` es texto plano.
54
+ Enables incremental ANSI output to `stdout`. `session.ansiOutput()` is still available even if you do not enable this option; what changes is the session's automatic write behavior when it rerenders. If you do not enable it, the primary output written to `stdout` is plain text.
55
55
 
56
56
  ### `clipboard?: TerminalClipboardAdapter | false`
57
57
 
58
- - si pasas un adapter, la sesion usa `readText()` y `writeText()` cuando ejecuta atajos como `CTRL_C` o `CTRL_V`
59
- - si pasas `false`, desactivas la integracion con clipboard del sistema
60
- - aun con `clipboard: false`, `session.clipboard()` y `session.setClipboard()` siguen funcionando como buffer de la sesion
58
+ - if you pass an adapter, the session uses `readText()` and `writeText()` when handling shortcuts such as `CTRL_C` or `CTRL_V`
59
+ - if you pass `false`, system clipboard integration is disabled
60
+ - even with `clipboard: false`, `session.clipboard()` and `session.setClipboard()` still work as the session buffer
61
61
 
62
62
  ```tsx
63
63
  /** @jsx v */
@@ -95,21 +95,21 @@ session.setClipboard("fallback value");
95
95
 
96
96
  ### `stdin?`
97
97
 
98
- Stream de entrada para teclado y mouse. La sesion se suscribe a `data`, intenta activar `raw mode` si existe `setRawMode(true)` y llama `resume()` si el stream lo soporta.
98
+ Input stream for keyboard and mouse. The session subscribes to `data`, tries to enable raw mode with `setRawMode(true)` if available, and calls `resume()` if the stream supports it.
99
99
 
100
- Contrato esperado:
100
+ Expected contract:
101
101
 
102
- - `on("data", listener)` obligatorio
103
- - `off(...)` o `removeListener(...)` opcional para cleanup
104
- - `setRawMode?(boolean)` opcional
105
- - `resume?()` y `pause?()` opcionales
102
+ - `on("data", listener)` is required
103
+ - `off(...)` or `removeListener(...)` is optional for cleanup
104
+ - `setRawMode?(boolean)` is optional
105
+ - `resume?()` and `pause?()` are optional
106
106
 
107
107
  ### `stdout?`
108
108
 
109
- Destino de escritura para la salida producida en cada rerender.
109
+ Write target for the output produced on each rerender.
110
110
 
111
- - con `ansi: false`, escribe texto plano
112
- - con `ansi: true`, escribe diffs ANSI incrementales
111
+ - with `ansi: false`, writes plain text
112
+ - with `ansi: true`, writes incremental ANSI diffs
113
113
 
114
114
  ```tsx
115
115
  /** @jsx v */
@@ -132,21 +132,21 @@ const session = mountTerminal(app, {
132
132
  });
133
133
  ```
134
134
 
135
- ## Lifecycle de `TerminalSession`
135
+ ## `TerminalSession` lifecycle
136
136
 
137
- La sesion mantiene un frame actual, una salida actual y el estado interactivo asociado al arbol enfocable. El ciclo practico es:
137
+ The session keeps a current frame, a current output, and the interactive state associated with the focusable tree. In practice, the cycle is:
138
138
 
139
- 1. montar con `mountTerminal()`
140
- 2. leer con `output()` o `ansiOutput()`
141
- 3. mutar estado externo o despachar interacciones
142
- 4. rerender con `update()` o mediante eventos que ya disparan rerender
143
- 5. cerrar con `destroy()`
139
+ 1. mount with `mountTerminal()`
140
+ 2. read with `output()` or `ansiOutput()`
141
+ 3. mutate external state or dispatch interactions
142
+ 4. rerender with `update()` or through events that already trigger rerenders
143
+ 5. close with `destroy()`
144
144
 
145
145
  ### `update()`
146
146
 
147
- Vuelve a evaluar `input`, recalcula el frame y devuelve la salida plana actual.
147
+ Reevaluates `input`, recalculates the frame, and returns the current plain-text output.
148
148
 
149
- Usalo cuando mutaste estado fuera de handlers de la sesion.
149
+ Use it when you changed state outside the session handlers.
150
150
 
151
151
  ```tsx
152
152
  const state = { count: 0 };
@@ -165,19 +165,19 @@ console.log(session.output());
165
165
 
166
166
  ### `output()`
167
167
 
168
- Devuelve el frame actual en texto plano. Es la forma mas directa de:
168
+ Returns the current frame as plain text. It is the most direct way to:
169
169
 
170
- - inspeccionar estado actual
171
- - validar snapshots
172
- - probar foco y contenido sin ANSI
170
+ - inspect the current state
171
+ - validate snapshots
172
+ - test focus and content without ANSI
173
173
 
174
174
  ### `ansiOutput()`
175
175
 
176
- Devuelve el frame actual serializado como ANSI completo, incluyendo cursor y spans visuales. Es util cuando quieres:
176
+ Returns the current frame serialized as full ANSI output, including the cursor and visual spans. It is useful when you want to:
177
177
 
178
- - inspeccionar posicion de cursor
179
- - validar seleccion o foco en una terminal ANSI
180
- - integrar una capa que consume escape sequences completas
178
+ - inspect cursor position
179
+ - validate selection or focus in an ANSI terminal
180
+ - integrate with a layer that consumes full escape sequences
181
181
 
182
182
  ```tsx
183
183
  /** @jsx v */
@@ -195,35 +195,35 @@ console.log(ansi);
195
195
 
196
196
  ### `destroy()`
197
197
 
198
- Desmonta listeners de `stdin`, intenta salir de raw mode con `setRawMode(false)` y llama `pause()` si existe.
198
+ Removes `stdin` listeners, tries to exit raw mode with `setRawMode(false)`, and calls `pause()` if available.
199
199
 
200
- Llamalo siempre cuando montaste la sesion con `stdin` real o un emisor conectado.
200
+ Always call it when you mounted the session with a real `stdin` or a connected emitter.
201
201
 
202
202
  ```ts
203
203
  session.destroy();
204
204
  ```
205
205
 
206
- ## Foco y coordenadas
206
+ ## Focus and coordinates
207
207
 
208
- El foco vive a nivel de sesion. Para participar en este flujo, los nodos interactivos necesitan `id`.
208
+ Focus lives at the session level. To participate in this flow, interactive nodes need an `id`.
209
209
 
210
210
  ### `focus(id)`
211
211
 
212
- Enfoca un nodo por `id`. Devuelve `true` si lo encontro.
212
+ Focuses a node by `id`. Returns `true` if it found one.
213
213
 
214
- ### `focusNext()` y `focusPrev()`
214
+ ### `focusNext()` and `focusPrev()`
215
215
 
216
- Recorren el orden actual de elementos enfocables. `dispatchKey("TAB")` y `dispatchKey("SHIFT_TAB")` usan este mismo flujo.
216
+ Walk the current focusable-element order. `dispatchKey("TAB")` and `dispatchKey("SHIFT_TAB")` use the same flow.
217
217
 
218
218
  ### `focusAt(x, y)`
219
219
 
220
- Busca el hitbox en las coordenadas actuales, actualiza hover semantico cuando aplica y enfoca ese nodo.
220
+ Looks up the hitbox at the current coordinates, updates semantic hover when applicable, and focuses that node.
221
221
 
222
222
  ### `clickAt(x, y)`
223
223
 
224
- - si cae sobre un `Button`, dispara su accion
225
- - si cae sobre un `Input`, enfoca y coloca cursor segun la coordenada
226
- - si cae sobre otra superficie enfocable, mueve el foco
224
+ - if it lands on a `Button`, it triggers its action
225
+ - if it lands on an `Input`, it focuses it and places the cursor based on the coordinate
226
+ - if it lands on another focusable surface, it moves focus there
227
227
 
228
228
  ```tsx
229
229
  const session = mountTerminal(() => (
@@ -237,14 +237,14 @@ session.focusAt(2, 1);
237
237
  session.clickAt(3, 2);
238
238
  ```
239
239
 
240
- ## Keyboard dispatch por sesion
240
+ ## Per-session keyboard dispatch
241
241
 
242
- `dispatchKey(key)` procesa una tecla ya normalizada contra el nodo enfocado y devuelve la salida plana actual.
242
+ `dispatchKey(key)` processes a normalized key against the focused node and returns the current plain-text output.
243
243
 
244
- Atajos soportados por la API publica observables en pruebas:
244
+ Shortcuts supported by the public API and observable in tests:
245
245
 
246
- - globales: `TAB`, `SHIFT_TAB`
247
- - `Input`: caracteres de un solo byte, `ENTER`, `LEFT`, `RIGHT`, `SHIFT_LEFT`, `SHIFT_RIGHT`, `ALT_LEFT`, `ALT_RIGHT`, `HOME`, `END`, `CTRL_A`, `CTRL_C`, `CTRL_X`, `CTRL_V`, `BACKSPACE`, `DELETE`
246
+ - global: `TAB`, `SHIFT_TAB`
247
+ - `Input`: single-byte characters, `ENTER`, `LEFT`, `RIGHT`, `SHIFT_LEFT`, `SHIFT_RIGHT`, `ALT_LEFT`, `ALT_RIGHT`, `HOME`, `END`, `CTRL_A`, `CTRL_C`, `CTRL_X`, `CTRL_V`, `BACKSPACE`, `DELETE`
248
248
  - `Button`: `ENTER`, `SPACE`
249
249
  - `List`: `UP`, `DOWN`, `LEFT`, `RIGHT`, `ENTER`
250
250
  - `ScrollView`: `UP`, `DOWN`
@@ -275,14 +275,14 @@ session.dispatchKey("C");
275
275
  session.dispatchKey("ENTER");
276
276
  ```
277
277
 
278
- ## Clipboard adapter y `clipboard: false`
278
+ ## Clipboard adapter and `clipboard: false`
279
279
 
280
- La sesion separa dos conceptos:
280
+ The session separates two concepts:
281
281
 
282
- - buffer de clipboard de la sesion: `clipboard()` y `setClipboard()`
283
- - integracion con el sistema: `options.clipboard`
282
+ - the session clipboard buffer: `clipboard()` and `setClipboard()`
283
+ - system integration: `options.clipboard`
284
284
 
285
- Con un adapter, los atajos de input leen y escriben contra ese adapter. Sin adapter, la sesion conserva un valor local. Con `clipboard: false`, desactivas la integracion externa pero puedes seguir usando el buffer local de la sesion para pruebas o integraciones manuales.
285
+ With an adapter, input shortcuts read from and write to that adapter. Without an adapter, the session keeps a local value. With `clipboard: false`, external integration is disabled, but you can still use the local session buffer for tests or manual integrations.
286
286
 
287
287
  ```tsx
288
288
  const state = { value: "abcd" };
@@ -305,17 +305,17 @@ session.dispatchKey("END");
305
305
  session.dispatchKey("CTRL_V");
306
306
  ```
307
307
 
308
- ## Streams `stdin` y `stdout`
308
+ ## `stdin` and `stdout` streams
309
309
 
310
- Conectar streams vuelve a la sesion util como runtime de CLI, no solo como helper de pruebas.
310
+ Connecting streams makes the session useful as a CLI runtime, not just as a test helper.
311
311
 
312
- Comportamiento observable:
312
+ Observable behavior:
313
313
 
314
- - al montar, la sesion se suscribe a `stdin.on("data", listener)`
315
- - si `stdin.setRawMode` existe, intenta `setRawMode(true)`
316
- - si `stdin.resume` existe, intenta `resume()`
317
- - en cada rerender, si existe `stdout.write`, la sesion escribe el frame actual
318
- - al destruir, intenta desuscribirse y restaurar `raw mode`
314
+ - on mount, the session subscribes to `stdin.on("data", listener)`
315
+ - if `stdin.setRawMode` exists, it tries `setRawMode(true)`
316
+ - if `stdin.resume` exists, it tries `resume()`
317
+ - on each rerender, if `stdout.write` exists, the session writes the current frame
318
+ - on destroy, it tries to unsubscribe and restore raw mode
319
319
 
320
320
  ```tsx
321
321
  /** @jsx v */
@@ -351,12 +351,12 @@ session.destroy();
351
351
 
352
352
  ## ANSI output
353
353
 
354
- Hay dos formas practicas de trabajar con ANSI:
354
+ There are two practical ways to work with ANSI:
355
355
 
356
- - `ansi: true` + `stdout`: la sesion emite diffs incrementales en cada rerender
357
- - `session.ansiOutput()`: recupera el frame ANSI completo del estado actual
356
+ - `ansi: true` + `stdout`: the session emits incremental diffs on each rerender
357
+ - `session.ansiOutput()`: retrieves the full ANSI frame for the current state
358
358
 
359
- Esto es especialmente util cuando la terminal consumidora necesita minimizar repaints o cuando quieres verificar cursor, foco y seleccion con escape sequences reales.
359
+ This is especially useful when the consuming terminal needs to minimize repaints or when you want to verify cursor, focus, and selection with real escape sequences.
360
360
 
361
361
  ```tsx
362
362
  const state = { value: "AB" };
@@ -379,15 +379,15 @@ session.dispatchKey("LEFT");
379
379
  console.log(session.ansiOutput());
380
380
  ```
381
381
 
382
- ## Mouse SGR, wheel y pointer capture
382
+ ## SGR mouse, wheel, and pointer capture
383
383
 
384
- Cuando conectas `stdin`, la sesion acepta secuencias SGR de mouse y las traduce a interaccion practica sobre el frame actual.
384
+ When you connect `stdin`, the session accepts SGR mouse sequences and translates them into practical interaction over the current frame.
385
385
 
386
- ### Press, drag y release
386
+ ### Press, drag, and release
387
387
 
388
- - `press`: enfoca y activa el hitbox en la coordenada
389
- - `drag`: si hay un `Input` activo por mouse, extiende seleccion; en `List` y `ScrollView`, actualiza hover por fila
390
- - `release`: termina seleccion por mouse y cierra captura cuando aplica
388
+ - `press`: focuses and activates the hitbox at the coordinate
389
+ - `drag`: if an `Input` is active through the mouse, it extends selection; in `List` and `ScrollView`, it updates row hover
390
+ - `release`: ends mouse selection and closes capture when applicable
391
391
 
392
392
  ```ts
393
393
  stdin.emit("data", "\u001b[<0;4;1M");
@@ -395,34 +395,34 @@ stdin.emit("data", "\u001b[<32;7;1M");
395
395
  stdin.emit("data", "\u001b[<0;7;1m");
396
396
  ```
397
397
 
398
- Ese patron es suficiente para seleccionar texto dentro de un `Input` por coordenadas.
398
+ That pattern is enough to select text inside an `Input` by coordinates.
399
399
 
400
400
  ### Wheel
401
401
 
402
- El wheel se despacha como navegacion vertical sobre el nodo bajo el puntero:
402
+ Wheel input is dispatched as vertical navigation on the node under the pointer:
403
403
 
404
- - `wheel-up` equivale a `dispatchKey("UP")`
405
- - `wheel-down` equivale a `dispatchKey("DOWN")`
404
+ - `wheel-up` is equivalent to `dispatchKey("UP")`
405
+ - `wheel-down` is equivalent to `dispatchKey("DOWN")`
406
406
 
407
407
  ```ts
408
408
  stdin.emit("data", "\u001b[<65;2;1M");
409
409
  ```
410
410
 
411
- En un `ScrollView` enfocado o localizado por coordenadas, eso desplaza el viewport.
411
+ In a focused `ScrollView`, or one resolved by coordinates, that scrolls the viewport.
412
412
 
413
- ### Pointer capture a nivel practico
413
+ ### Pointer capture in practice
414
414
 
415
- `pointerCapture` hoy aplica a `List` y `ScrollView`.
415
+ `pointerCapture` currently applies to `List` and `ScrollView`.
416
416
 
417
- Sin `pointerCapture`, el hover semantico depende de que el drag siga dentro del hitbox visible. Con `pointerCapture`, la sesion mantiene la interaccion durante el drag aunque el puntero salga del area inicial, y dispara:
417
+ Without `pointerCapture`, semantic hover depends on the drag staying inside the visible hitbox. With `pointerCapture`, the session keeps the interaction during the drag even if the pointer leaves the initial area, and triggers:
418
418
 
419
419
  - `oncapturestart`
420
420
  - `oncaptureend`
421
421
 
422
- Esto es util para:
422
+ This is useful for:
423
423
 
424
- - listas que deben seguir rastreando la fila activa durante drag
425
- - scroll views que conservan hover o release aunque el puntero termine fuera del viewport
424
+ - lists that need to keep tracking the active row during a drag
425
+ - scroll views that keep hover or release behavior even if the pointer ends outside the viewport
426
426
 
427
427
  ```tsx
428
428
  const session = mountTerminal(() => (
@@ -442,10 +442,10 @@ stdin.emit("data", "\u001b[<32;99;99M");
442
442
  stdin.emit("data", "\u001b[<0;99;99m");
443
443
  ```
444
444
 
445
- ## Recomendaciones practicas
445
+ ## Practical recommendations
446
446
 
447
- - usa `renderTerminal()` para snapshots y `mountTerminal()` para runtime interactivo
448
- - da `id` estables a `Input`, `Button`, `List` y `ScrollView` si vas a usar foco, coordenadas o dispatch programatico
449
- - llama `update()` solo cuando mutaste estado fuera de handlers ya conectados a la sesion
450
- - llama `destroy()` siempre que montes con `stdin`
451
- - usa `clipboard: false` en pruebas o entornos donde no quieres depender del clipboard del sistema
447
+ - use `renderTerminal()` for snapshots and `mountTerminal()` for interactive runtime
448
+ - give stable `id` values to `Input`, `Button`, `List`, and `ScrollView` if you plan to use focus, coordinates, or programmatic dispatch
449
+ - call `update()` only when you changed state outside handlers already connected to the session
450
+ - always call `destroy()` when mounting with `stdin`
451
+ - use `clipboard: false` in tests or environments where you do not want to depend on the system clipboard
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valyrianjs/terminal",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Terminal adapter for valyrian.js",
5
5
  "license": "Apache-2.0",
6
6
  "private": false,