microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.85k stars 8.34k forks source link

Allow "hyperlink" matching for arbitrary patterns and adding custom handlers #8849

Open mikemaccana opened 3 years ago

mikemaccana commented 3 years ago

Description of the new feature/enhancement

A lot of developer tools print errors in:

dir/dir/filename:lineNumber:columnNumber

format. For example:

image

Terminal should make these clickable.

Proposed technical implementation details (optional)

Leverage any relevant bits about how http links work in the current version of Terminal.

zadjii-msft commented 3 years ago

How would that work though? Do editors have any sort of unified way of requesting "please open this file, to this row/column"? Because I'm pretty sure they don't. VsCode might have one way, emacs another, vim a third - but I'm not sure there's any way for the terminal to know which program is the user's editor for a given filetype.

Plus like, if we ShellExecute a .py file, isn't the default behavior to run the file with the python interpreter? So that's even less likely to work!

I think VSCode's integrated terminal gets away with this because they know the editor is VsCode, and they know exactly how to tell themself how to open a file to a given row/column.

If there's a way of doing this that's supposed to be standard across editors, I'm happy to throw our weight behind it. But I'm not sure how feasible this request is without some sort of standard way of doing this.

ghost commented 3 years ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

KalleOlaviNiemitalo commented 3 years ago

Do editors have any sort of unified way of requesting "please open this file, to this row/column"?

Nano, vim, emacs (or emacsclient), and less support +42 file for opening file and selecting line 42. I don't think there is a common syntax for column numbers in argv.

mikemaccana commented 3 years ago

How would that work though?

As a vscode user

✅ Open file:lineNumbers in editor Editor command. $FILE is the file name, $COLUMN is the column name [ code.exe --goto "$FILE:$LINE" ]

As a vi user

✅ Open file:lineNumbers in editor Editor command. $FILE is the file name, $COLUMN is the column name [ vi $FILE +$LINE ]

DHowett commented 3 years ago

This is just a specific case of #8902 (which somebody just filed!). We should consolidate.

zadjii-msft commented 3 years ago

Okay, I'll work on consolidating this with 8902, and comments we've mentioned elsewhere.

mikemaccana commented 3 years ago

Thanks!

zadjii-msft commented 3 years ago

And what about support editor:// protocol handler? aik099/PhpStormProtocol

image


As of Windows Terminal Preview 1.4 (I think) you can Ctrl+click on text that matches a URL and it will open in a browser. This feature request would be to match on certain text and turn that into a clickable link using some of the text as a parameter.

Example

Let's say the following is on the terminal, from the output of git log

Fixes issue in T1234

I would like to setup a regex \b(T\d+)\b and when I Ctrl+click on T1234, open up https://example.com/tasks/T1234.

I would like this to be configured in settings.json something like

"arbitrarylinks": [
    {
        "pattern": "\\b(T\\d+)\\b",
        "link": "https://example.com/tasks/$1"
    }
]

So lets say we wanted to solve both these cases. What we need is a way to specify:

So we couldn't just do this automatically for all editors in one unified fashion, unfortunately. But we could allow users to add config for their specific editor.

DHowett commented 3 years ago

This could also be an extension point. /cc @zadjii-msft triaged into backlog.

stinos commented 3 years ago

How would that work though?

Could have a look at how ConEmu does it: supply a bunch of 'macros' which are fed into a custom command and replaced there. Activated with Ctrl key but that's minor. See https://conemu.github.io/en/SettingsHighlight.html.

This is the only reason I'm still not on Terminal fulltime: it's not interesting to have to manually copy/paste file/line from the terminal to the editor.

Klaster1 commented 10 months ago

Any updates on this? Not baing able to click on file paths in output like in ConEmu is a huge deal breaker, I do this all the time while working with tests and TypeScript.

zadjii-msft commented 9 months ago

Nothing since I posted the spec draft in #15700. Alas, been too busy with other priorities to loop back on that one.

From that spec:

Turn text into clickable links

A similar request from [#8849] that should also be captured. People want the ability to configure the regexes that are used for turning text into clickable links. Currently, we only match on a predefined set into clickable text.

// I did not test these regexes
{
    "match": "(^(.+)\\/([^\\/]+)$):(\\d):(\\d)",
    "action": "clickableLink",
    "target": "code.exe --goto \"${match[1]}:${match[2]}\""
},
{
    "match": "git push --set-upstream origin ([^\\w]*)",
    "action": "clickableLink",
    "target": "vi \"${match[1]}\" +${match[2]}\""
},
{
    "match": "\\b(T\\d+)\\b",
    "action": "clickableLink",
    "target": "https://example.com/tasks/${match[1]}"
},
trajano commented 6 months ago

I'd also like a simple pattern to translate the SSH azure devops links to HTTP equivalents.

e.g. ssh.dev.azure.com:v3/ORG/PROJ/REPO to https://dev.azure.com/ORG/PROJ/_git/REPO