You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
2.6 KiB

4 years ago
  1. 'use strict';
  2. const utils = require('./utils');
  3. const colors = require('ansi-colors');
  4. const styles = {
  5. default: colors.noop,
  6. noop: colors.noop,
  7. /**
  8. * Modifiers
  9. */
  10. set inverse(custom) {
  11. this._inverse = custom;
  12. },
  13. get inverse() {
  14. return this._inverse || utils.inverse(this.primary);
  15. },
  16. set complement(custom) {
  17. this._complement = custom;
  18. },
  19. get complement() {
  20. return this._complement || utils.complement(this.primary);
  21. },
  22. /**
  23. * Main color
  24. */
  25. primary: colors.cyan,
  26. /**
  27. * Main palette
  28. */
  29. success: colors.green,
  30. danger: colors.magenta,
  31. strong: colors.bold,
  32. warning: colors.yellow,
  33. muted: colors.dim,
  34. disabled: colors.gray,
  35. dark: colors.dim.gray,
  36. underline: colors.underline,
  37. set info(custom) {
  38. this._info = custom;
  39. },
  40. get info() {
  41. return this._info || this.primary;
  42. },
  43. set em(custom) {
  44. this._em = custom;
  45. },
  46. get em() {
  47. return this._em || this.primary.underline;
  48. },
  49. set heading(custom) {
  50. this._heading = custom;
  51. },
  52. get heading() {
  53. return this._heading || this.muted.underline;
  54. },
  55. /**
  56. * Statuses
  57. */
  58. set pending(custom) {
  59. this._pending = custom;
  60. },
  61. get pending() {
  62. return this._pending || this.primary;
  63. },
  64. set submitted(custom) {
  65. this._submitted = custom;
  66. },
  67. get submitted() {
  68. return this._submitted || this.success;
  69. },
  70. set cancelled(custom) {
  71. this._cancelled = custom;
  72. },
  73. get cancelled() {
  74. return this._cancelled || this.danger;
  75. },
  76. /**
  77. * Special styling
  78. */
  79. set typing(custom) {
  80. this._typing = custom;
  81. },
  82. get typing() {
  83. return this._typing || this.dim;
  84. },
  85. set placeholder(custom) {
  86. this._placeholder = custom;
  87. },
  88. get placeholder() {
  89. return this._placeholder || this.primary.dim;
  90. },
  91. set highlight(custom) {
  92. this._highlight = custom;
  93. },
  94. get highlight() {
  95. return this._highlight || this.inverse;
  96. }
  97. };
  98. styles.merge = (options = {}) => {
  99. if (options.styles && typeof options.styles.enabled === 'boolean') {
  100. colors.enabled = options.styles.enabled;
  101. }
  102. if (options.styles && typeof options.styles.visible === 'boolean') {
  103. colors.visible = options.styles.visible;
  104. }
  105. let result = utils.merge({}, styles, options.styles);
  106. delete result.merge;
  107. for (let key of Object.keys(colors)) {
  108. if (!result.hasOwnProperty(key)) {
  109. Reflect.defineProperty(result, key, { get: () => colors[key] });
  110. }
  111. }
  112. for (let key of Object.keys(colors.styles)) {
  113. if (!result.hasOwnProperty(key)) {
  114. Reflect.defineProperty(result, key, { get: () => colors[key] });
  115. }
  116. }
  117. return result;
  118. };
  119. module.exports = styles;