render.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. module.exports = async(value, prompt, context = {}) => {
  3. let { choices, multiple } = prompt.options;
  4. let { size, submitted } = prompt.state;
  5. let prefix = context.prefix || await prompt.prefix();
  6. let separator = context.separator || await prompt.separator();
  7. let message = context.message || await prompt.message();
  8. // ? Select your favorite colors >
  9. // ^ ^ ^
  10. // prefix message separator
  11. let promptLine = [prefix, message, separator].filter(Boolean).join(' ');
  12. prompt.state.prompt = promptLine;
  13. let header = context.header || await prompt.header();
  14. let output = context.format || await prompt.format(value);
  15. let help = context.help || await prompt.error() || await prompt.hint();
  16. let body = context.body || await prompt.body();
  17. let footer = context.footer || await prompt.footer();
  18. if (output || !help) promptLine += ' ' + output;
  19. if (help && !promptLine.includes(help)) promptLine += ' ' + help;
  20. if (submitted && choices && multiple && !output && !body) {
  21. promptLine += prompt.styles.danger('No items were selected');
  22. }
  23. prompt.clear(size);
  24. prompt.write([header, promptLine, body, footer].filter(Boolean).join('\n'));
  25. prompt.restore();
  26. };