|
- export default () => async (card: string) => {
- // can't import es modules naturally, we use dynamic imports here
- const { default: wrapAnsi } = await import('wrap-ansi');
-
- const Console = console;
- const lineWidth = process.stdout.columns ?? 80;
- const text = wrapAnsi(card, lineWidth, { hard: true, trim: true });
- const lines = text.split('\n').map((line) => {
- let centeredLine = line;
-
- while (centeredLine.length < lineWidth) {
- // add space after
- centeredLine = `${centeredLine} `;
- if (centeredLine.length < lineWidth) {
- // add space before
- centeredLine = ` ${centeredLine}`;
- }
- }
- return centeredLine.slice(0, lineWidth);
- });
- const displayLines = [...lines];
- Console.log();
- Console.log(displayLines.join('\n'));
- Console.log();
- };
|