fix: build linux/386 (#2153)

Carlos Alexandro Becker created

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

Change summary

internal/ui/model/clipboard.go           | 15 +++++++++++++++
internal/ui/model/clipboard_linux_386.go |  7 +++++++
internal/ui/model/clipboard_other.go     | 15 +++++++++++++++
internal/ui/model/ui.go                  |  5 ++---
4 files changed, 39 insertions(+), 3 deletions(-)

Detailed changes

internal/ui/model/clipboard.go 🔗

@@ -0,0 +1,15 @@
+package model
+
+import "errors"
+
+type clipboardFormat int
+
+const (
+	clipboardFormatText clipboardFormat = iota
+	clipboardFormatImage
+)
+
+var (
+	errClipboardPlatformUnsupported = errors.New("clipboard operations are not supported on this platform")
+	errClipboardUnknownFormat       = errors.New("unknown clipboard format")
+)

internal/ui/model/clipboard_other.go 🔗

@@ -0,0 +1,15 @@
+//go:build !linux || !386
+
+package model
+
+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/ui/model/ui.go 🔗

@@ -24,7 +24,6 @@ import (
 	tea "charm.land/bubbletea/v2"
 	"charm.land/catwalk/pkg/catwalk"
 	"charm.land/lipgloss/v2"
-	nativeclipboard "github.com/aymanbagabas/go-nativeclipboard"
 	"github.com/charmbracelet/crush/internal/agent/tools/mcp"
 	"github.com/charmbracelet/crush/internal/app"
 	"github.com/charmbracelet/crush/internal/commands"
@@ -3086,7 +3085,7 @@ func (m *UI) handleFilePathPaste(path string) tea.Cmd {
 // creates an attachment. If no image data is found, it falls back to
 // interpreting clipboard text as a file path.
 func (m *UI) pasteImageFromClipboard() tea.Msg {
-	imageData, err := nativeclipboard.Image.Read()
+	imageData, err := readClipboard(clipboardFormatImage)
 	if int64(len(imageData)) > common.MaxAttachmentSize {
 		return util.InfoMsg{
 			Type: util.InfoTypeError,
@@ -3103,7 +3102,7 @@ func (m *UI) pasteImageFromClipboard() tea.Msg {
 		}
 	}
 
-	textData, textErr := nativeclipboard.Text.Read()
+	textData, textErr := readClipboard(clipboardFormatText)
 	if textErr != nil || len(textData) == 0 {
 		return util.NewInfoMsg("Clipboard is empty or does not contain an image")
 	}