randy3k / Terminus

Bring a real terminal to Sublime Text
https://packagecontrol.io/packages/Terminus
MIT License
1.37k stars 83 forks source link

Clicking on file links in terminus build systems? #341

Closed MK-Alias closed 2 years ago

MK-Alias commented 2 years ago

Hello,

I'm using a build system that outputs traced code with filename:line_number for debugging. VScode picks up on this automatically but Terminus does not. I believe there are regex options to accomplish this, but don't know where to start!

Example output of my trace:

 [ c:\path\to\source\main.cpp:10 ] ## hello world!

I would like to be able to click on it to take me to the source at line 10, can someone please point me to the right direction.!?

Any help on this would be greatly appriciated!

Thanks!

MK-Alias commented 2 years ago

I've literally never wrote a regexp before, but with some practice I came up with this:

(.:\/(?:(?!\:).)*|.:\\(?:(?!\:).)*|\.\/(?:(?!\:).)*|\.\\(?:(?!\:).)*|\\(?:(?!\:).)*|\/(?:(?!\:).)*):([0-9]+)

to put this in the build system, you MUST escape the backslashes and put in a variable named: file_regex like this:

{
  "file_regex": "(.:\\/(?:(?!\\:).)*|.:\\\\(?:(?!\\:).)*|\\.\\/(?:(?!\\:).)*|\\.\\\\(?:(?!\\:).)*|\\\\(?:(?!\\:).)*|\\/(?:(?!\\:).)*):([0-9]+)"
}

This will select any windows or unix file-path in the first group and the line number in the second group. This is exactly what i was needing, it can select all these examples, regardless of their surroundings:

C:\path\to\file.cpp:10
c:/path/to/file.cpp:10
c:/path\to/changing\slashes.cpp:100
/path/to/file:50
\path\to/changing\slashes:100
./path/to/file.cpp:30
.\path/to/file.cpp:50

The only limitation is that the filename MUST start with on of:

X:\
X:/
/
\
./
.\

So if you have any lose filenames like this:

filename.cpp:100

you must convert it to

./filename.cpp:100
.\filename.cpp:100

And the line-number :100 is mandatory!

TIP: use :0 if unknown/unneeded