renderer.js 745 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. const renderers = {
  3. silent: require('listr-silent-renderer'),
  4. verbose: require('listr-verbose-renderer'),
  5. default: require('listr-update-renderer')
  6. };
  7. const isRendererSupported = renderer => process.stdout.isTTY === true || renderer.nonTTY === true;
  8. const getRendererClass = renderer => {
  9. if (typeof renderer === 'string') {
  10. return renderers[renderer] || renderers.default;
  11. }
  12. return typeof renderer === 'function' ? renderer : renderers.default;
  13. };
  14. exports.getRenderer = (renderer, fallbackRenderer) => {
  15. let ret = getRendererClass(renderer);
  16. if (!isRendererSupported(ret)) {
  17. ret = getRendererClass(fallbackRenderer);
  18. if (!ret || !isRendererSupported(ret)) {
  19. ret = renderers.verbose;
  20. }
  21. }
  22. return ret;
  23. };