CLI for Oblique Strategies.
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.

26 lines
806 B

  1. export default () => async (card: string) => {
  2. // can't import es modules naturally, we use dynamic imports here
  3. const { default: wrapAnsi } = await import('wrap-ansi');
  4. const Console = console;
  5. const lineWidth = process.stdout.columns ?? 80;
  6. const text = wrapAnsi(card, lineWidth, { hard: true, trim: true });
  7. const lines = text.split('\n').map((line) => {
  8. let centeredLine = line;
  9. while (centeredLine.length < lineWidth) {
  10. // add space after
  11. centeredLine = `${centeredLine} `;
  12. if (centeredLine.length < lineWidth) {
  13. // add space before
  14. centeredLine = ` ${centeredLine}`;
  15. }
  16. }
  17. return centeredLine.slice(0, lineWidth);
  18. });
  19. const displayLines = [...lines];
  20. Console.log();
  21. Console.log(displayLines.join('\n'));
  22. Console.log();
  23. };