Search code examples
node.jsterminal

How do I make a clickable terminal link that runs a function in node.js?


I am using ansi-escapes to make the link. How would I make it run a function when the link is clicked? I'm okay with making it run a terminal command. And if so is there some sort of URI that I can use to run a terminal command? I am using Windows Terminal, however I would like it to work for other terminals as well.


Solution

  • If you make a link with a file:/// uri to a batch file, Windows Terminal will run it, because it simply executes open ${url}. From that batch file you can then run something like node terminalCallback.js. The only allowed uri protocols are:

    1. http(s)
    2. file