/**
 * Phase C: Safe Text Helper - Kill long lines that cause scrollbars
 *
 * Even if layout is correct, one long line (debug banner, status, etc.)
 * can force horizontal scrollbars in AWS CloudShell / web terminals.
 *
 * This helper truncates all text to safe widths.
 */
/**
 * Phase C: Truncate text to safe width with ellipsis
 */
export function safeText(str, maxWidth) {
    if (typeof str !== 'string') {
        return '';
    }
    if (str.length <= maxWidth) {
        return str;
    }
    // Truncate with ellipsis if needed
    if (maxWidth <= 3) {
        return '.'.repeat(maxWidth);
    }
    return str.substring(0, maxWidth - 3) + '...';
}
/**
 * Phase C: Truncate each line in a multi-line string
 */
export function safeTextLines(content, maxWidth) {
    if (typeof content !== 'string') {
        return '';
    }
    const lines = content.split('\n');
    return lines.map(line => safeText(line, maxWidth)).join('\n');
}
/**
 * Phase C: Truncate text for a box with borders
 * Accounts for border width and padding
 */
export function safeTextForBox(content, boxWidth, hasBorders = true, paddingLeft = 0, paddingRight = 0) {
    // Calculate internal width
    let internalWidth = boxWidth;
    if (hasBorders) {
        internalWidth -= 2; // Left and right border chars (│)
    }
    internalWidth -= paddingLeft + paddingRight;
    // Ensure minimum width
    internalWidth = Math.max(1, internalWidth);
    return safeTextLines(content, internalWidth);
}
//# sourceMappingURL=safeText.js.map