terminal icon indicating copy to clipboard operation
terminal copied to clipboard

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

Open mikemaccana opened this issue 3 years ago • 12 comments

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.

mikemaccana avatar Jan 22 '21 14:01 mikemaccana

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.

zadjii-msft avatar Jan 22 '21 15:01 zadjii-msft

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.

ghost avatar Jan 26 '21 16:01 ghost

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.

KalleOlaviNiemitalo avatar Jan 26 '21 18:01 KalleOlaviNiemitalo

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 ]

mikemaccana avatar Jan 26 '21 18:01 mikemaccana

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

DHowett avatar Jan 26 '21 18:01 DHowett

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

zadjii-msft avatar Jan 26 '21 18:01 zadjii-msft

Thanks!

mikemaccana avatar Jan 26 '21 18:01 mikemaccana

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:

  • I want to match an arbitrary pattern of text in the Terminal, and
  • When I click on such a pattern, what do we do?
    • Right now, we just ShellExecute the hyperlink.
    • We need to also be able to ShellExecute links that users specify, with contents from the match
    • We also need to be able to execute arbitrary executables that the user has specified, again using contents from the match

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.

zadjii-msft avatar Jan 26 '21 18:01 zadjii-msft

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

DHowett avatar Jan 28 '21 02:01 DHowett

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.

stinos avatar Mar 24 '21 08:03 stinos

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.

Klaster1 avatar Jan 30 '24 05:01 Klaster1

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]}"
},

zadjii-msft avatar Jan 30 '24 15:01 zadjii-msft

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

trajano avatar May 14 '24 15:05 trajano