@dotrino/terminal-agent 0.11.1 → 0.13.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/consoles.js +15 -4
- package/index.js +4 -2
- package/package.json +1 -1
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
|
|
@@ -61,9 +62,13 @@ class Console {
|
|
|
61
62
|
|
|
62
63
|
resize (cols, rows) {
|
|
63
64
|
if (!cols || !rows) return
|
|
65
|
+
const changed = cols !== this.cols || rows !== this.rows
|
|
64
66
|
this.cols = cols; this.rows = rows
|
|
65
67
|
try { this.pty.resize(cols, rows) } catch (_) {}
|
|
66
68
|
try { this.screen.resize(cols, rows) } catch (_) {}
|
|
69
|
+
// Quien mira desde otro aparato se entera del tamaño nuevo y adapta su vista (la PWA no
|
|
70
|
+
// encoge la consola: la muestra a su tamaño, con desplazamiento).
|
|
71
|
+
if (changed) this._meta()
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
/**
|
|
@@ -98,7 +103,7 @@ class Console {
|
|
|
98
103
|
*/
|
|
99
104
|
info () {
|
|
100
105
|
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 }
|
|
106
|
+
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
107
|
}
|
|
103
108
|
}
|
|
104
109
|
|
|
@@ -115,8 +120,14 @@ export class ConsoleHub {
|
|
|
115
120
|
|
|
116
121
|
create ({ cols = 80, rows = 24, origin = 'remote', cwd = null } = {}) {
|
|
117
122
|
const id = randomId()
|
|
123
|
+
// Su NÚMERO: el libre más bajo, y no cambia mientras viva. Si se cierra la 1, la 2 sigue
|
|
124
|
+
// siendo la 2 y la próxima nueva será la 1. Lo da el agente para que sea el mismo en todas
|
|
125
|
+
// las ventanas y aparatos.
|
|
126
|
+
const used = new Set([...this.consoles.values()].map((c) => c.n))
|
|
127
|
+
let n = 1
|
|
128
|
+
while (used.has(n)) n++
|
|
118
129
|
const pty = this._spawn({ cols, rows, cwd })
|
|
119
|
-
const c = new Console({ id, pty, cols, rows, origin })
|
|
130
|
+
const c = new Console({ id, n, pty, cols, rows, origin })
|
|
120
131
|
pty.onData((d) => c._out(d))
|
|
121
132
|
pty.onExit(({ exitCode }) => {
|
|
122
133
|
c.exited = true
|
|
@@ -131,7 +142,7 @@ export class ConsoleHub {
|
|
|
131
142
|
|
|
132
143
|
get (id) { return this.consoles.get(id) || null }
|
|
133
144
|
|
|
134
|
-
list () { return [...this.consoles.values()].map((c) => c.info()) }
|
|
145
|
+
list () { return [...this.consoles.values()].map((c) => c.info()).sort((a, b) => a.n - b.n) }
|
|
135
146
|
|
|
136
147
|
kill (id) {
|
|
137
148
|
const c = this.consoles.get(id)
|
package/index.js
CHANGED
|
@@ -70,7 +70,9 @@ export function makeHub (pty, opts = {}) {
|
|
|
70
70
|
* ella: cerrar la ventana mata su shell, como en cualquier terminal. Una ventana que solo
|
|
71
71
|
* se enganchó a una consola ajena, o que la soltó a propósito (`detach`), no mata nada.
|
|
72
72
|
*
|
|
73
|
-
* Tamaño con varios mirando: manda el último que se enganchó o
|
|
73
|
+
* Tamaño con varios mirando: manda el último que se enganchó (o abrió). Escribir lo cambia solo
|
|
74
|
+
* desde una ventana de esta máquina; desde otro aparato (la PWA), solo al engancharse o con su
|
|
75
|
+
* botón «Ajustar a esta pantalla» (un `resize` explícito).
|
|
74
76
|
* Exportada para las pruebas.
|
|
75
77
|
*
|
|
76
78
|
* @param {object} session
|
|
@@ -131,7 +133,7 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
|
131
133
|
if (msg.type === 'detach') { owned = null; release(); return }
|
|
132
134
|
if (msg.type === 'input') {
|
|
133
135
|
if (!current) return
|
|
134
|
-
if (current.cols !== size.cols || current.rows !== size.rows) current.resize(size.cols, size.rows)
|
|
136
|
+
if (origin === 'local' && (current.cols !== size.cols || current.rows !== size.rows)) current.resize(size.cols, size.rows)
|
|
135
137
|
current.write(String(msg.data ?? ''))
|
|
136
138
|
return
|
|
137
139
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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": {
|