feat: make hook hint deep links clickable using OSC 8 terminal hyperlinks#13734
feat: make hook hint deep links clickable using OSC 8 terminal hyperlinks#13734
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Compose hook “next steps” hint to render the Docker Desktop logs deep link as a clickable OSC 8 terminal hyperlink (with underline styling), while suppressing escape sequences when ANSI output is disabled via NO_COLOR or COMPOSE_ANSI=never.
Changes:
- Added
Osc8Linkhelper to generate OSC 8 hyperlinks when ANSI is enabled. - Updated hook hint templates to use hyperlink-wrapped deep links, gated by env-based ANSI suppression.
- Added unit tests for OSC 8 link formatting and hook output under ANSI-enabled/disabled conditions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| cmd/formatter/ansi.go | Adds OSC 8 hyperlink helper and improves lenAnsi documentation. |
| cmd/formatter/ansi_test.go | Adds tests validating OSC 8 hyperlink output and ANSI-disabled behavior. |
| cmd/compose/hooks.go | Converts hint templates to functions and wraps the deep link using OSC 8 when allowed. |
| cmd/compose/hooks_test.go | Updates existing expectations and adds tests for OSC 8 presence/absence based on env. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Osc8Link wraps text in an OSC 8 terminal hyperlink escape sequence with | ||
| // underline styling, making it clickable in supported terminal emulators. | ||
| // When ANSI output is disabled, returns the plain text without escape sequences. | ||
| func Osc8Link(url, text string) string { | ||
| if disableAnsi { | ||
| return text | ||
| } | ||
| return "\033]8;;" + url + "\033\\\033[4m" + text + "\033[24m\033]8;;\033\\" | ||
| } |
There was a problem hiding this comment.
Exported function name Osc8Link doesn’t follow the repository’s initialism convention (e.g., SetANSIMode, URL). Consider renaming it to OSC8Link to match Go initialism style, and update call sites/tests accordingly.
| if shouldDisableAnsi() { | ||
| return url | ||
| } | ||
| return formatter.Osc8Link(url, url) |
There was a problem hiding this comment.
This call site uses formatter.Osc8Link; if the helper is renamed to follow initialism conventions (e.g., OSC8Link), update this reference as well so the hook continues to compile.
| return formatter.Osc8Link(url, url) | |
| return formatter.OSC8Link(url, url) |
| func TestHandleHook_HintContainsOsc8Link(t *testing.T) { | ||
| data := marshalHookData(t, hooks.Request{ | ||
| RootCmd: "compose logs", | ||
| }) | ||
| var buf bytes.Buffer | ||
| err := handleHook([]string{data}, &buf) | ||
| assert.NilError(t, err) | ||
|
|
||
| msg := unmarshalResponse(t, buf.Bytes()) | ||
| // Verify the template contains the OSC 8 hyperlink sequence | ||
| wantLink := formatter.Osc8Link(deepLink, deepLink) | ||
| assert.Assert(t, len(wantLink) > len(deepLink), "Osc8Link should wrap the URL with escape sequences") | ||
| assert.Assert(t, strings.Contains(msg.Template, wantLink), "hint should contain OSC 8 hyperlink") | ||
| } |
There was a problem hiding this comment.
TestHandleHook_HintContainsOsc8Link assumes OSC 8 is enabled, but it doesn’t control NO_COLOR/COMPOSE_ANSI. If either env var is set in the test runner environment, shouldDisableAnsi() will return true and this test will fail/flap. Make the test deterministic by explicitly clearing or setting these env vars to values that allow ANSI before calling handleHook.
…inks Wrap the docker-desktop://dashboard/logs URL in OSC 8 escape sequences with underline styling so it appears as a clickable link in supported terminals. Respects NO_COLOR and COMPOSE_ANSI=never to suppress escapes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
0249bfa to
6734d5e
Compare
|
The |
What I did
Wrap the docker-desktop://dashboard/logs URL in OSC 8 escape sequences with underline styling so it appears as a clickable link in supported terminals. Respects NO_COLOR and COMPOSE_ANSI=never to suppress escapes.
Related issue
N/A
(not mandatory) A picture of a cute animal, if possible in relation to what you did
