Skip to content
Merged
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
20 changes: 20 additions & 0 deletions pkg/tui/page/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package chat

import (
"context"
"fmt"
"os"

"github.com/atotto/clipboard"
"github.com/charmbracelet/bubbles/v2/help"
Expand Down Expand Up @@ -36,6 +38,7 @@ type Page interface {
layout.Help
CompactSession() tea.Cmd
CopySessionToClipboard() tea.Cmd
Cleanup()
}

// chatPage implements Page
Expand Down Expand Up @@ -153,6 +156,8 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
p.msgCancel()
p.msgCancel = nil
}
// Stop progress bar if active
p.stopProgressBar()
return p, nil
}

Expand Down Expand Up @@ -193,6 +198,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case *runtime.StreamStartedEvent:
spinnerCmd := p.setWorking(true)
cmd := p.messages.AddAssistantMessage()
p.startProgressBar()
return p, tea.Batch(cmd, p.messages.ScrollToBottom(), spinnerCmd)
case *runtime.AgentChoiceEvent:
cmd := p.messages.AppendToLastMessage(msg.AgentName, types.MessageTypeAssistant, msg.Content)
Expand All @@ -216,6 +222,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if p.msgCancel != nil {
p.msgCancel = nil
}
p.stopProgressBar()
return p, tea.Batch(cmd, p.messages.ScrollToBottom(), spinnerCmd)
case *runtime.PartialToolCallEvent:
// When we first receive a tool call, show it immediately in pending state
Expand Down Expand Up @@ -455,3 +462,16 @@ func (p *chatPage) CompactSession() tea.Cmd {

return p.messages.ScrollToBottom()
}

func (p *chatPage) Cleanup() {
p.stopProgressBar()
}

// See: https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC
func (p *chatPage) startProgressBar() {
fmt.Fprint(os.Stderr, "\x1b]9;4;3;0\x1b\\")
}

func (p *chatPage) stopProgressBar() {
fmt.Fprint(os.Stderr, "\x1b]9;4;0;0\x1b\\")
}
1 change: 1 addition & 0 deletions pkg/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {

switch {
case key.Matches(msg, a.keyMap.Quit):
a.chatPage.Cleanup()
return tea.Quit
case key.Matches(msg, a.keyMap.CommandPalette):
// Open command palette
Expand Down
Loading