mirror of
https://github.com/sst/opencode.git
synced 2025-07-08 00:25:00 +00:00
Merge a7036603db
into d87922c0eb
This commit is contained in:
commit
0e01903b29
3 changed files with 33 additions and 8 deletions
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -56,11 +57,6 @@ func main() {
|
||||||
option.WithBaseURL(url),
|
option.WithBaseURL(url),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
slog.Error("Failed to create client", "error", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create main context for the application
|
// Create main context for the application
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
@ -70,8 +66,25 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
var stdinContent string
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
|
||||||
program := tea.NewProgram(
|
program := tea.NewProgram(
|
||||||
tui.NewModel(app_),
|
tui.NewModel(app_, stdinContent),
|
||||||
tea.WithAltScreen(),
|
tea.WithAltScreen(),
|
||||||
tea.WithKeyboardEnhancements(),
|
tea.WithKeyboardEnhancements(),
|
||||||
tea.WithMouseCellMotion(),
|
tea.WithMouseCellMotion(),
|
||||||
|
|
|
@ -95,7 +95,7 @@ func (m statusComponent) View() string {
|
||||||
Render(m.app.Info.Path.Cwd)
|
Render(m.app.Info.Path.Cwd)
|
||||||
|
|
||||||
sessionInfo := ""
|
sessionInfo := ""
|
||||||
if m.app.Session.ID != "" {
|
if m.app.Session.ID != "" && m.app.Model != nil {
|
||||||
tokens := float64(0)
|
tokens := float64(0)
|
||||||
cost := float64(0)
|
cost := float64(0)
|
||||||
contextWindow := m.app.Model.Limit.Context
|
contextWindow := m.app.Model.Limit.Context
|
||||||
|
|
|
@ -66,6 +66,7 @@ type appModel struct {
|
||||||
fileViewerStart int
|
fileViewerStart int
|
||||||
fileViewerEnd int
|
fileViewerEnd int
|
||||||
fileViewerHit bool
|
fileViewerHit bool
|
||||||
|
stdinContent string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a appModel) Init() tea.Cmd {
|
func (a appModel) Init() tea.Cmd {
|
||||||
|
@ -89,6 +90,16 @@ func (a appModel) Init() tea.Cmd {
|
||||||
return dialog.ShowInitDialogMsg{Show: shouldShow}
|
return dialog.ShowInitDialogMsg{Show: shouldShow}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// If we have stdin content, send it as the first message
|
||||||
|
if a.stdinContent != "" {
|
||||||
|
cmds = append(cmds, func() tea.Msg {
|
||||||
|
return app.SendMsg{
|
||||||
|
Text: a.stdinContent,
|
||||||
|
Attachments: []opencode.FilePartParam{},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return tea.Batch(cmds...)
|
return tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -974,7 +985,7 @@ func (a appModel) executeCommand(command commands.Command) (tea.Model, tea.Cmd)
|
||||||
return a, tea.Batch(cmds...)
|
return a, tea.Batch(cmds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewModel(app *app.App) tea.Model {
|
func NewModel(app *app.App, stdinContent string) tea.Model {
|
||||||
commandProvider := completions.NewCommandCompletionProvider(app)
|
commandProvider := completions.NewCommandCompletionProvider(app)
|
||||||
fileProvider := completions.NewFileAndFolderContextGroup(app)
|
fileProvider := completions.NewFileAndFolderContextGroup(app)
|
||||||
|
|
||||||
|
@ -1004,6 +1015,7 @@ func NewModel(app *app.App) tea.Model {
|
||||||
interruptKeyState: InterruptKeyIdle,
|
interruptKeyState: InterruptKeyIdle,
|
||||||
fileViewer: fileviewer.New(app),
|
fileViewer: fileviewer.New(app),
|
||||||
messagesRight: app.State.MessagesRight,
|
messagesRight: app.State.MessagesRight,
|
||||||
|
stdinContent: stdinContent,
|
||||||
}
|
}
|
||||||
|
|
||||||
return model
|
return model
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue