The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/lib/logger/showBox.ts

46 lines
1.2 KiB

import s from 'underscore.string';
import * as colors from 'colorette';
// force enable colors on dev env
if (process.env.NODE_ENV !== 'production') {
colors.options.enabled = true;
}
type LogColors = 'white' | 'blue' | 'green' | 'magenta' | 'red';
export function showBox(title: string, message: string, color?: LogColors): void {
const msgLines = message.split('\n');
const len = Math.max.apply(
null,
msgLines.map((line) => line.length),
);
const topLine = `+--${s.pad('', len, '-')}--+`;
const separator = `| ${s.pad('', len, '')} |`;
const lines = [];
lines.push(topLine);
if (title) {
lines.push(`| ${s.lrpad(title, len)} |`);
lines.push(topLine);
}
lines.push(separator);
[...lines, ...msgLines.map((line) => `| ${s.rpad(line, len)} |`), separator, topLine].forEach((line) =>
console.log(color ? colors[color](line) : line),
);
}
export function showErrorBox(title: string, message: string): void {
showBox(title, message, 'red');
}
export function showSuccessBox(title: string, message: string): void {
showBox(title, message, 'green');
}
export function showWarningBox(title: string, message: string): void {
showBox(title, message, 'magenta');
}