fix: editor: exclude native clipboard support from linux/386 builds (#1903)

Ayman Bagabas created

Change summary

internal/tui/components/chat/editor/clipboard.go           |  8 ++++
internal/tui/components/chat/editor/clipboard_linux_386.go |  7 +++
internal/tui/components/chat/editor/clipboard_other.go     | 15 ++++++++
internal/tui/components/chat/editor/editor.go              | 10 +++-
4 files changed, 37 insertions(+), 3 deletions(-)

Detailed changes

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
+}

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.")