fix(tui): tighten SGR fragment matching

This commit is contained in:
Brooklyn Nicholson 2026-04-30 17:50:49 -05:00
parent 71b685aee0
commit ded011c5a5
4 changed files with 11 additions and 5 deletions

View File

@ -127,4 +127,10 @@ describe('fragmented SGR mouse recovery', () => {
expect(key).toMatchObject({ kind: 'key', sequence: 'see 1;2;3M for details' })
})
it('does not match prefixless fragments inside longer digit runs', () => {
const [[key]] = parseMultipleKeypresses(INITIAL_STATE, '1234;56;78M9;10;11M')
expect(key).toMatchObject({ kind: 'key', sequence: '1234;56;78M9;10;11M' })
})
})

View File

@ -63,7 +63,7 @@ const XTVERSION_RE = /^\x1bP>\|(.*?)(?:\x07|\x1b\\)$/s
// Button 32=left-drag (0x20 | motion-bit). Plain 0/1/2 = left/mid/right click.
// eslint-disable-next-line no-control-regex
const SGR_MOUSE_RE = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])$/
const SGR_MOUSE_FRAGMENT_RE = /(?:\[<|<)?(?:[0-9]|[1-9][0-9]|1\d{2}|2[0-4]\d|25[0-5]);\d+;\d+[Mm]/g
const SGR_MOUSE_FRAGMENT_RE = /(?<!\d)(?:\[<|<)?(?:[0-9]|[1-9][0-9]|1\d{2}|2[0-4]\d|25[0-5]);\d+;\d+[Mm]/g
function createPasteKey(content: string): ParsedKey {
return {

View File

@ -4,8 +4,8 @@ import { resetTerminalModes, TERMINAL_MODE_RESET } from '../lib/terminalModes.js
describe('terminal mode reset', () => {
it('includes common sticky input modes', () => {
expect(TERMINAL_MODE_RESET).toContain("\x1b[0'z")
expect(TERMINAL_MODE_RESET).toContain("\x1b[0'{")
expect(TERMINAL_MODE_RESET).toContain('\x1b[0\'z')
expect(TERMINAL_MODE_RESET).toContain('\x1b[0\'{')
expect(TERMINAL_MODE_RESET).toContain('\x1b[?2029l')
expect(TERMINAL_MODE_RESET).toContain('\x1b[?1016l')
expect(TERMINAL_MODE_RESET).toContain('\x1b[?1015l')

View File

@ -1,8 +1,8 @@
import { writeSync } from 'node:fs'
export const TERMINAL_MODE_RESET =
"\x1b[0'z" + // DEC locator reporting
"\x1b[0'{" + // selectable locator events
'\x1b[0\'z' + // DEC locator reporting
'\x1b[0\'{' + // selectable locator events
'\x1b[?2029l' + // passive mouse
'\x1b[?1016l' + // SGR-pixels mouse
'\x1b[?1015l' + // urxvt decimal mouse