terminalLink.js 481 B

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