aahook
Version:
A CLI tool that displays ASCII art when commands succeed or fail
145 lines ⢠5.89 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.colorizeCommand = colorizeCommand;
exports.createThemeCommand = createThemeCommand;
const aa_manager_1 = require("../aa-manager");
const color_engine_1 = require("../color/color-engine");
const fs = __importStar(require("fs"));
/**
* Apply color theme to ASCII art
*/
async function colorizeCommand(artName, options = {}) {
const manager = new aa_manager_1.AAManager();
const engine = new color_engine_1.ColorEngine();
try {
// List themes if requested
if (options.listThemes) {
const themes = await engine.listThemes();
console.log('\nšØ Available Color Themes:\n');
for (const theme of themes) {
console.log(` ⢠${theme}`);
}
console.log('\nš” Usage: npx aahook colorize <art> --theme <theme-name>\n');
return;
}
// Get the ASCII art
const art = await manager.getLocal(artName);
if (!art) {
console.error(`\nā ASCII art '${artName}' not found locally.`);
console.error('š” Use "npx aahook gallery" to see installed arts.');
console.error('š” Or install new art with "npx aahook install <category>/<name>"\n');
return;
}
// Determine which theme to use
let coloredArt;
if (options.custom) {
// Load custom theme file
if (!fs.existsSync(options.custom)) {
console.error(`\nā Custom theme file not found: ${options.custom}\n`);
return;
}
console.log(`\nšØ Applying custom theme: ${options.custom}...`);
const customTheme = await engine.parseTheme(options.custom);
coloredArt = engine.applyTheme(art.content, customTheme);
}
else if (options.theme) {
// Load predefined theme
console.log(`\nšØ Applying theme: ${options.theme}...`);
try {
const theme = await engine.loadTheme(options.theme);
coloredArt = engine.applyTheme(art.content, theme);
}
catch (error) {
console.error(`\nā Theme '${options.theme}' not found.`);
console.error('š” Use "npx aahook colorize --list-themes" to see available themes.\n');
return;
}
}
else {
// Default to rainbow theme
console.log('\nš Applying default rainbow theme...');
const rainbowTheme = await engine.loadTheme('rainbow');
coloredArt = engine.applyTheme(art.content, rainbowTheme);
}
// Display the colored art
console.log('\n⨠Colored ASCII Art:\n');
console.log('ā'.repeat(50));
console.log(coloredArt);
console.log('ā'.repeat(50));
// Save if requested
if (options.save) {
const outputName = options.output || `${artName}-colored`;
const savedPath = await engine.saveColoredArt(coloredArt, outputName);
console.log(`\nā
Saved colored art to: ${savedPath}`);
console.log(`š” Use it in hooks: npx aahook config --success colored/${outputName}.txt\n`);
}
else if (!options.preview) {
console.log('\nš” To save this colored version, add --save flag');
console.log('š” Example: npx aahook colorize cat --theme neon --save\n');
}
}
catch (error) {
console.error(`\nā Colorization failed: ${error.message}\n`);
process.exit(1);
}
}
/**
* Create a custom theme interactively (future feature)
*/
async function createThemeCommand(name) {
console.log('\nšØ Theme creator coming soon!');
console.log('For now, create themes manually in ~/.aahook/themes/\n');
const exampleTheme = {
name: name,
version: '1.0.0',
description: 'Custom theme',
author: 'Your name',
colors: {
mode: 'line',
rules: [
{
match: { start: 0, end: 0 },
color: { fg: '#FF0000' }
}
]
}
};
console.log('Example theme structure:');
console.log(JSON.stringify(exampleTheme, null, 2));
console.log('\nModes: line, pattern, character, region');
console.log('Colors: hex (#RRGGBB), named (red, blue), or ANSI (0-255)\n');
}
//# sourceMappingURL=colorize.js.map
;