summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorAiden Cline <[email protected]>2025-07-22 17:19:20 -0500
committerGitHub <[email protected]>2025-07-22 17:19:20 -0500
commit38ae7d60aac11661330ad60056de08c30d8e153c (patch)
treefbf41321d716e34c3b6385fde29478b40cff2b85 /packages
parent2d1f9fc321bf4b5e49ddf9c12b6b20889cbe2dd0 (diff)
downloadopencode-38ae7d60aac11661330ad60056de08c30d8e153c.tar.gz
opencode-38ae7d60aac11661330ad60056de08c30d8e153c.zip
feat(tui): support pipe into tui (#1230)
Diffstat (limited to 'packages')
-rw-r--r--packages/tui/cmd/opencode/main.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/packages/tui/cmd/opencode/main.go b/packages/tui/cmd/opencode/main.go
index a882d9daf..54dbd15a5 100644
--- a/packages/tui/cmd/opencode/main.go
+++ b/packages/tui/cmd/opencode/main.go
@@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
+ "io"
"log/slog"
"os"
"os/signal"
@@ -51,6 +52,30 @@ func main() {
os.Exit(1)
}
+ stat, err := os.Stdin.Stat()
+ if err != nil {
+ slog.Error("Failed to stat stdin", "error", err)
+ os.Exit(1)
+ }
+
+ // Check if there's data piped to stdin
+ if (stat.Mode() & os.ModeCharDevice) == 0 {
+ stdin, err := io.ReadAll(os.Stdin)
+ if err != nil {
+ slog.Error("Failed to read stdin", "error", err)
+ os.Exit(1)
+ }
+ stdinContent := strings.TrimSpace(string(stdin))
+ if stdinContent != "" {
+ if prompt == nil || *prompt == "" {
+ prompt = &stdinContent
+ } else {
+ combined := *prompt + "\n" + stdinContent
+ prompt = &combined
+ }
+ }
+ }
+
httpClient := opencode.NewClient(
option.WithBaseURL(url),
)