terminalLink.js 496 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const supportsHyperlinks = require('supports-hyperlinks');
  3. // ANSI escapes
  4. const OSC = '\u001B]';
  5. const BEL = '\u0007';
  6. const SEP = ';';
  7. /**
  8. * @see https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
  9. *
  10. * @param {string} text
  11. * @param {string} url
  12. * @returns {string}
  13. */
  14. module.exports = function terminalLink(text, url) {
  15. if (supportsHyperlinks.stdout) {
  16. return [OSC, '8', SEP, SEP, url, BEL, text, OSC, '8', SEP, SEP, BEL].join('');
  17. }
  18. return text;
  19. };