From 3c64ee0ce1989e3f5cc97d7b5df8e97fcc04e90a Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Fri, 16 Jan 2026 15:59:23 -0500 Subject: [PATCH] fix: editor: exclude native clipboard support from linux/386 builds (#1903) --- internal/tui/components/chat/editor/clipboard.go | 8 ++++++++ .../components/chat/editor/clipboard_linux_386.go | 7 +++++++ .../tui/components/chat/editor/clipboard_other.go | 15 +++++++++++++++ internal/tui/components/chat/editor/editor.go | 10 +++++++--- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 internal/tui/components/chat/editor/clipboard.go create mode 100644 internal/tui/components/chat/editor/clipboard_linux_386.go create mode 100644 internal/tui/components/chat/editor/clipboard_other.go diff --git a/internal/tui/components/chat/editor/clipboard.go b/internal/tui/components/chat/editor/clipboard.go new file mode 100644 index 0000000000000000000000000000000000000000..de4b95da3cab6069bf31f61b5fb9e2908f970c07 --- /dev/null +++ b/internal/tui/components/chat/editor/clipboard.go @@ -0,0 +1,8 @@ +package editor + +type clipboardFormat int + +const ( + clipboardFormatText clipboardFormat = iota + clipboardFormatImage +) diff --git a/internal/tui/components/chat/editor/clipboard_linux_386.go b/internal/tui/components/chat/editor/clipboard_linux_386.go new file mode 100644 index 0000000000000000000000000000000000000000..85f4111f7ea2ec50da457720c4cfba28f1e18ca7 --- /dev/null +++ b/internal/tui/components/chat/editor/clipboard_linux_386.go @@ -0,0 +1,7 @@ +//go:build linux && 386 + +package editor + +func readClipboard(clipboardFormat) ([]byte, error) { + return nil, errClipboardPlatformUnsupported +} diff --git a/internal/tui/components/chat/editor/clipboard_other.go b/internal/tui/components/chat/editor/clipboard_other.go new file mode 100644 index 0000000000000000000000000000000000000000..6c744385ef5d9ca58a3f6a3aca4ba55492bedd7c --- /dev/null +++ b/internal/tui/components/chat/editor/clipboard_other.go @@ -0,0 +1,15 @@ +//go:build !linux || !386 + +package editor + +import "github.com/aymanbagabas/go-nativeclipboard" + +func readClipboard(f clipboardFormat) ([]byte, error) { + switch f { + case clipboardFormatText: + return nativeclipboard.Text.Read() + case clipboardFormatImage: + return nativeclipboard.Image.Read() + } + return nil, errClipboardUnknownFormat +} diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index b5cadb8cde8a1ced8543d01eb7abd28d906f1597..8f7c43c76a965539db3c3d6de4f46377c8a10a5c 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -16,7 +16,6 @@ import ( "charm.land/bubbles/v2/textarea" tea "charm.land/bubbletea/v2" "charm.land/lipgloss/v2" - nativeclipboard "github.com/aymanbagabas/go-nativeclipboard" "github.com/charmbracelet/crush/internal/app" "github.com/charmbracelet/crush/internal/filetracker" "github.com/charmbracelet/crush/internal/fsext" @@ -35,6 +34,11 @@ import ( "github.com/charmbracelet/x/editor" ) +var ( + errClipboardPlatformUnsupported = fmt.Errorf("clipboard operations are not supported on this platform") + errClipboardUnknownFormat = fmt.Errorf("unknown clipboard format") +) + type Editor interface { util.Model layout.Sizeable @@ -341,12 +345,12 @@ func (m *editorCmp) Update(msg tea.Msg) (util.Model, tea.Cmd) { } // Handle image paste from clipboard if key.Matches(msg, m.keyMap.PasteImage) { - imageData, err := nativeclipboard.Image.Read() + imageData, err := readClipboard(clipboardFormatImage) if err != nil || len(imageData) == 0 { // If no image data found, try to get text data (could be file path) var textData []byte - textData, err = nativeclipboard.Text.Read() + textData, err = readClipboard(clipboardFormatText) if err != nil || len(textData) == 0 { // If clipboard is empty, show a warning return m, util.ReportWarn("No data found in clipboard. Note: Some terminals may not support reading image data from clipboard directly.")