Files
example-eino/adk/internal/terminal/input.go
T
zhaoyupeng.elqbandTRAE CLI 81deca8c8e feat: initialize Eino examples and ADK applications
Include chat, weather, image, travel, streaming ASR and text examples,
shared model initialization, documentation, and existing tests.

Co-authored-by: TRAE CLI <traecli@bytedance.com>
2026-11-19 11:08:03 +08:00

52 lines
945 B
Go

package terminal
import (
"bufio"
"context"
"io"
)
type inputLine struct {
text string
err error
}
// terminalInput 统一读取标准输入,聊天、录音结束和生图确认顺序消费。
type terminalInput struct {
lines <-chan inputLine
}
func newInput(ctx context.Context, reader io.Reader) *terminalInput {
lines := make(chan inputLine)
go func() {
defer close(lines)
scanner := bufio.NewScanner(reader)
for scanner.Scan() {
select {
case lines <- inputLine{text: scanner.Text()}:
case <-ctx.Done():
return
}
}
if err := scanner.Err(); err != nil {
select {
case lines <- inputLine{err: err}:
case <-ctx.Done():
}
}
}()
return &terminalInput{lines: lines}
}
func (i *terminalInput) next(ctx context.Context) (string, error) {
select {
case <-ctx.Done():
return "", ctx.Err()
case line, ok := <-i.lines:
if !ok {
return "", io.EOF
}
return line.text, line.err
}
}