Fix: streaming to tui
This commit is contained in:
18
bot.go
18
bot.go
@@ -48,7 +48,6 @@ var (
|
|||||||
chunkParser ChunkParser
|
chunkParser ChunkParser
|
||||||
lastToolCall *models.FuncCall
|
lastToolCall *models.FuncCall
|
||||||
lastRespStats *models.ResponseStats
|
lastRespStats *models.ResponseStats
|
||||||
|
|
||||||
outputHandler OutputHandler
|
outputHandler OutputHandler
|
||||||
cliPrevOutput string
|
cliPrevOutput string
|
||||||
cliRespDone chan bool
|
cliRespDone chan bool
|
||||||
@@ -65,30 +64,15 @@ type TUIOutputHandler struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *TUIOutputHandler) Write(p string) {
|
func (h *TUIOutputHandler) Write(p string) {
|
||||||
if h.tv != nil {
|
|
||||||
fmt.Fprint(h.tv, p)
|
fmt.Fprint(h.tv, p)
|
||||||
}
|
|
||||||
if cfg != nil && cfg.CLIMode {
|
|
||||||
fmt.Print(p)
|
|
||||||
cliPrevOutput = p
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *TUIOutputHandler) Writef(format string, args ...interface{}) {
|
func (h *TUIOutputHandler) Writef(format string, args ...interface{}) {
|
||||||
s := fmt.Sprintf(format, args...)
|
fmt.Fprintf(h.tv, format, args...)
|
||||||
if h.tv != nil {
|
|
||||||
fmt.Fprint(h.tv, s)
|
|
||||||
}
|
|
||||||
if cfg != nil && cfg.CLIMode {
|
|
||||||
fmt.Print(s)
|
|
||||||
cliPrevOutput = s
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *TUIOutputHandler) ScrollToEnd() {
|
func (h *TUIOutputHandler) ScrollToEnd() {
|
||||||
if h.tv != nil {
|
|
||||||
h.tv.ScrollToEnd()
|
h.tv.ScrollToEnd()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CLIOutputHandler struct{}
|
type CLIOutputHandler struct{}
|
||||||
|
|||||||
2
tui.go
2
tui.go
@@ -230,7 +230,6 @@ func initTUI() {
|
|||||||
tview.Styles = colorschemes["default"]
|
tview.Styles = colorschemes["default"]
|
||||||
app = tview.NewApplication()
|
app = tview.NewApplication()
|
||||||
pages = tview.NewPages()
|
pages = tview.NewPages()
|
||||||
outputHandler = &TUIOutputHandler{tv: textView}
|
|
||||||
shellInput = tview.NewInputField().
|
shellInput = tview.NewInputField().
|
||||||
SetLabel(fmt.Sprintf("[%s]$ ", cfg.FilePickerDir)). // dynamic prompt
|
SetLabel(fmt.Sprintf("[%s]$ ", cfg.FilePickerDir)). // dynamic prompt
|
||||||
SetFieldWidth(0).
|
SetFieldWidth(0).
|
||||||
@@ -349,6 +348,7 @@ func initTUI() {
|
|||||||
// calling it explicitly makes text streaming to look more smooth
|
// calling it explicitly makes text streaming to look more smooth
|
||||||
app.Draw()
|
app.Draw()
|
||||||
})
|
})
|
||||||
|
outputHandler = &TUIOutputHandler{tv: textView}
|
||||||
notificationWidget = tview.NewTextView().
|
notificationWidget = tview.NewTextView().
|
||||||
SetTextAlign(tview.AlignCenter).
|
SetTextAlign(tview.AlignCenter).
|
||||||
SetDynamicColors(true).
|
SetDynamicColors(true).
|
||||||
|
|||||||
Reference in New Issue
Block a user