summaryrefslogtreecommitdiffhomepage
path: root/packages/tui
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-07-08 13:02:13 -0500
committeradamdottv <[email protected]>2025-07-08 13:02:13 -0500
commitf31cbf2744cd14e5350d054e78d047a36b218f6c (patch)
treef9620381c804255d71d78893a0d736c2f74a5e60 /packages/tui
parent8322f18e0339fa015346c6700b4e71d2b193b402 (diff)
downloadopencode-f31cbf2744cd14e5350d054e78d047a36b218f6c.tar.gz
opencode-f31cbf2744cd14e5350d054e78d047a36b218f6c.zip
fix: image reading
Diffstat (limited to 'packages/tui')
-rw-r--r--packages/tui/internal/components/chat/editor.go16
-rw-r--r--packages/tui/sdk/packages/ssestream/ssestream.go2
2 files changed, 13 insertions, 5 deletions
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go
index cc31fbef2..82b3bf71e 100644
--- a/packages/tui/internal/components/chat/editor.go
+++ b/packages/tui/internal/components/chat/editor.go
@@ -104,13 +104,19 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
base64EncodedFile := base64.StdEncoding.EncodeToString(fileBytes)
url := fmt.Sprintf("data:%s;base64,%s", mediaType, base64EncodedFile)
+ attachmentCount := len(m.textarea.GetAttachments())
+ attachmentIndex := attachmentCount + 1
+ label := "File"
+ if strings.HasPrefix(mediaType, "image/") {
+ label = "Image"
+ }
attachment := &textarea.Attachment{
ID: uuid.NewString(),
- Display: fmt.Sprintf("<%s>", filePath),
+ MediaType: mediaType,
+ Display: fmt.Sprintf("[%s #%d]", label, attachmentIndex),
URL: url,
Filename: filePath,
- MediaType: mediaType,
}
m.textarea.InsertAttachment(attachment)
m.textarea.InsertString(" ")
@@ -325,12 +331,14 @@ func (m *editorComponent) Clear() (tea.Model, tea.Cmd) {
func (m *editorComponent) Paste() (tea.Model, tea.Cmd) {
imageBytes := clipboard.Read(clipboard.FmtImage)
if imageBytes != nil {
+ attachmentCount := len(m.textarea.GetAttachments())
+ attachmentIndex := attachmentCount + 1
base64EncodedFile := base64.StdEncoding.EncodeToString(imageBytes)
attachment := &textarea.Attachment{
ID: uuid.NewString(),
- Display: "<clipboard-image>",
- Filename: "clipboard-image",
MediaType: "image/png",
+ Display: fmt.Sprintf("[Image #%d]", attachmentIndex),
+ Filename: fmt.Sprintf("image-%d.png", attachmentIndex),
URL: fmt.Sprintf("data:image/png;base64,%s", base64EncodedFile),
}
m.textarea.InsertAttachment(attachment)
diff --git a/packages/tui/sdk/packages/ssestream/ssestream.go b/packages/tui/sdk/packages/ssestream/ssestream.go
index 81adbd69b..87ab56f2c 100644
--- a/packages/tui/sdk/packages/ssestream/ssestream.go
+++ b/packages/tui/sdk/packages/ssestream/ssestream.go
@@ -29,7 +29,7 @@ func NewDecoder(res *http.Response) Decoder {
decoder = t(res.Body)
} else {
scn := bufio.NewScanner(res.Body)
- scn.Buffer(nil, bufio.MaxScanTokenSize<<4)
+ scn.Buffer(nil, (bufio.MaxScanTokenSize<<4)*10)
decoder = &eventStreamDecoder{rc: res.Body, scn: scn}
}
return decoder