style.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const c = require('kleur');
  3. const figures = require('./figures');
  4. // rendering user input.
  5. const styles = Object.freeze({
  6. password: { scale: 1, render: input => '*'.repeat(input.length) },
  7. emoji: { scale: 2, render: input => '😃'.repeat(input.length) },
  8. invisible: { scale: 0, render: input => '' },
  9. default: { scale: 1, render: input => `${input}` }
  10. });
  11. const render = type => styles[type] || styles.default;
  12. // icon to signalize a prompt.
  13. const symbols = Object.freeze({
  14. aborted: c.red(figures.cross),
  15. done: c.green(figures.tick),
  16. default: c.cyan('?')
  17. });
  18. const symbol = (done, aborted) => aborted ? symbols.aborted : done ? symbols.done : symbols.default;
  19. // between the question and the user's input.
  20. const delimiter = completing => c.gray(completing ? figures.ellipsis : figures.pointerSmall);
  21. const item = (expandable, expanded) => c.gray(expandable ? expanded ? figures.pointerSmall : '+' : figures.line);
  22. module.exports = {
  23. styles,
  24. render,
  25. symbols,
  26. symbol,
  27. delimiter,
  28. item
  29. };