Fix: streaming to tui

This commit is contained in:
Grail Finder
2026-03-17 10:51:53 +03:00
parent 326a1a4d09
commit 69a69547ff
2 changed files with 7 additions and 23 deletions

18
bot.go
View File

@@ -48,7 +48,6 @@ var (
chunkParser ChunkParser
lastToolCall *models.FuncCall
lastRespStats *models.ResponseStats
outputHandler OutputHandler
cliPrevOutput string
cliRespDone chan bool
@@ -65,31 +64,16 @@ type TUIOutputHandler struct {
}
func (h *TUIOutputHandler) Write(p string) {
if h.tv != nil {
fmt.Fprint(h.tv, p)
}
if cfg != nil && cfg.CLIMode {
fmt.Print(p)
cliPrevOutput = p
}
}
func (h *TUIOutputHandler) Writef(format string, args ...interface{}) {
s := fmt.Sprintf(format, args...)
if h.tv != nil {
fmt.Fprint(h.tv, s)
}
if cfg != nil && cfg.CLIMode {
fmt.Print(s)
cliPrevOutput = s
}
fmt.Fprintf(h.tv, format, args...)
}
func (h *TUIOutputHandler) ScrollToEnd() {
if h.tv != nil {
h.tv.ScrollToEnd()
}
}
type CLIOutputHandler struct{}

2
tui.go
View File

@@ -230,7 +230,6 @@ func initTUI() {
tview.Styles = colorschemes["default"]
app = tview.NewApplication()
pages = tview.NewPages()
outputHandler = &TUIOutputHandler{tv: textView}
shellInput = tview.NewInputField().
SetLabel(fmt.Sprintf("[%s]$ ", cfg.FilePickerDir)). // dynamic prompt
SetFieldWidth(0).
@@ -349,6 +348,7 @@ func initTUI() {
// calling it explicitly makes text streaming to look more smooth
app.Draw()
})
outputHandler = &TUIOutputHandler{tv: textView}
notificationWidget = tview.NewTextView().
SetTextAlign(tview.AlignCenter).
SetDynamicColors(true).