UNPKG

@paulstinchcombe/kami721c-sdk

Version:

SDK for interacting with KAMI721C NFT contracts

81 lines (73 loc) 3 kB
/** * Console color utility - provides functions for colorized terminal output */ // Define ANSI color code constants export const colors = { // Text colors reset: '\x1b[0m', black: '\x1b[30m', red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', blue: '\x1b[34m', magenta: '\x1b[35m', cyan: '\x1b[36m', white: '\x1b[37m', // Bright text colors brightRed: '\x1b[91m', brightGreen: '\x1b[92m', brightYellow: '\x1b[93m', brightBlue: '\x1b[94m', brightMagenta: '\x1b[95m', brightCyan: '\x1b[96m', brightWhite: '\x1b[97m', // Background colors (can be combined with text colors) bgBlack: '\x1b[40m', bgRed: '\x1b[41m', bgGreen: '\x1b[42m', bgYellow: '\x1b[43m', bgBlue: '\x1b[44m', bgMagenta: '\x1b[45m', bgCyan: '\x1b[46m', bgWhite: '\x1b[47m', // Text styles bold: '\x1b[1m', dim: '\x1b[2m', italic: '\x1b[3m', underline: '\x1b[4m', }; // Helper functions for common log types export const logStyles = { info: (text: string): string => `${colors.cyan}${text}${colors.reset}`, success: (text: string): string => `${colors.green}${text}${colors.reset}`, warning: (text: string): string => `${colors.yellow}${text}${colors.reset}`, error: (text: string): string => `${colors.red}${text}${colors.reset}`, highlight: (text: string): string => `${colors.bold}${colors.brightYellow}${text}${colors.reset}`, important: (text: string): string => `${colors.bold}${colors.magenta}${text}${colors.reset}`, transaction: (text: string): string => `${colors.brightBlue}${text}${colors.reset}`, hash: (hash: string): string => `${colors.dim}${hash.substring(0, 10)}...${hash.substring(58)}${colors.reset}`, address: (address: string): string => `${colors.cyan}${address.substring(0, 6)}...${address.substring(38)}${colors.reset}`, title: (text: string): string => `${colors.bold}${colors.brightWhite}${text}${colors.reset}`, section: (text: string): string => `\n${colors.bold}${colors.brightCyan}=== ${text} ===${colors.reset}\n`, value: (text: string | number | bigint): string => `${colors.brightGreen}${text}${colors.reset}`, label: (text: string): string => `${colors.brightWhite}${text}${colors.reset}`, }; // Simple colorized logging functions export const colorLog = { info: (message: string): void => console.log(logStyles.info(message)), success: (message: string): void => console.log(logStyles.success(message)), warning: (message: string): void => console.log(logStyles.warning(message)), error: (message: string): void => console.error(logStyles.error(message)), transaction: (message: string, hash?: string): void => { if (hash) { console.log(`${logStyles.transaction(message)} ${logStyles.hash(hash)}`); } else { console.log(logStyles.transaction(message)); } }, section: (title: string): void => console.log(logStyles.section(title)), }; // Format a key-value pair for logging export function formatKeyValue(key: string, value: string | number | bigint): string { return `${logStyles.label(key)}: ${logStyles.value(value)}`; }