From d2154c82ab4dff045a505d6adbe05dfe68a3cb4d Mon Sep 17 00:00:00 2001 From: Charlotte Croce Date: Sun, 20 Apr 2025 17:34:03 -0400 Subject: [PATCH] create CLI logo --- src/fylgja-cli.js | 15 ++---- src/logo.js | 0 src/utils/cli-logo.js | 105 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 12 deletions(-) delete mode 100644 src/logo.js create mode 100644 src/utils/cli-logo.js diff --git a/src/fylgja-cli.js b/src/fylgja-cli.js index 70b7b15..db63a7d 100644 --- a/src/fylgja-cli.js +++ b/src/fylgja-cli.js @@ -13,6 +13,8 @@ const { handleCommand: handleAlerts } = require('./handlers/alerts/alerts_handle const { handleCommand: handleCase } = require('./handlers/case/case_handler'); const { handleCommand: handleConfig } = require('./handlers/config/config_handler'); const { handleCommand: handleStats } = require('./handlers/stats/stats_handler'); +const { generateGradientLogo } = require('./utils/cli-logo'); + const readline = require('readline'); @@ -87,17 +89,6 @@ try { const FILE_NAME = 'fylgja-cli.js'; -// ASCII art logo for the CLI -const ASCII_LOGO = ` -░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓██████▓▒░ -░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ -░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ -░▒▓██████▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░ ░▒▓█▓▒▒▓███▓▒░ ░▒▓█▓▒░▒▓████████▓▒░ -░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ -░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ -░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓████████▓▒░▒▓██████▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░ -`; - // Command history array let commandHistory = []; let historyIndex = -1; @@ -679,7 +670,7 @@ CLI Commands: * Start the CLI application */ function startCLI() { - console.log(ASCII_LOGO); + console.log(generateGradientLogo()); console.log(`Fylgja CLI v${version} - Interactive SIEM Management Tool`); console.log(`Type 'help' for usage information or 'exit' to quit\n`); diff --git a/src/logo.js b/src/logo.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/utils/cli-logo.js b/src/utils/cli-logo.js new file mode 100644 index 0000000..70c887f --- /dev/null +++ b/src/utils/cli-logo.js @@ -0,0 +1,105 @@ +/** + * 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 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 = { + generateGradientLogo, + }; \ No newline at end of file