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