Enable xterm bracketed paste (?2004h/?2004l), parse ESC[200~…201~ as a single paste event, insert paste in the buffer with one undo step, and replace prompt input with first-line sanitized text capped by BARE_EDIT_MAX_PROMPT. Cap typed prompt length for terminals without bracketed paste. Extend tests and rebuild kernel /bin edit and nano bundles.
34 lines
1.6 KiB
JavaScript
34 lines
1.6 KiB
JavaScript
import test from 'brittle'
|
|
import { readFile } from 'node:fs/promises'
|
|
import { dirname, join } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
const tuiPath = join(__dirname, '../lib/edit-tui.js')
|
|
const kernelEditPath = join(__dirname, '../../../kernel/bin/edit')
|
|
|
|
test('edit-tui finally tears down alternate screen or clears display', async (t) => {
|
|
const src = await readFile(tuiPath, 'utf8')
|
|
t.ok(src.includes('[?1049h'), 'expected alternate-screen enter when alt mode enabled')
|
|
t.ok(src.includes('[?1049l'), 'expected alternate-screen leave in finally')
|
|
t.ok(
|
|
(src.match(/\\x1b\[2J\\x1b\[H/g) || []).length >= 2,
|
|
'expected full clear sequence in draw and in finally fallback'
|
|
)
|
|
t.ok(src.includes('BARE_EDIT_NO_ALTSCREEN'), 'expected env gate for alternate screen')
|
|
t.ok(src.includes('[?2004h'), 'expected bracketed paste enable when enabled')
|
|
t.ok(src.includes('[?2004l'), 'expected bracketed paste disable in finally')
|
|
t.ok(src.includes('BARE_EDIT_NO_BRACKETED_PASTE'), 'expected env gate for bracketed paste')
|
|
})
|
|
|
|
test('shipped kernel/bin/edit includes TTY teardown escapes', async (t) => {
|
|
const bin = await readFile(kernelEditPath, 'utf8')
|
|
t.ok(bin.includes('[?1049h'), 'kernel edit should enter alternate screen')
|
|
t.ok(bin.includes('[?1049l'), 'kernel edit should leave alternate screen in finally')
|
|
t.ok(bin.includes('[?2004l'), 'kernel edit should disable bracketed paste in finally')
|
|
t.ok(
|
|
(bin.match(/\\x1b\[2J\\x1b\[H/g) || []).length >= 2,
|
|
'kernel edit should full-clear in draw and finally fallback'
|
|
)
|
|
})
|