export function parseInputSequence(chunk) {
    const events = [];
    let i = 0;
    const push = (input, key = {}) => events.push({ input, key });
    while (i < chunk.length) {
        const rest = chunk.slice(i);
        if (rest.startsWith('\x1b[5~')) {
            push('', { pageUp: true });
            i += 4;
            continue;
        }
        if (rest.startsWith('\x1b[6~')) {
            push('', { pageDown: true });
            i += 4;
            continue;
        }
        if (rest.startsWith('\x1b[3~')) {
            push('', { delete: true });
            i += 4;
            continue;
        }
        if (rest.startsWith('\x1b[A')) {
            push('', { upArrow: true });
            i += 3;
            continue;
        }
        if (rest.startsWith('\x1b[B')) {
            push('', { downArrow: true });
            i += 3;
            continue;
        }
        if (rest.startsWith('\x1b[C')) {
            push('', { rightArrow: true });
            i += 3;
            continue;
        }
        if (rest.startsWith('\x1b[D')) {
            push('', { leftArrow: true });
            i += 3;
            continue;
        }
        if (rest.startsWith('\x1b[H') || rest.startsWith('\x1bOH')) {
            push('', { home: true });
            i += 3;
            continue;
        }
        if (rest.startsWith('\x1b[F') || rest.startsWith('\x1bOF')) {
            push('', { end: true });
            i += 3;
            continue;
        }
        const ch = chunk[i];
        const code = ch.charCodeAt(0);
        if (ch === '\x1b') {
            push('', { escape: true });
            i += 1;
            continue;
        }
        if (ch === '\r' || ch === '\n') {
            push('', { return: true });
            i += 1;
            continue;
        }
        if (ch === '\t') {
            push('', { tab: true });
            i += 1;
            continue;
        }
        if (ch === '\x7f' || ch === '\b') {
            push('', { backspace: true });
            i += 1;
            continue;
        }
        if (code >= 1 && code <= 26) {
            push(String.fromCharCode(code + 96), { ctrl: true });
            i += 1;
            continue;
        }
        push(ch, {});
        i += 1;
    }
    return events;
}
//# sourceMappingURL=input.js.map