on main help sign in
fix: editor: exclude native clipboard support from linux/386 builds (#1903)
3c64ee0Ayman Bagabas
internal/tui/components/chat/editor/clipboard.gonew file+8
@@ -0,0 +1,8 @@
1+package editor
2+
3+type clipboardFormat int
4+
5+const (
6+ clipboardFormatText clipboardFormat = iota
7+ clipboardFormatImage
8+)
internal/tui/components/chat/editor/clipboard_linux_386.gonew file+7
@@ -0,0 +1,7 @@
1+//go:build linux && 386
2+
3+package editor
4+
5+func readClipboard(clipboardFormat) ([]byte, error) {
6+ return nil, errClipboardPlatformUnsupported
7+}
internal/tui/components/chat/editor/clipboard_other.gonew file+15
@@ -0,0 +1,15 @@
1+//go:build !linux || !386
2+
3+package editor
4+
5+import "github.com/aymanbagabas/go-nativeclipboard"
6+
7+func readClipboard(f clipboardFormat) ([]byte, error) {
8+ switch f {
9+ case clipboardFormatText:
10+ return nativeclipboard.Text.Read()
11+ case clipboardFormatImage:
12+ return nativeclipboard.Image.Read()
13+ }
14+ return nil, errClipboardUnknownFormat
15+}
internal/tui/components/chat/editor/editor.go+7−3
@@ -16,7 +16,6 @@ import (
16 "charm.land/bubbles/v2/textarea"
16 "charm.land/bubbles/v2/textarea"
17 tea "charm.land/bubbletea/v2"
17 tea "charm.land/bubbletea/v2"
18 "charm.land/lipgloss/v2"
18 "charm.land/lipgloss/v2"
19− nativeclipboard "github.com/aymanbagabas/go-nativeclipboard"
20 "github.com/charmbracelet/crush/internal/app"
19 "github.com/charmbracelet/crush/internal/app"
21 "github.com/charmbracelet/crush/internal/filetracker"
20 "github.com/charmbracelet/crush/internal/filetracker"
22 "github.com/charmbracelet/crush/internal/fsext"
21 "github.com/charmbracelet/crush/internal/fsext"
@@ -35,6 +34,11 @@ import (
35 "github.com/charmbracelet/x/editor"
34 "github.com/charmbracelet/x/editor"
36)
35)
37
36
37+var (
38+ errClipboardPlatformUnsupported = fmt.Errorf("clipboard operations are not supported on this platform")
39+ errClipboardUnknownFormat = fmt.Errorf("unknown clipboard format")
40+)
41+
38type Editor interface {
42type Editor interface {
39 util.Model
43 util.Model
40 layout.Sizeable
44 layout.Sizeable
@@ -341,12 +345,12 @@ func (m *editorCmp) Update(msg tea.Msg) (util.Model, tea.Cmd) {
341 }
345 }
342 // Handle image paste from clipboard
346 // Handle image paste from clipboard
343 if key.Matches(msg, m.keyMap.PasteImage) {
347 if key.Matches(msg, m.keyMap.PasteImage) {
344− imageData, err := nativeclipboard.Image.Read()
348+ imageData, err := readClipboard(clipboardFormatImage)
345
349
346 if err != nil || len(imageData) == 0 {
350 if err != nil || len(imageData) == 0 {
347 // If no image data found, try to get text data (could be file path)
351 // If no image data found, try to get text data (could be file path)
348 var textData []byte
352 var textData []byte
349− textData, err = nativeclipboard.Text.Read()
353+ textData, err = readClipboard(clipboardFormatText)
350 if err != nil || len(textData) == 0 {
354 if err != nil || len(textData) == 0 {
351 // If clipboard is empty, show a warning
355 // If clipboard is empty, show a warning
352 return m, util.ReportWarn("No data found in clipboard. Note: Some terminals may not support reading image data from clipboard directly.")
356 return m, util.ReportWarn("No data found in clipboard. Note: Some terminals may not support reading image data from clipboard directly.")