Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Add --hyperlink option #133

Closed
NightMachinery opened this issue May 16, 2021 · 6 comments
Closed

[FR] Add --hyperlink option #133

NightMachinery opened this issue May 16, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@NightMachinery
Copy link

Terminals have recently gotten support for hyperlinks in ANSI.

tty-link () {
	local link="$1" 
	local desc="${2:-${link:t}}" 
	if test -e "$link"
	then
		link="file://$(hostname)$(grealpath "$link")" 
	fi
	printf '\e]8;;%s\e\\%s\e]8;;\e\\\n' "$link" "$desc"
}

image

It'd be nice to have the filenames as hyperlinks. Ideally, each printed line should be a hyperlink in the style /path/to/file:linenumber:column-of-first-match.

Related:

@genivia-inc genivia-inc added the enhancement New feature or request label May 17, 2021
@genivia-inc
Copy link
Member

@genivia-inc
Copy link
Member

Thanks for the feedback and suggestion.

We could make OSC code hyperlinks the default when color output is enabled. Terminals that do not support this OSC code ignore it, as expected/required. We can extend the color palette GREP_COLORS with a new parameter nh (no hyperlink) to disable this OSC code by the user, just in case if for some reason the terminal does not behave well, like GNU grep has ne to disable EL in case the terminal has issues with EL.

I'm thinking that this is approach probably more intuitive than adding yet another new option. Enabling and disabling hyperlinks depends on the terminal output and is enabled by internal detection of ANSI-capable terminals. Same for ANSI color output.

@NightMachinery
Copy link
Author

Sounds fine to me. I generally prefer having simple options to having mini DSLs like GREP_COLORS, but it’s not a big matter. Thanks!

@genivia-inc
Copy link
Member

According to Hyperlinks (a.k.a. HTML-like anchors) in terminal emulators:

Any terminal that correctly implements OSC parsing according to ECMA-48 is guaranteed not to suffer from compatibility issues. That is, even if explicit hyperlinks aren't supported, the target URI is silently ignored and the supposed-to-be-visible text is displayed, without artifacts.

If a terminal emits garbage upon an OSC 8 explicit hyperlink sequence, that terminal is buggy according to ECMA-48. It is, and will always be, outside of the scope of this specification to deal with buggy terminals.

Alas, that is not the case. After playing a bit with my prototype implementation, I found at least one popular terminal program (on Raspberry Pi) that produces garbage. So it is easy to claim these terminal programs are buggy, but unfortunately we cannot assume that these "buggy terminals" will be fixed anytime soon. Also more -R on MacOS does not like this OSC 8 code and produces garbage, meaning that ugrep --pager will produce garbage. I will make sure ugrep -Q works with this code.

So we need to be more pragmatic. Let's make this optional by adding a new GREP_COLORS parameter hl to enable hyperlinks. Making this part of the color palette has the advantage that the GREP_COLORS variable (or a .ugrep config file) can be used on a machine with a terminal that supports this OSC 8 code. Initially this hl code is disabled by default in ugrep when using the default color palette. If the OSC 8 hyperlink code ever becomes more widely accepted then hl can become the default in ugrep, rather than an option. Adding a --hyperlink option to ugrep is fine too, it just sets --colors=hl to expand the GREP_COLORSpalette currently active.

@genivia-inc
Copy link
Member

This feature is added to ugrep 3.3, available very soon. I've tested this feature with Windows Terminal. It is a nice addition.

@NightMachinery
Copy link
Author

Thanks! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants