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

Add auto modifier to hyperlink argument to match both ls behavior and color argument behavior #746

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mrnossiom
Copy link
Contributor

@mrnossiom mrnossiom commented Dec 27, 2023

Description

Add a WHEN modifier to the --hyperlink argument. This matches both ls behavior and the --color argument behavior.

I think ls is doing it right because you might want to enable --hyperlink in a shell alias but still get plain text when piping into some other program without control chars in the way. Setting --hyperlink in a shell alias is useful for terminal integration (e.g. Kitty).

The public API is compatible since --hyperlink defaults to auto and doesn't break. However, it changes the behavior, with no value the option worked like always but it now defaults to auto. Even though I consider auto to be the right default, maybe it could be changed to always to keep old meaning.

Closes #1059 (duplicate)

@mrnossiom mrnossiom force-pushed the fix/add-auto-ability-to-hyperlink-option branch from 9b6fe20 to f149767 Compare December 27, 2023 12:37
@mrnossiom mrnossiom changed the title feat: add auto option to hyperlink option to match both ls behaviour and color option behaviour Add auto modifier to hyperlink argument to match both ls behavior and color argument behavior Dec 27, 2023
@mrnossiom mrnossiom marked this pull request as ready for review December 27, 2023 12:56
src/theme/mod.rs Outdated Show resolved Hide resolved
@mrnossiom mrnossiom force-pushed the fix/add-auto-ability-to-hyperlink-option branch from 34bc0b1 to 7bb01a2 Compare December 28, 2023 19:05
@mrnossiom
Copy link
Contributor Author

mrnossiom commented Dec 28, 2023

I just noticed that there is a bug in the logic of calculating items lengths with shows when combined with grid option. I guess the hyperlink feature is not used much and that no one reported that.

The target/release/eza binary is built out of 7bb01a2f (right before this message)

image

Argument sets used:

eza --color=auto --hyperlink -GlhFa
eza --color=auto --hyperlink=always -GlhFa
eza --color=auto --hyperlink=never -GlhFa

@PThorpe92
Copy link
Member

I just noticed that there is a bug in the logic of calculating items lengths with shows when combined with grid option. I guess the hyperlink feature is not used much and that no one reported that.

This probably came leftover from #742, which I tested but apparently not the particular combination of hyperlinks, -F and grid because -F seems to be the problem.

with -F

image

without

image

Thanks for reporting this! 👍

@mrnossiom
Copy link
Contributor Author

Do you know why it would trigger only when hyperlinks are enabled ?

@MartinFillon
Copy link
Contributor

Do you know why it would trigger only when hyperlinks are enabled ?

As hyperlinks are not calculated and taken into account when not enabled they are not count for when taking the width

@mrnossiom
Copy link
Contributor Author

Rebased and tested

image

It now works!

@mrnossiom mrnossiom requested a review from MartinFillon July 16, 2024 12:00
@nikelborm
Copy link

nikelborm commented Jul 16, 2024

#1059 Is not duplicate. The changes are different. On top of the same functionality I did refactoring and shell completions

@mrnossiom mrnossiom force-pushed the fix/add-auto-ability-to-hyperlink-option branch from 255e17f to 5e31b92 Compare July 16, 2024 12:53
@mrnossiom
Copy link
Contributor Author

Right, I had forgotten to update the help text.

Copy link
Member

@cafkafk cafkafk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! We don't use merge updates, please remove the merge update commit and use rebase instead to update the branch

@mrnossiom mrnossiom force-pushed the fix/add-auto-ability-to-hyperlink-option branch 2 times, most recently from 5e31b92 to fa8aab1 Compare August 28, 2024 16:44
@mrnossiom mrnossiom requested a review from cafkafk August 28, 2024 17:03
Copy link
Contributor

@MartinFillon MartinFillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mrnossiom mrnossiom force-pushed the fix/add-auto-ability-to-hyperlink-option branch from fa8aab1 to c400597 Compare September 5, 2024 16:32
@mrnossiom mrnossiom requested a review from gierens as a code owner September 5, 2024 16:32
Copy link
Member

@cafkafk cafkafk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the behavior change, this is breaking.

Also, I've found that some terminal emulators do in fact parse hyperlinks that are piped perfectly fine (e.g. kitty) while others (iterm2) doesn't, making the decision as to whether or not to default to auto more important.

I'm wondering what others thing re: defaulting to auto, I'm leaning defaulting to always, since to me, not supporting piped hyperlinks is worse compliance with hyperlinks, and we should support the case where a terminal emulator is doing it's best.

See also:

@mrnossiom
Copy link
Contributor Author

mrnossiom commented Nov 1, 2024

My initial argument for making hyperlink follow the color flag behavior is that I enable it in a ls alias (together with color and icons).

When piping into fzf for example, the icons and the color ANSI codes are disabled but the hyperlinks markers are still there. There is no way to enable hyperlink by default and to disable it when being pipeed in other software.

One way out to make this less breaking is just having --hyperlink default to always but adding the possibility to do --hyperlink=auto. This is still a breaking change I believe, if you had --hyperlink smth_else_not_related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

5 participants