@dotrino/terminal-agent 0.11.0 → 0.12.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/bin/terminal.js CHANGED
@@ -314,7 +314,13 @@ function interactive (conn, first, dir) {
314
314
  .finally(() => process.exit(code))
315
315
  }
316
316
 
317
+ // La pantalla de la consola (`replay`) está hecha para pintarse sobre una pantalla LIMPIA con
318
+ // el cursor en el origen. Al arrancar, la TTY puede haber repetido algo de lo tecleado en los
319
+ // primeros milisegundos (antes de pasar a crudo), y entonces todo se pintaba corrido: el cursor
320
+ // acababa en la columna 0 o encima del prompt. Por eso, antes de la primera, en limpio.
321
+ let clean = false
317
322
  conn.on('message', (m) => {
323
+ if (m.type === 'replay' && !clean) { clean = true; out.write('\x1b[H\x1b[2J') }
318
324
  if (m.type === 'out' || m.type === 'replay') { out.write(filter(m.data)); return }
319
325
  if (m.type === 'attached') {
320
326
  consoleId = m.id
package/consoles.js CHANGED
@@ -27,8 +27,9 @@ export const REPLAY_CHUNK = 64 * 1024
27
27
  const randomId = () => [...crypto.getRandomValues(new Uint8Array(8))].map((x) => x.toString(16).padStart(2, '0')).join('')
28
28
 
29
29
  class Console {
30
- constructor ({ id, pty, cols, rows, origin }) {
30
+ constructor ({ id, n, pty, cols, rows, origin }) {
31
31
  this.id = id
32
+ this.n = n // su número, fijo mientras viva (ver ConsoleHub.create)
32
33
  this.pty = pty
33
34
  this.origin = origin // 'local' (una ventana de esta máquina) | 'remote' (otro aparato)
34
35
  this.title = '' // el que pone la shell (OSC 0/2), para reconocerla en la lista
@@ -98,7 +99,7 @@ class Console {
98
99
  */
99
100
  info () {
100
101
  const watchers = [...this.viewers].filter((v) => v.origin).map((v) => ({ origin: v.origin, device: v.device || null, tag: v.tag || null }))
101
- return { id: this.id, origin: this.origin, title: this.title, cols: this.cols, rows: this.rows, createdAt: this.createdAt, lastActive: this.lastActive, viewers: this.viewers.size, watchers }
102
+ return { id: this.id, n: this.n, origin: this.origin, title: this.title, cols: this.cols, rows: this.rows, createdAt: this.createdAt, lastActive: this.lastActive, viewers: this.viewers.size, watchers }
102
103
  }
103
104
  }
104
105
 
@@ -115,8 +116,14 @@ export class ConsoleHub {
115
116
 
116
117
  create ({ cols = 80, rows = 24, origin = 'remote', cwd = null } = {}) {
117
118
  const id = randomId()
119
+ // Su NÚMERO: el libre más bajo, y no cambia mientras viva. Si se cierra la 1, la 2 sigue
120
+ // siendo la 2 y la próxima nueva será la 1. Lo da el agente para que sea el mismo en todas
121
+ // las ventanas y aparatos.
122
+ const used = new Set([...this.consoles.values()].map((c) => c.n))
123
+ let n = 1
124
+ while (used.has(n)) n++
118
125
  const pty = this._spawn({ cols, rows, cwd })
119
- const c = new Console({ id, pty, cols, rows, origin })
126
+ const c = new Console({ id, n, pty, cols, rows, origin })
120
127
  pty.onData((d) => c._out(d))
121
128
  pty.onExit(({ exitCode }) => {
122
129
  c.exited = true
@@ -131,7 +138,7 @@ export class ConsoleHub {
131
138
 
132
139
  get (id) { return this.consoles.get(id) || null }
133
140
 
134
- list () { return [...this.consoles.values()].map((c) => c.info()) }
141
+ list () { return [...this.consoles.values()].map((c) => c.info()).sort((a, b) => a.n - b.n) }
135
142
 
136
143
  kill (id) {
137
144
  const c = this.consoles.get(id)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotrino/terminal-agent",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Dotrino Terminal: las ventanas de esta máquina (dotrino-terminal) y su agente, que deja abrir esas mismas consolas desde los otros aparatos de tu cuenta, cifrado punto a punto.",
5
5
  "type": "module",
6
6
  "bin": {