pinokiod 8.3.11 → 8.3.12

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/kernel/shells.js CHANGED
@@ -772,10 +772,16 @@ class Shells {
772
772
  session.emit(payload)
773
773
  }
774
774
  } else if (params.binary) {
775
- // From the terminal's binary channel: one character per byte (old-format
776
- // mouse reports). Written as bytes, because as text a value above 127
777
- // would reach the program as two bytes.
778
- session.emit(Buffer.from(String(params.emit), "binary"))
775
+ const report = Buffer.from(String(params.emit), "binary")
776
+ // Legacy mouse input is ESC [ M followed by button, column and row bytes.
777
+ // Coordinates start at 1 and are encoded as value + 32. From column or
778
+ // row 96, Windows ConPTY's UTF-8 decoding can corrupt the position.
779
+ if (this.kernel.platform === "win32" && report.length === 6 &&
780
+ report[0] === 0x1b && report[1] === 0x5b && report[2] === 0x4d &&
781
+ (report[4] > 127 || report[5] > 127)) {
782
+ return true
783
+ }
784
+ session.emit(report)
779
785
  } else {
780
786
  session.emit(params.emit)
781
787
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "8.3.11",
3
+ "version": "8.3.12",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -255,19 +255,32 @@ test('nothing is replayed while the connection is not open', (t) => {
255
255
  assert.deepEqual(wheel, [1])
256
256
  })
257
257
 
258
- function shellsWith(session) {
259
- const shells = Object.create(Shells.prototype)
258
+ function shellsWith(session, platform = process.platform) {
259
+ const shells = new Shells({ platform })
260
260
  shells.get = () => session
261
261
  return shells
262
262
  }
263
263
 
264
- test('input from the binary channel reaches the shell as the same bytes', () => {
264
+ test('Unix shells receive the original legacy mouse bytes even at wide columns', () => {
265
+ for (const platform of ['darwin', 'linux']) {
266
+ const received = []
267
+ const shells = shellsWith({ emit: (message) => received.push(message) }, platform)
268
+ shells.emit({ id: 'a', emit: OLD_FORMAT_REPORT, binary: true })
269
+ assert.deepEqual(received, [Buffer.from(OLD_FORMAT_BYTES)])
270
+ }
271
+ })
272
+
273
+ test('Windows drops only legacy mouse reports beyond column or row 95', () => {
265
274
  const received = []
266
- const shells = shellsWith({ emit: (message) => received.push(message) })
267
- shells.emit({ id: 'a', emit: OLD_FORMAT_REPORT, binary: true })
268
- assert.equal(received.length, 1)
269
- assert.ok(Buffer.isBuffer(received[0]))
270
- assert.deepEqual([...received[0]], OLD_FORMAT_BYTES)
275
+ const shells = shellsWith({ emit: (message) => received.push(message) }, 'win32')
276
+ const lastValid = '\x1b[M\x60\x7f\x7f'
277
+ const otherBinary = '\x1b[X\x60\x80\x80'
278
+ for (const emit of [lastValid, '\x1b[M\x60\x80\x7f', '\x1b[M\x60\x7f\x80', otherBinary]) {
279
+ assert.equal(shells.emit({ id: 'a', emit, binary: true }), true)
280
+ }
281
+ const sgr = '\x1b[<64;164;5M'
282
+ shells.emit({ id: 'a', emit: sgr })
283
+ assert.deepEqual(received, [Buffer.from(lastValid, 'binary'), Buffer.from(otherBinary, 'binary'), sgr])
271
284
  })
272
285
 
273
286
  test('typed text and pastes are still passed on as text', () => {