Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func maybeWriteMemProfile() {
func handleError(err error) {
maybeWriteMemProfile()
// exhaust stdin
if !isInputTTY() {
if !isInputTTY() && shouldReadInput() {
_, _ = io.ReadAll(os.Stdin)
}

Expand Down
2 changes: 1 addition & 1 deletion mods.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func (m *Mods) findReadID(in string) (*Conversation, error) {
}

func (m *Mods) readStdinCmd() tea.Msg {
if !isInputTTY() {
if !isInputTTY() && shouldReadInput() {
reader := bufio.NewReader(os.Stdin)
stdinBytes, err := io.ReadAll(reader)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions term.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ var isInputTTY = OnceValue(func() bool {
return isatty.IsTerminal(os.Stdin.Fd())
})

var shouldReadInput = OnceValue(func() bool {
stat, _ := os.Stdin.Stat()
return stat.Size() > 0
})

var isOutputTTY = OnceValue(func() bool {
return isatty.IsTerminal(os.Stdout.Fd())
})
Expand Down
Loading