Skip to content

fix(app): switch to native clipboard library#82

Merged
gammons merged 10 commits into
gammons:mainfrom
gcgbarbosa:main
Jun 11, 2026
Merged

fix(app): switch to native clipboard library#82
gammons merged 10 commits into
gammons:mainfrom
gcgbarbosa:main

Conversation

@gcgbarbosa

Copy link
Copy Markdown
Contributor

Replaces tea.SetClipboard with golang.design/x/clipboard . Fixes copying failures on macOS (especially inside tmux environments). Works across macOS, Linux, and Windows.

Fixes #80

Replaces `tea.SetClipboard` with `golang.design/x/clipboard` .
Fixes copying failures on macOS (especially inside tmux environments).
Works across macOS, Linux, and Windows.
@gammons

gammons commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Thanks for this — switching to golang.design/x/clipboard is the right call and matches how the rest of the app already handles the clipboard (smart-paste, image attach). One blocking issue plus minor cleanup:

Blocking: unguarded clipboard.Write can panic the app. The library requires a successful clipboard.Init() before any Write; its docs note that otherwise Read/Write "may result in an unrecoverable panic." Everywhere else in the codebase the clipboard is gated behind a.clipboardAvailable (set from the clipboard.Init() result in cmd/slk/main.go), e.g. smartPaste. This new path is the only unguarded call, so on environments where init failed (Wayland without wl-clipboard, headless/SSH, missing libx11) pressing Y would crash instead of no-op.

Minor: false success toast. _ = clipboard.Write(...) discards the result and then always returns PermalinkCopiedMsg{}, so a failed write still shows "Copied permalink" — basically the original #80 symptom relocated. Guarding on clipboardAvailable fixes both:

if !a.clipboardAvailable {
    return nil
}
_ = clipboard.Write(clipboard.FmtText, []byte(url))
return statusbar.PermalinkCopiedMsg{}

Cosmetic: gofmt -l flags the file — a double blank line in the imports, trailing whitespace on two blank lines, and a stray blank line before openLinksOfSelected. A quick gofmt -w internal/ui/app.go cleans it up.

Replaces `tea.SetClipboard` with `golang.design/x/clipboard` inside the `MouseReleaseMsg` handler.
- Added `a.clipboardAvailable` guard to prevent panics
- Added `CopyFailedMsg` error notification
@gcgbarbosa gcgbarbosa closed this Jun 11, 2026
@gcgbarbosa gcgbarbosa reopened this Jun 11, 2026
@gcgbarbosa

Copy link
Copy Markdown
Contributor Author

should be good now @gammons

@gammons

gammons commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Thanks for the updates — the clipboardAvailable guard is the right fix, and extending it to the mouse-selection copy in drag.go is a nice catch.

One blocker though: CI will be red. go test ./... fails 5 tests that pass on main:

TestCopyPermalink_FromMessagesPane    (got PermalinkCopyFailedMsg, want PermalinkCopiedMsg)
TestCopyPermalink_FromThreadPane
TestCopyPermalink_ShiftYTriggersCopy
TestApp_DragInMessagesEmitsClipboardAndToast
TestDrag_MotionCoalescing_ReleaseFlushesPending

Root cause: tests build the App without calling clipboard.Init(), so clipboardAvailable is false and the new guard short-circuits the success path to the failure message. Clipboard reads are injectable (clipboardRead / SetClipboardReader) but the new writes call package-level clipboard.Write directly, so tests can't simulate a successful copy — and flipping clipboardAvailable = true would then hit the real clipboard.Write, which can panic in headless CI.

Suggest mirroring the read seam: add a clipboardWrite field (default clipboard.Write) + SetClipboardWriter hook, use it in app.go and drag.go, then update the 5 tests to inject a fake writer (and the two drag tests to stop expecting tea.SetClipboard).

Minor: gofmt -l still flags internal/ui/app.go (trailing whitespace on the two tab-only blank lines + a double blank line before openLinksOfSelected).

- clipboardWrite field
- initialize clipboardWrite with a default writer.
- copyPermalinkOfSelected method  use clipboardWrite instead of a direct call.
- SetClipboardWriter method allow tests to inject a fake writer
- Removed redundant reflection checks for clipboard messages.
- Enhanced clipboard integration in tests by using the `clipboard` package directly.
- Added checks to ensure that clipboard data is correctly written during drag actions and message copy operations.
- Ensured that plain clicks do not erroneously write to the clipboard or emit copied messages.
@gammons

gammons commented Jun 11, 2026

Copy link
Copy Markdown
Owner

thanks @gcgbarbosa !

@gammons gammons merged commit b671575 into gammons:main Jun 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permalinks are not working on ghostty + macosx

2 participants