pinokiod 8.3.31 → 8.3.32
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/package.json
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
lastSize: null,
|
|
9
9
|
initialSent: false,
|
|
10
10
|
suppressNext: false,
|
|
11
|
-
allowLocalFit: true
|
|
11
|
+
allowLocalFit: true,
|
|
12
|
+
lastShellSeen: null
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
function sameSize(cols, rows) {
|
|
@@ -76,6 +77,17 @@
|
|
|
76
77
|
sendResize(state.term.cols, state.term.rows, true)
|
|
77
78
|
state.initialSent = true
|
|
78
79
|
},
|
|
80
|
+
// Called with the id of the shell whose output just arrived. A shell the
|
|
81
|
+
// page has not had output from before is sent the page's size: it was
|
|
82
|
+
// started at the size its run was launched with, which need not be the
|
|
83
|
+
// page's size now. Every step of a script run is a new shell. The id a
|
|
84
|
+
// page is handed when it connects is not counted: it can be the finished
|
|
85
|
+
// shell of an earlier run, and a size sent there reaches no one.
|
|
86
|
+
shellSeen: function(id) {
|
|
87
|
+
if (!id || id === state.lastShellSeen || !state.term) return
|
|
88
|
+
state.lastShellSeen = id
|
|
89
|
+
sendResize(state.term.cols, state.term.rows, true)
|
|
90
|
+
},
|
|
79
91
|
handleResizePacket: function(packet) {
|
|
80
92
|
if (!state.term || !packet || !packet.data) return
|
|
81
93
|
const cols = packet.data.cols
|
package/server/views/pro.ejs
CHANGED
|
@@ -339,13 +339,10 @@ async function displayResults(config) {
|
|
|
339
339
|
}
|
|
340
340
|
} else if (packet.type === "stream") {
|
|
341
341
|
// set the current shell id
|
|
342
|
-
const previousShellId = shell_id
|
|
343
342
|
if (packet.data.id) {
|
|
344
343
|
shell_id = packet.data.id
|
|
345
344
|
}
|
|
346
|
-
|
|
347
|
-
resizeSync.sendInitial()
|
|
348
|
-
}
|
|
345
|
+
resizeSync.shellSeen(shell_id)
|
|
349
346
|
if (packet.data.raw) {
|
|
350
347
|
write(packet.data.raw)
|
|
351
348
|
} else if (packet.data.json) {
|
package/server/views/shell.ejs
CHANGED
|
@@ -689,9 +689,7 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
689
689
|
if (!previousShellId) {
|
|
690
690
|
this.flushPendingInput()
|
|
691
691
|
}
|
|
692
|
-
|
|
693
|
-
this.resizeSync.sendInitial()
|
|
694
|
-
}
|
|
692
|
+
this.resizeSync.shellSeen(shell_id)
|
|
695
693
|
notifyShellSession(shell_id)
|
|
696
694
|
}
|
|
697
695
|
if (packet.data.raw) {
|
|
@@ -1944,14 +1944,11 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
1944
1944
|
refreshParent(packet)
|
|
1945
1945
|
pluginTerminalDiscoveryRefresher.markActivity()
|
|
1946
1946
|
// set the current shell id
|
|
1947
|
-
const previousShellId = shell_id
|
|
1948
1947
|
if (packet.data.id) {
|
|
1949
1948
|
shell_id = packet.data.id
|
|
1950
1949
|
this.flushPendingInput()
|
|
1951
1950
|
}
|
|
1952
|
-
|
|
1953
|
-
this.resizeSync.sendInitial()
|
|
1954
|
-
}
|
|
1951
|
+
this.resizeSync.shellSeen(shell_id)
|
|
1955
1952
|
if (packet.data.raw) {
|
|
1956
1953
|
this.writeBatched(packet.data.raw)
|
|
1957
1954
|
} else if (packet.data.json) {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// The size a terminal page sends to its shell (server/public/resizeSync.js),
|
|
2
|
+
// driven with the packets a script's page gets, in the order it gets them.
|
|
3
|
+
const assert = require('node:assert/strict')
|
|
4
|
+
const fs = require('node:fs')
|
|
5
|
+
const path = require('node:path')
|
|
6
|
+
const test = require('node:test')
|
|
7
|
+
const vm = require('node:vm')
|
|
8
|
+
|
|
9
|
+
const source = fs.readFileSync(path.resolve(__dirname, '../server/public/resizeSync.js'), 'utf8')
|
|
10
|
+
|
|
11
|
+
// A page: its terminal, the id of the shell it believes it is on, and what it
|
|
12
|
+
// has sent. `connect` and `stream` do what the page does on those packets.
|
|
13
|
+
const page = (cols, rows) => {
|
|
14
|
+
const window = {}
|
|
15
|
+
vm.runInNewContext(source, { window })
|
|
16
|
+
const sent = []
|
|
17
|
+
const term = { cols, rows }
|
|
18
|
+
let shellId = null
|
|
19
|
+
const sync = window.PinokioResizeSync.create({
|
|
20
|
+
term,
|
|
21
|
+
socket: { run: (message) => sent.push({ id: message.id, cols: message.resize.cols, rows: message.resize.rows }) },
|
|
22
|
+
getShellId: () => shellId,
|
|
23
|
+
})
|
|
24
|
+
return {
|
|
25
|
+
term, sent, sync,
|
|
26
|
+
launch() { sync.reset() },
|
|
27
|
+
connect(shell) {
|
|
28
|
+
if (shell) shellId = shell
|
|
29
|
+
if (shellId) sync.sendInitial()
|
|
30
|
+
},
|
|
31
|
+
stream(id) {
|
|
32
|
+
if (id) shellId = id
|
|
33
|
+
sync.shellSeen(shellId)
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test('the first shell of a first run is sent the page size', () => {
|
|
39
|
+
const p = page(120, 40)
|
|
40
|
+
p.launch()
|
|
41
|
+
p.connect(null) // nothing has run under this script before
|
|
42
|
+
p.stream('shell-1')
|
|
43
|
+
assert.deepEqual(p.sent, [{ id: 'shell-1', cols: 120, rows: 40 }])
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('a run started again sends its size to the new shell, not only to the finished one it was handed', () => {
|
|
47
|
+
const p = page(260, 61)
|
|
48
|
+
p.launch()
|
|
49
|
+
// the page is one column wider by the time the server answers
|
|
50
|
+
p.term.cols = 261
|
|
51
|
+
// the server hands over the last shell of the earlier run, which is finished
|
|
52
|
+
p.connect('old-run-last-shell')
|
|
53
|
+
assert.deepEqual(p.sent, [{ id: 'old-run-last-shell', cols: 261, rows: 61 }])
|
|
54
|
+
// output arrives from the new run's first shell, started at the launch size
|
|
55
|
+
p.stream('new-run-shell-1')
|
|
56
|
+
assert.deepEqual(p.sent[1], { id: 'new-run-shell-1', cols: 261, rows: 61 })
|
|
57
|
+
assert.equal(p.sent.length, 2)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('every step of a run is a new shell and each is sent the size once', () => {
|
|
61
|
+
const p = page(100, 30)
|
|
62
|
+
p.launch()
|
|
63
|
+
p.connect(null)
|
|
64
|
+
p.stream('step-1')
|
|
65
|
+
p.stream('step-1')
|
|
66
|
+
p.stream('step-1')
|
|
67
|
+
// resized while step 1 runs: goes to step 1 as before
|
|
68
|
+
p.term.cols = 140
|
|
69
|
+
p.sync.sendResize(p.term.cols, p.term.rows)
|
|
70
|
+
p.stream('step-2')
|
|
71
|
+
p.stream('step-2')
|
|
72
|
+
p.stream('step-3')
|
|
73
|
+
assert.deepEqual(p.sent, [
|
|
74
|
+
{ id: 'step-1', cols: 100, rows: 30 },
|
|
75
|
+
{ id: 'step-1', cols: 140, rows: 30 },
|
|
76
|
+
{ id: 'step-2', cols: 140, rows: 30 },
|
|
77
|
+
{ id: 'step-3', cols: 140, rows: 30 },
|
|
78
|
+
])
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('output with no shell id sends nothing', () => {
|
|
82
|
+
const p = page(100, 30)
|
|
83
|
+
p.launch()
|
|
84
|
+
p.stream(null)
|
|
85
|
+
assert.deepEqual(p.sent, [])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('every page that shows a shell reports each shell it gets output from', () => {
|
|
89
|
+
// Each page's own handling of a stream packet is inline in its view. If the
|
|
90
|
+
// call goes from one, a shell started again under that page is back to
|
|
91
|
+
// having its size sent only to a finished shell.
|
|
92
|
+
for (const name of ['terminal.ejs', 'shell.ejs', 'pro.ejs']) {
|
|
93
|
+
const view = fs.readFileSync(path.resolve(__dirname, '../server/views', name), 'utf8')
|
|
94
|
+
const stream = view.slice(view.indexOf('packet.type === "stream"'))
|
|
95
|
+
const handler = stream.slice(0, stream.indexOf("packet.type === 'disconnect'"))
|
|
96
|
+
assert.ok(handler.length > 0, name)
|
|
97
|
+
assert.match(handler, /shell_id = packet\.data\.id[\s\S]*resizeSync\.shellSeen\(shell_id\)/, name)
|
|
98
|
+
assert.doesNotMatch(handler, /sendInitial/, name)
|
|
99
|
+
}
|
|
100
|
+
})
|