"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MAX_BUFFER = void 0;
exports.appendToBuffer = appendToBuffer;
exports.MAX_BUFFER = 100 * 1024;
// Appends PTY output to a terminal's sliding-window buffer, keeping detachOffset
// pointing at the same stream position when the front of the buffer is trimmed.
function appendToBuffer(state, data, maxBuffer = exports.MAX_BUFFER) {
    state.buffer += data;
    if (state.buffer.length > maxBuffer) {
        const trimmed = state.buffer.length - maxBuffer; // measure BEFORE slicing
        state.buffer = state.buffer.slice(-maxBuffer);
        if (state.detachOffset > 0) {
            state.detachOffset = Math.max(0, state.detachOffset - trimmed);
        }
    }
}
