summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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),
)