style.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. exited: c.yellow(figures.cross),
  17. default: c.cyan('?')
  18. });
  19. const symbol = (done, aborted, exited) =>
  20. aborted ? symbols.aborted : exited ? symbols.exited : done ? symbols.done : symbols.default;
  21. // between the question and the user's input.
  22. const delimiter = completing =>
  23. c.gray(completing ? figures.ellipsis : figures.pointerSmall);
  24. const item = (expandable, expanded) =>
  25. c.gray(expandable ? (expanded ? figures.pointerSmall : '+') : figures.line);
  26. module.exports = {
  27. styles,
  28. render,
  29. symbols,
  30. symbol,
  31. delimiter,
  32. item
  33. };