roles.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. const utils = require('./utils');
  3. const roles = {
  4. default(prompt, choice) {
  5. return choice;
  6. },
  7. checkbox(prompt, choice) {
  8. throw new Error('checkbox role is not implemented yet');
  9. },
  10. editable(prompt, choice) {
  11. throw new Error('editable role is not implemented yet');
  12. },
  13. expandable(prompt, choice) {
  14. throw new Error('expandable role is not implemented yet');
  15. },
  16. heading(prompt, choice) {
  17. choice.disabled = '';
  18. choice.indicator = [choice.indicator, ' '].find(v => v != null);
  19. choice.message = choice.message || '';
  20. return choice;
  21. },
  22. input(prompt, choice) {
  23. throw new Error('input role is not implemented yet');
  24. },
  25. option(prompt, choice) {
  26. return roles.default(prompt, choice);
  27. },
  28. radio(prompt, choice) {
  29. throw new Error('radio role is not implemented yet');
  30. },
  31. separator(prompt, choice) {
  32. choice.disabled = '';
  33. choice.indicator = [choice.indicator, ' '].find(v => v != null);
  34. choice.message = choice.message || prompt.symbols.line.repeat(5);
  35. return choice;
  36. },
  37. spacer(prompt, choice) {
  38. return choice;
  39. }
  40. };
  41. module.exports = (name, options = {}) => {
  42. let role = utils.merge({}, roles, options.roles);
  43. return role[name] || role.default;
  44. };