UNPKG

@inquirer/testing

Version:
21 lines (20 loc) 641 B
import xterm from '@xterm/headless'; export async function interpretTerminalOutput(rawOutput, cols = 10_000, rows = 4000) { const term = new xterm.Terminal({ cols, rows, allowProposedApi: true, convertEol: true, }); await new Promise((resolve) => term.write(rawOutput, resolve)); const lines = []; for (let i = 0; i < term.rows; i++) { lines.push(term.buffer.active.getLine(i)?.translateToString(true) ?? ''); } term.dispose(); // Trim trailing empty lines while (lines.length > 0 && lines.at(-1) === '') { lines.pop(); } return lines.join('\n'); }