DEV Community

Valeria
Valeria

Posted on

Day 17: Terminal Links & Other Escapes 🔗

Ever wondered how to make a clickable link in a terminal? Well you don't have to wonder no more: you can use special ANSI code for it!
And ansi-escapes have you covered!

Install the package with e.g. deno add npm:ansi-escapes and create a file, e.g. main.ts:

import {link as createLink} from "ansi-escapes";

const link = createLink("link", "https://valeriavg.dev");

console.log(`Hello! Would you like to check this ${link} perhaps?`);
Enter fullscreen mode Exit fullscreen mode

Run with e.g. deno run -A ./main.ts and enjoy:

VSCode Terminal with a link

The screenshot is from VSCode terminal, but not every terminal would support links!

On Mac, for example, iTerm2 would support it:

iTerm2

But default terminal app would not:

Mac terminal

There are other libraries that would help you detect if a feature is supported or not and ansi-escapes comes with a lot of features!

Check it out and do share your creations!

Liked the content and would love to have more of it all year long?

Buy Me A Coffee

Top comments (0)