@dotrino/terminal-agent 0.14.0 → 0.15.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 +1 -1
- package/consoles.js +21 -9
- package/index.js +2 -2
- package/package.json +1 -1
package/bin/terminal.js
CHANGED
|
@@ -380,7 +380,7 @@ function interactive (conn, first, dir) {
|
|
|
380
380
|
// «r»: esta ventana manda en el tamaño de la consola (la app la usa al ganar el foco: con
|
|
381
381
|
// varias ventanas de tamaños distintos en la misma consola, se ajusta a la que miras).
|
|
382
382
|
if (ch === 'r') { conn.send({ type: 'resize', ...size() }); continue }
|
|
383
|
-
// «p» / «u»: esta ventana fija (
|
|
383
|
+
// «p» / «u»: esta ventana fija (⤢) o suelta el tamaño de la consola.
|
|
384
384
|
if (ch === 'p' || ch === 'u') { conn.send({ type: 'pin', on: ch === 'p' }); if (ch === 'p') conn.send({ type: 'resize', ...size() }); continue }
|
|
385
385
|
if (ch === 'n') {
|
|
386
386
|
if (send) { input(send); send = '' }
|
package/consoles.js
CHANGED
|
@@ -38,10 +38,12 @@ class Console {
|
|
|
38
38
|
this.createdAt = Date.now()
|
|
39
39
|
this.lastActive = Date.now()
|
|
40
40
|
this.viewers = new Set() // sesiones mirando: { onOut(data), onExit(code), onMeta?(info), origin, device?, tag?, size? }
|
|
41
|
-
// QUIÉN MANDA EN EL TAMAÑO. `
|
|
41
|
+
// QUIÉN MANDA EN EL TAMAÑO. `pinKey`: la pantalla que lo eligió a propósito (⤢ en la app o el teléfono);
|
|
42
42
|
// si nadie, `holder`: el último que se enganchó. Solo ese lo cambia, y se sigue su pantalla
|
|
43
43
|
// (redimensionar la ventana, girar el teléfono). Escribir o dar foco no cambia nada.
|
|
44
|
-
|
|
44
|
+
// `pinKey` recuerda QUÉ PANTALLA lo eligió (ventana o aparato), no su conexión: si esa pantalla
|
|
45
|
+
// pasa a otra consola y vuelve, lo recupera. Mientras no está, manda el último que llegó.
|
|
46
|
+
this.pinKey = null
|
|
45
47
|
this.holder = null
|
|
46
48
|
this.exited = false
|
|
47
49
|
this.screen = new Terminal({ cols, rows, scrollback: SCROLLBACK, allowProposedApi: true })
|
|
@@ -100,9 +102,10 @@ class Console {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
detach (viewer) {
|
|
103
|
-
if (!this.viewers.
|
|
105
|
+
if (!this.viewers.has(viewer)) return
|
|
106
|
+
// Quién decidía, ANTES de quitarlo: si era él, hay que pasar el tamaño a otro.
|
|
104
107
|
const before = this.decider()
|
|
105
|
-
|
|
108
|
+
this.viewers.delete(viewer)
|
|
106
109
|
// Si se fue el último que llegó, lo es el último de los que quedan.
|
|
107
110
|
if (this.holder === viewer) this.holder = [...this.viewers].filter((v) => v.size).pop() || null
|
|
108
111
|
// Si cambió quién decide (se fue el que lo tenía, fijado o no), manda su tamaño.
|
|
@@ -112,7 +115,13 @@ class Console {
|
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
/** Quién decide el tamaño ahora. */
|
|
115
|
-
decider () { return this.
|
|
118
|
+
decider () { return this.pinnedViewer() || this.holder }
|
|
119
|
+
|
|
120
|
+
/** La pantalla que eligió el tamaño, si está mirando ahora. */
|
|
121
|
+
pinnedViewer () {
|
|
122
|
+
if (!this.pinKey) return null
|
|
123
|
+
return [...this.viewers].filter((v) => viewerKey(v) === this.pinKey).pop() || null
|
|
124
|
+
}
|
|
116
125
|
|
|
117
126
|
/**
|
|
118
127
|
* `viewer` dice su tamaño (al engancharse, `attaching`, o porque cambió su pantalla). Se aplica
|
|
@@ -124,10 +133,10 @@ class Console {
|
|
|
124
133
|
else this._meta()
|
|
125
134
|
}
|
|
126
135
|
|
|
127
|
-
/**
|
|
136
|
+
/** ⤢: `viewer` fija (o suelta) el tamaño a su pantalla. */
|
|
128
137
|
pin (viewer, on) {
|
|
129
|
-
if (on) this.
|
|
130
|
-
else if (this.
|
|
138
|
+
if (on) this.pinKey = viewerKey(viewer)
|
|
139
|
+
else if (this.pinKey === viewerKey(viewer)) this.pinKey = null
|
|
131
140
|
const d = this.decider()
|
|
132
141
|
if (d?.size) this.resize(d.size.cols, d.size.rows)
|
|
133
142
|
this._meta()
|
|
@@ -141,11 +150,14 @@ class Console {
|
|
|
141
150
|
info () {
|
|
142
151
|
const watchers = [...this.viewers].filter((v) => v.origin).map((v) => ({ origin: v.origin, device: v.device || null, tag: v.tag || null }))
|
|
143
152
|
const d = this.decider()
|
|
144
|
-
const sizeBy = d ? { origin: d.origin || null, device: d.device || null, tag: d.tag || null, pinned: d === this.
|
|
153
|
+
const sizeBy = d ? { origin: d.origin || null, device: d.device || null, tag: d.tag || null, pinned: !!d && d === this.pinnedViewer() } : null
|
|
145
154
|
return { id: this.id, n: this.n, sizeBy, origin: this.origin, title: this.title, cols: this.cols, rows: this.rows, createdAt: this.createdAt, lastActive: this.lastActive, viewers: this.viewers.size, watchers }
|
|
146
155
|
}
|
|
147
156
|
}
|
|
148
157
|
|
|
158
|
+
/** Qué pantalla es un `viewer`: su ventana (`tag`) o su aparato, sin importar la conexión. */
|
|
159
|
+
function viewerKey (v) { return `${v.origin || ''}|${v.device || ''}|${v.tag || ''}` }
|
|
160
|
+
|
|
149
161
|
/** Las consolas de este agente. */
|
|
150
162
|
export class ConsoleHub {
|
|
151
163
|
/**
|
package/index.js
CHANGED
|
@@ -70,7 +70,7 @@ 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: lo decide quien lo FIJÓ (`pin`, el
|
|
73
|
+
* Tamaño con varios mirando: lo decide quien lo FIJÓ (`pin`, el ⤢ de la app o el teléfono) y, si
|
|
74
74
|
* nadie, el último que se enganchó. Solo esa pantalla lo cambia (sus `resize` se siguen: girar el
|
|
75
75
|
* teléfono, redimensionar la ventana). Escribir o dar foco no cambia nada.
|
|
76
76
|
* Exportada para las pruebas.
|
|
@@ -137,7 +137,7 @@ export function serveSession (session, hub, { origin = 'remote' } = {}) {
|
|
|
137
137
|
return
|
|
138
138
|
}
|
|
139
139
|
if (msg.type === 'resize') { takeSize(msg); current?.sizeFrom(viewer); return }
|
|
140
|
-
//
|
|
140
|
+
// ⤢ «Esta pantalla manda en el tamaño» (on) o soltarlo (off).
|
|
141
141
|
if (msg.type === 'pin') { current?.pin(viewer, !!msg.on); return }
|
|
142
142
|
if (msg.type === 'close') { if (current) hub.kill(current.id); return }
|
|
143
143
|
if (msg.type === 'kill') { if (!hub.kill(msg.id)) fail('no-console', 'that console no longer exists') }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotrino/terminal-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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": {
|