Skip to content

Commit

Permalink
Add example for terminal link provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Aug 10, 2020
1 parent 34fe02c commit 83261e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions terminal-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"onCommand:terminalTest.onDidChangeTerminalDimensions",
"onCommand:terminalTest.onDidWriteTerminalData",
"onCommand:terminalTest.processId",
"onCommand:terminalTest.registerTerminalLinkProvider",
"onCommand:terminalTest.sendText",
"onCommand:terminalTest.sendTextNoNewLine",
"onCommand:terminalTest.show",
Expand Down Expand Up @@ -100,6 +101,10 @@
{
"command": "terminalTest.clearEnvironment",
"title": "Terminal API: Clear environment"
},
{
"command": "terminalTest.registerTerminalLinkProvider",
"title": "Terminal API: Register link provider"
}
]
},
Expand Down
25 changes: 25 additions & 0 deletions terminal-sample/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,31 @@ export function activate(context: vscode.ExtensionContext) {
console.log(`onDidChangeTerminalDimensions: terminal:${event.terminal.name}, columns=${event.dimensions.columns}, rows=${event.dimensions.rows}`);
});
}));

// vscode.window.registerTerminalLinkProvider
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.registerTerminalLinkProvider', () => {
(<any>vscode.window).registerTerminalLinkProvider({
provideTerminalLinks: (context: any, token: vscode.CancellationToken) => {
// Detect the first instance of the word "link" if it exists and linkify it
const startIndex = (context.line as string).indexOf('link');
if (startIndex === -1) {
return [];
}
return [
{
startIndex,
length: 'link'.length,
tooltip: 'Show a notification',
// You can return data in this object to access inside handleTerminalLink
data: 'Example data'
}
];
},
handleTerminalLink: (link: any) => {
vscode.window.showInformationMessage(`Link activated (data = ${link.data})`);
}
});
}));
}

function colorText(text: string): string {
Expand Down

0 comments on commit 83261e3

Please sign in to comment.