fix: enable OSC 8 hyperlinks by default in TTY terminals
What does this MR do?
Enables OSC 8 terminal hyperlinks by default in TTY output. Previously, hyperlinks were off unless the user opted in with display_hyperlinks: true or FORCE_HYPERLINKS=1.
Changes
- Change the default hyperlink mode from
"never"to"auto"iniostreams.New()."auto"emits hyperlinks only when stdout is a TTY and not paged. - Centralize the test default to
"never"incmdtest.TestIOStreamsso existing tests stay unaffected. - Add
display_hyperlinks: falseas the documented opt-out.display_hyperlinks: truenow maps to"auto"(preserves the existing TTY-only semantics for users who already opted in). - Fix a precedence bug where a falsy
FORCE_HYPERLINKS=0orGLAB_FORCE_HYPERLINKS=0would silently overridedisplay_hyperlinks: false. Falsy env values now fall through to the config. - Extract the hyperlink configuration logic into a testable
configureHyperlinksfunction and addTestMain_configureHyperlinkscovering the precedence matrix. - Add a
DisplayHyperlinks()getter toIOStreamsfor test inspection.
Behavior matrix
| Env var | display_hyperlinks |
Resulting mode |
|---|---|---|
FORCE_HYPERLINKS=1 |
any | always |
GLAB_FORCE_HYPERLINKS=1 |
any | always |
FORCE_HYPERLINKS=0 or falsy |
false |
never |
FORCE_HYPERLINKS=0 or falsy |
true |
auto |
| unset | false |
never |
| unset | true |
auto |
| unset | unset | auto (new default) |
How to test
Run glab api --help in a supported terminal without any environment variables or config changes. The "GitLab REST API documentation" and "GitLab GraphQL documentation" links should be clickable.
To verify a falsy FORCE_HYPERLINKS no longer overrides the config opt-out (comment 1 fix):
glab config set display_hyperlinks false
FORCE_HYPERLINKS=0 glab api --helpLinks should appear as plain text.
Related issues and merge requests
Edited by Brendan Lynch