fylgja/src/fylgja-cli/utils/cli_logo.js
Charlotte Croce deedbc7b9f create mkdocs
2025-07-09 22:30:57 -04:00

114 lines
No EOL
4.6 KiB
JavaScript

/**
* cli_logo.js
*
* Gradient-colored ASCII logo for CLI
*/
// Define the ASCII logo
const logoLines = [
'░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓██████▓▒░ ',
'░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ',
'░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ',
'░▒▓██████▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░ ░▒▓█▓▒▒▓███▓▒░ ░▒▓█▓▒░▒▓████████▓▒░ ',
'░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ',
'░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ',
'░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓████████▓▒░▒▓██████▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░ '
];
// Colors (hex codes without # prefix)
const colors = {
teal: '7DE2D1',
darkTeal: '339989',
offWhite: 'FFFAFB',
lavender: '8F95D3'
};
// Convert hex to RGB
function hexToRgb(hex) {
const r = parseInt(hex.substring(0, 2), 16);
const g = parseInt(hex.substring(2, 4), 16);
const b = parseInt(hex.substring(4, 6), 16);
return { r, g, b };
}
// Linear interpolation between two colors
function interpolateColor(color1, color2, factor) {
return {
r: Math.round(color1.r + factor * (color2.r - color1.r)),
g: Math.round(color1.g + factor * (color2.g - color1.g)),
b: Math.round(color1.b + factor * (color2.b - color1.b))
};
}
// Get ANSI true color escape code
function getTrueColorCode(r, g, b) {
return `\x1b[38;2;${r};${g};${b}m`;
}
// Get ANSI 256-color escape code (fallback for terminals without true color support)
function get256ColorCode(r, g, b) {
// Convert RGB to approximate 256-color code
const ansi256 = 16 +
36 * Math.round(r * 5 / 255) +
6 * Math.round(g * 5 / 255) +
Math.round(b * 5 / 255);
return `\x1b[38;5;${ansi256}m`;
}
/**
* Generate a normal logo without any gradient colors
* @returns {string} The plain ASCII logo
*/
function generateNormalLogo() {
return '\n' + logoLines.join('\n') + '\n';
}
/**
* Generate a 2D gradient (both horizontal and vertical gradients combined)
* This creates the most dramatic effect but is more processing-intensive
* @returns {string} The gradient-colored logo
*/
function generateGradientLogo() {
// Convert hex colors to RGB (corners of the 2D gradient)
const topLeft = hexToRgb(colors.teal);
const topRight = hexToRgb(colors.darkTeal);
const bottomLeft = hexToRgb(colors.offWhite);
const bottomRight = hexToRgb(colors.lavender);
// Initialize gradient logo
let gradientLogo = '\n';
// Process each line
for (let y = 0; y < logoLines.length; y++) {
const line = logoLines[y];
const verticalPosition = y / (logoLines.length - 1);
// Interpolate top and bottom colors
const leftColor = interpolateColor(topLeft, bottomLeft, verticalPosition);
const rightColor = interpolateColor(topRight, bottomRight, verticalPosition);
// Process each character in the line
for (let x = 0; x < line.length; x++) {
const char = line[x];
const horizontalPosition = x / (line.length - 1);
// Interpolate between left and right colors
const color = interpolateColor(leftColor, rightColor, horizontalPosition);
// Apply the color and add the character
gradientLogo += getTrueColorCode(color.r, color.g, color.b) + char;
}
// Reset color and add newline
gradientLogo += '\x1b[0m\n';
}
return gradientLogo;
}
// Export the gradient logo functions
module.exports = {
generateNormalLogo,
generateGradientLogo,
};