"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.noColor = void 0;
exports.moveTo = moveTo;
exports.hideCursor = hideCursor;
exports.showCursor = showCursor;
exports.resetAttributes = resetAttributes;
exports.bold = bold;
exports.dim = dim;
exports.italic = italic;
exports.underline = underline;
exports.inverse = inverse;
exports.strikethrough = strikethrough;
exports.clearScreen = clearScreen;
exports.alternateScreen = alternateScreen;
exports.mainScreen = mainScreen;
exports.enableMouseMode = enableMouseMode;
exports.disableMouseMode = disableMouseMode;
exports.fgColor = fgColor;
exports.bgColor = bgColor;
const ESC = '\x1b[';
/** NO_COLOR standard (https://no-color.org/): suppress color when set. */
exports.noColor = process.env.NO_COLOR != null;
function moveTo(row, col) {
    return `${ESC}${row};${col}H`;
}
function hideCursor() { return `${ESC}?25l`; }
function showCursor() { return `${ESC}?25h`; }
function resetAttributes() { return `${ESC}0m`; }
function bold() { return exports.noColor ? '' : `${ESC}1m`; }
function dim() { return exports.noColor ? '' : `${ESC}2m`; }
function italic() { return exports.noColor ? '' : `${ESC}3m`; }
function underline() { return exports.noColor ? '' : `${ESC}4m`; }
function inverse() { return exports.noColor ? '' : `${ESC}7m`; }
function strikethrough() { return exports.noColor ? '' : `${ESC}9m`; }
function clearScreen() { return `${ESC}2J${ESC}H`; }
function alternateScreen() { return `${ESC}?1049h`; }
function mainScreen() { return `${ESC}?1049l`; }
function enableMouseMode() { return `${ESC}?1000h${ESC}?1006h`; }
function disableMouseMode() { return `${ESC}?1000l${ESC}?1006l`; }
function fgColor(color) {
    if (exports.noColor)
        return '';
    switch (color.mode) {
        case 'default': return `${ESC}39m`;
        case 'palette':
            if (color.value < 8)
                return `${ESC}${30 + color.value}m`;
            if (color.value < 16)
                return `${ESC}${90 + color.value - 8}m`;
            return `${ESC}38;5;${color.value}m`;
        case 'rgb': {
            const r = (color.value >> 16) & 0xff;
            const g = (color.value >> 8) & 0xff;
            const b = color.value & 0xff;
            return `${ESC}38;2;${r};${g};${b}m`;
        }
    }
}
function bgColor(color) {
    if (exports.noColor)
        return '';
    switch (color.mode) {
        case 'default': return `${ESC}49m`;
        case 'palette':
            if (color.value < 8)
                return `${ESC}${40 + color.value}m`;
            if (color.value < 16)
                return `${ESC}${100 + color.value - 8}m`;
            return `${ESC}48;5;${color.value}m`;
        case 'rgb': {
            const r = (color.value >> 16) & 0xff;
            const g = (color.value >> 8) & 0xff;
            const b = color.value & 0xff;
            return `${ESC}48;2;${r};${g};${b}m`;
        }
    }
}
//# sourceMappingURL=ansi.js.map