Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 516x 516x 232x 232x 232x 232x 232x 232x 232x 1x 1x 1x 1x 1x 180x 180x 180x 180x 1x 1x 26x 26x 26x 26x 26x 26x 26x 26x 26x 1x 26x 26x 26x 26x 26x 26x 26x 26x 26x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /**
* Console logging utilities with pretty formatting
*/
// ANSI color codes for terminal output
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
dim: '\x1b[2m',
underscore: '\x1b[4m',
blink: '\x1b[5m',
reverse: '\x1b[7m',
hidden: '\x1b[8m',
// Foreground colors
black: '\x1b[30m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
white: '\x1b[37m',
gray: '\x1b[90m',
// Background 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',
} as const;
// Check if we're in a browser or Node.js environment
const isBrowser =
typeof window !== 'undefined' && typeof window.document !== 'undefined';
const supportsColor = !isBrowser && process.stdout?.isTTY;
/**
* Apply color to text if colors are supported
*/
function colorize(text: string, color: string): string {
if (!supportsColor) return text;
return `${color}${text}${colors.reset}`;
}
/**
* Get current timestamp in HH:MM:SS format
*/
function getTimestamp(): string {
const now = new Date();
const hours = now.getHours().toString().padStart(2, '0');
const minutes = now.getMinutes().toString().padStart(2, '0');
const seconds = now.getSeconds().toString().padStart(2, '0');
return `${hours}:${minutes}:${seconds}`;
}
/**
* Print a message with a bold header
*/
export function printWithHeader(header: string, body: string): void {
const formattedHeader = colorize(header, colors.bright + colors.cyan);
console.log(`\n${formattedHeader}`);
console.log(body);
}
/**
* Print a divider line
*/
export function printDivider(char = '─', length = 60): void {
console.log(colorize(char.repeat(length), colors.dim));
}
/**
* Print text in a box with borders
*/
export function printBox(text: string, title?: string): void {
const lines = text.split('\n');
const maxLength = Math.max(...lines.map((l) => l.length), title?.length ?? 0);
const top = `┌${'─'.repeat(maxLength + 2)}┐`;
const bottom = `└${'─'.repeat(maxLength + 2)}┘`;
console.log(colorize(top, colors.dim));
if (title) {
const titleLine = `│ ${colorize(title.padEnd(maxLength), colors.bright + colors.cyan)} │`;
console.log(colorize(titleLine.replace(colors.reset, ''), colors.dim));
console.log(colorize(`├${'─'.repeat(maxLength + 2)}┤`, colors.dim));
}
lines.forEach((line) => {
const paddedLine = line.padEnd(maxLength);
console.log(
`${colorize('│', colors.dim)} ${paddedLine} ${colorize('│', colors.dim)}`,
);
});
console.log(colorize(bottom, colors.dim));
}
/**
* Standard log (gray timestamp + message)
*/
export function log(...args: unknown[]): void {
const timestamp = colorize(`[${getTimestamp()}]`, colors.gray);
console.log(timestamp, ...args);
}
/**
* Info message (blue icon + message)
*/
export function info(...args: unknown[]): void {
const prefix = colorize('ℹ', colors.blue);
const timestamp = colorize(`[${getTimestamp()}]`, colors.gray);
console.info(timestamp, prefix, ...args);
}
/**
* Success message (green checkmark + message)
*/
export function success(...args: unknown[]): void {
const prefix = colorize('✓', colors.green);
const timestamp = colorize(`[${getTimestamp()}]`, colors.gray);
console.log(
timestamp,
prefix,
colorize(String(args[0]), colors.green),
...args.slice(1),
);
}
/**
* Warning message (yellow warning sign + message)
*/
export function warn(...args: unknown[]): void {
const prefix = colorize('⚠', colors.yellow);
const timestamp = colorize(`[${getTimestamp()}]`, colors.gray);
console.warn(
timestamp,
prefix,
colorize(String(args[0]), colors.yellow),
...args.slice(1),
);
}
/**
* Error message (red X + message)
*/
export function error(...args: unknown[]): void {
const prefix = colorize('✖', colors.red);
const timestamp = colorize(`[${getTimestamp()}]`, colors.gray);
console.error(
timestamp,
prefix,
colorize(String(args[0]), colors.red),
...args.slice(1),
);
}
/**
* Debug message (magenta bug icon + dimmed message)
*/
export function debug(...args: unknown[]): void {
if (process.env.NODE_ENV === 'production') return;
const prefix = colorize('🐛', colors.magenta);
const timestamp = colorize(`[${getTimestamp()}]`, colors.gray);
const dimmedArgs = args.map((arg) =>
typeof arg === 'string' ? colorize(arg, colors.dim) : arg,
);
console.debug(timestamp, prefix, ...dimmedArgs);
}
/**
* Print a progress indicator
*/
export function progress(current: number, total: number, label?: string): void {
const percentage = Math.round((current / total) * 100);
const barLength = 30;
const filled = Math.round((current / total) * barLength);
const empty = barLength - filled;
const bar = `[${colorize('█'.repeat(filled), colors.green)}${'░'.repeat(empty)}]`;
const percentStr = `${percentage}%`.padStart(4);
const progressStr = `${current}/${total}`.padStart(9);
const output = `${bar} ${colorize(percentStr, colors.bright)} ${progressStr}`;
const fullOutput = label
? `${output} ${colorize(label, colors.dim)}`
: output;
// Use carriage return to update the same line
process.stdout.write(`\r${fullOutput}`);
// Add newline when complete
if (current === total) {
console.log();
}
}
/**
* Print a table from array of objects
*/
export function table(
data: Record<string, unknown>[],
headers?: string[],
): void {
if (data.length === 0) {
console.log('No data to display');
return;
}
const keys = headers || Object.keys(data[0]);
const columnWidths: Record<string, number> = {};
// Calculate column widths
keys.forEach((key) => {
columnWidths[key] = Math.max(
key.length,
...data.map((row) => String(row[key] ?? '').length),
);
});
// Print header
const headerRow = keys
.map((key) =>
colorize(key.padEnd(columnWidths[key]), colors.bright + colors.cyan),
)
.join(' │ ');
console.log(headerRow);
// Print separator
const separator = keys
.map((key) => '─'.repeat(columnWidths[key]))
.join('─┼─');
console.log(colorize(separator, colors.dim));
// Print rows
data.forEach((row) => {
const rowStr = keys
.map((key) => String(row[key] ?? '').padEnd(columnWidths[key]))
.join(' │ ');
console.log(rowStr);
});
}
/**
* Group related logs together with indentation
*/
export function group(label: string, fn: () => void): void {
console.group(colorize(label, colors.bright + colors.cyan));
fn();
console.groupEnd();
}
/**
* Group related async logs together with indentation
*/
export async function groupAsync(
label: string,
fn: () => Promise<void>,
): Promise<void> {
console.group(colorize(label, colors.bright + colors.cyan));
await fn();
console.groupEnd();
}
/**
* Clear the console
*/
export function clear(): void {
console.clear();
}
/**
* Print JSON with syntax highlighting
*/
export function json(obj: Record<string, unknown>, indent = 2): void {
if (supportsColor) {
const highlighted = JSON.stringify(obj, null, indent)
.replace(/("[\w]+":)/g, colorize('$1', colors.blue)) // Keys
.replace(/: "([^"]*)"/g, `: ${colorize('"$1"', colors.green)}`) // String values
.replace(/: (\d+)/g, `: ${colorize('$1', colors.yellow)}`) // Numbers
.replace(/: (true|false)/g, `: ${colorize('$1', colors.magenta)}`) // Booleans
.replace(/: (null)/g, `: ${colorize('$1', colors.red)}`); // Null
console.log(highlighted);
} else {
console.log(JSON.stringify(obj, null, indent));
}
}
/**
* Print a tree structure
*/
export function tree(
obj: Record<string, unknown>,
_indent = '',
isLast = true,
isRoot = true,
): void {
if (isRoot) {
console.log(colorize('┬', colors.dim));
}
if (typeof obj !== 'object' || obj === null) {
console.log(colorize(String(obj), colors.green));
return;
}
const entries = Object.entries(obj);
entries.forEach(([key, value], index) => {
const isLastItem = index === entries.length - 1;
const prefix = isRoot ? '' : isLast ? ' ' : '│ ';
const connector = isLastItem ? '└─' : '├─';
console.log(
colorize(prefix + connector, colors.dim),
colorize(key, colors.cyan),
);
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
tree(value as Record<string, unknown>, prefix, isLastItem, false);
} else if (Array.isArray(value)) {
const arrPrefix = prefix + (isLastItem ? ' ' : '│ ');
value.forEach((item, i) => {
const arrConnector = i === value.length - 1 ? '└─' : '├─';
console.log(colorize(arrPrefix + arrConnector, colors.dim), item);
});
} else {
const valuePrefix = prefix + (isLastItem ? ' ' : '│ ');
console.log(
colorize(`${valuePrefix}└─`, colors.dim),
colorize(String(value), colors.green),
);
}
});
}
// Export all functions as a default object for convenience
export default {
printWithHeader,
printDivider,
printBox,
log,
info,
success,
warn,
error,
debug,
progress,
table,
group,
groupAsync,
clear,
json,
tree,
};
|