You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make result file paths hyperlinks on terminal #5189
Terminal emulators nowadays support hyperlinks pretty well.The standard emerged in 2017 and the current list of supporting terminal emulators is pretty exhaustive. Based on a quick prototype, making the links to result files in the console after execution is easy and works very well.
The simple solution ought to work fine on all Linux and OSX terminals and the main problem is handling Windows. The traditional Windows Console isn't a terminal emulator and doesn't support ANSI colors or hyperlinks. We have custom code for handling colors, but I don't think something like that is possible with links. There are, however, various other terminals for Windows and, for example, the Microsoft developed Windows Terminal is a proper terminal emulator that supports both ANSI colors and hyperlinks.
The problem is that we don't currently have any code for detecting terminal capabilities. With colors we, by default, simply use ANSI outside Windows and on Windows use the aforementioned custom solution. Using the same approach with hyperlinks would be easy, but then Windows users with "proper" terminals would need to separately enable hyperlinks with --console-colors ansi (or -C ansi). That's a bit annoying, but I believe it would be fine in the beginning.
I consider this so convenient feature that I tentatively add this to RF 7.1 scope and ask opinions from others on the #devel channel on our Slack. Because we want RF 7.1 out soon, there's no time for anything bigger, so my proposal is to support hyperlinks when ANSI colors are enabled and to keep them disabled on Windows by default. If we agree this is a good approach, I'll submit a separate issue about enhancing terminal capability testing in RF 7.2 to make the Windows support better.
We have a highly related issue #2435 that proposed prefixing result file paths with file:/// to make them hyperlinks on terminals that auto-detect URLs. The problem was that the prefix would have added some clutter and not that many terminal supported this functionality back in 2016 when the issue was submitted. The custom hyperlink support avoids the clutter and also the terminal support is good nowadays.
I committed the changes that enabled hyperlinks using ANSI codes. As explained in the original description, we use ANSI codes by default outside Windows and on Windows it is possible to enable them using -C ansi.
I also did some more studying related to ANSI code support on Windows. Detecting is a virtual terminal supporting them enabled turned out to be reasonable simple using GetConsoleMode and it is also possible to enable a virtual terminal using SetConsoleMode. These functions need to be called using ctypes, but we already have code like that for using colors on Windows.
I did some prototyping and this is what I learned using Windows 10:
Windows Console didn't have a virtual terminal enabled by default, but enabling it succeeded. After that using ANSI color codes on the console worked. Hyperlinks didn't work, but there were no extra artifacts so apparently the console doesn't recognize the used ANSI codes and simply ignores them (as it should in that case). If the console would ever get support for hyperlink ANSI codes, they'd most likely work just fine.
Windows Terminal had a virtual terminal enabled by default. ANSI color codes and hyperlinks worked out-of-the-box both on Power Shell and on Command Prompt. This is great, because Windows Terminal is going to replace Windows Console in the future.
All this looks so promising that I'll commit the changes related to checking and enabling virtual terminal soon as well. After that the hyperlink support ought to depend only on the used terminal.
I've tested that the functionality manually on Linux and on Windows. I've also added an automated test to verify that hyperlink ANSI codes are used and updated the docs related to --console-colors. The latest changes aren't pushed to GitHub yet, but I nevertheless consider this issue done.
This enhancement caused problems with IDE plugins that themselves convert result file paths to links. It's still a unclear where exactly the problem is, but it is safest if we make it possible to disable this behavior. PR #5195 proposed doing that with an environment variable, but I believe we should use a command line option instead because we use them otherwise for such configuration.
We already have --console-colors and --console-width options and I believe we should add --console-links with values AUTO and OFF for this purpose. AUTO would be the default and mean that links are enabled if colors are enabled and OFF would disable them unconditionally. Alternatively we could make --console-links a toggle that could be used like --no-console-links to disable links, but the option require a value means we can add more configuration values in the future is needed.
Consider adding the hostname to the link so that it would be file://host/uri instead of file:///uri we use nowadays. The hyperlink specification recommends that approach although it allows omitting the hostname as well.
It turned out that using file://host/path didn't work on Windows. Trying to use that resulted in a dialog with this error message:
This link type is currently not supported:
file://DESKTOP-QDBVQGD/E:/robotframework/tmp/report.html
I run this on my Windows virtual machine after changing the code to use socket.getfqdn() as the host. Because the error says "link type" I suspect the issue is due to the URI containing the host part.
We could make adding the host component platform dependent, but until there are concrete benefits in adding it outside Windows, I believe it's best to just omit it altogether.
I read a bit more about the hyperlink functionality and the file:// protocol and it seems that including the host name would be pretty convenient in remove access scenarios.
I also found out that the problem I had on Windows is a limitation with Windows Terminal. There's a issue about supporting the host name, but no timeline about when it would be added.
Based on this I believe we should add the host name outside Windows. I guess there can be terminals on Windows that would support them, but I don't know how we could detect that.
@d-biehl reported that on his WSL setup the host name was misconfigured and thus links didn't work. This is only a single data point, but I'm worried this could be pretty common with WSL. In addition to that, getting the host name requires a somewhat slow socket.getfqdn() call. We could try using socket.gethostname() instead, it ought to be a bit faster and it could also avoid the misconfiguration issue, but at this point of RF 7.1 development cycle I believe it's best to just not include the host name at all. That also makes the behavior uniform on different OSes.
Activity
pekkaklarck commentedon Aug 29, 2024
We have a highly related issue #2435 that proposed prefixing result file paths with
file:///to make them hyperlinks on terminals that auto-detect URLs. The problem was that the prefix would have added some clutter and not that many terminal supported this functionality back in 2016 when the issue was submitted. The custom hyperlink support avoids the clutter and also the terminal support is good nowadays.[-]Make result file paths hyperlinks on terminal emulators[/-][+]Make result file paths hyperlinks on terminal[/+]Linkify result paths on console using ANSI codes #5189
pekkaklarck commentedon Aug 29, 2024
I committed the changes that enabled hyperlinks using ANSI codes. As explained in the original description, we use ANSI codes by default outside Windows and on Windows it is possible to enable them using
-C ansi.I also did some more studying related to ANSI code support on Windows. Detecting is a virtual terminal supporting them enabled turned out to be reasonable simple using GetConsoleMode and it is also possible to enable a virtual terminal using SetConsoleMode. These functions need to be called using ctypes, but we already have code like that for using colors on Windows.
I did some prototyping and this is what I learned using Windows 10:
All this looks so promising that I'll commit the changes related to checking and enabling virtual terminal soon as well. After that the hyperlink support ought to depend only on the used terminal.
Enable ANSI codes on Windows if terminal supports them.
pekkaklarck commentedon Aug 29, 2024
I've tested that the functionality manually on Linux and on Windows. I've also added an automated test to verify that hyperlink ANSI codes are used and updated the docs related to
--console-colors. The latest changes aren't pushed to GitHub yet, but I nevertheless consider this issue done.Test terminal hyperlink ANSI code. #5189
1 remaining item
pekkaklarck commentedon Sep 2, 2024
This enhancement caused problems with IDE plugins that themselves convert result file paths to links. It's still a unclear where exactly the problem is, but it is safest if we make it possible to disable this behavior. PR #5195 proposed doing that with an environment variable, but I believe we should use a command line option instead because we use them otherwise for such configuration.
We already have
--console-colorsand--console-widthoptions and I believe we should add--console-linkswith valuesAUTOandOFFfor this purpose.AUTOwould be the default and mean that links are enabled if colors are enabled andOFFwould disable them unconditionally. Alternatively we could make--console-linksa toggle that could be used like--no-console-linksto disable links, but the option require a value means we can add more configuration values in the future is needed.pekkaklarck commentedon Sep 2, 2024
There are some other enhancements to the hyperlink support we should do now that we are making changes anyway require a second release candidate:
as_urito build the link in AnsiHighlighter #5196 does that and explains why it's a good idea in more detail.file://host/uriinstead offile:///uriwe use nowadays. The hyperlink specification recommends that approach although it allows omitting the hostname as well.use `as_uri` to build the link in AnsiHighlighter (#5196)
pekkaklarck commentedon Sep 2, 2024
It turned out that using
file://host/pathdidn't work on Windows. Trying to use that resulted in a dialog with this error message:I run this on my Windows virtual machine after changing the code to use
socket.getfqdn()as the host. Because the error says "link type" I suspect the issue is due to the URI containing the host part.We could make adding the host component platform dependent, but until there are concrete benefits in adding it outside Windows, I believe it's best to just omit it altogether.
pekkaklarck commentedon Sep 2, 2024
I read a bit more about the hyperlink functionality and the
file://protocol and it seems that including the host name would be pretty convenient in remove access scenarios.I also found out that the problem I had on Windows is a limitation with Windows Terminal. There's a issue about supporting the host name, but no timeline about when it would be added.
Based on this I believe we should add the host name outside Windows. I guess there can be terminals on Windows that would support them, but I don't know how we could detect that.
Add host to terminal hyperlinks outside Windows.
Make link to generated User Guide a hyperlink
Add --console-links for controlling using links on console.
pekkaklarck commentedon Sep 4, 2024
@d-biehl reported that on his WSL setup the host name was misconfigured and thus links didn't work. This is only a single data point, but I'm worried this could be pretty common with WSL. In addition to that, getting the host name requires a somewhat slow
socket.getfqdn()call. We could try usingsocket.gethostname()instead, it ought to be a bit faster and it could also avoid the misconfiguration issue, but at this point of RF 7.1 development cycle I believe it's best to just not include the host name at all. That also makes the behavior uniform on different OSes.Remove host name from file URI used in terminal hyperlinks