Skip to content

Commit a332115

Browse files
committed
use tea.View.ProgressBar instead of raw escape codes
Replace manual ConEmu progress bar escape sequences with Bubble Tea v2's native ProgressBar support on the tea.View struct. This uses the proper OSC 9;4 sequences via the framework instead of writing raw bytes to stderr, and automatically handles cleanup when the view changes. The progress bar state (indeterminate while working) is now set declaratively in the View() function based on chatPage.IsWorking(), following the Elm Architecture pattern. Assisted-By: cagent
1 parent b7cbaf9 commit a332115

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

pkg/tui/page/chat/chat.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"fmt"
77
"log/slog"
8-
"os"
98
"path/filepath"
109
goruntime "runtime"
1110
"strings"
@@ -611,8 +610,6 @@ func (p *chatPage) cancelStream(showCancelMessage bool) tea.Cmd {
611610
p.msgCancel = nil
612611
p.streamCancelled = true
613612
p.setPendingResponse(false)
614-
p.stopProgressBar()
615-
616613
// Send StreamCancelledMsg to all components to handle cleanup
617614
return tea.Batch(
618615
core.CmdHandler(msgtypes.StreamCancelledMsg{ShowMessage: showCancelMessage}),
@@ -853,8 +850,6 @@ func (p *chatPage) processMessage(msg msgtypes.SendMsg) tea.Cmd {
853850
// Start working state immediately to show the user something is happening.
854851
// This provides visual feedback while the runtime loads tools and prepares the stream.
855852
spinnerCmd := p.setWorking(true)
856-
p.startProgressBar()
857-
858853
// Check if this is an agent command that needs resolution
859854
// If so, show a loading message with the command description
860855
var loadingCmd tea.Cmd
@@ -892,7 +887,6 @@ func (p *chatPage) CompactSession(additionalPrompt string) tea.Cmd {
892887
}
893888

894889
func (p *chatPage) Cleanup() {
895-
p.stopProgressBar()
896890
p.sidebar.Cleanup()
897891
}
898892

@@ -999,13 +993,3 @@ func (p *chatPage) BlurMessages() {
999993
func (p *chatPage) ScrollToBottom() tea.Cmd {
1000994
return p.messages.ScrollToBottom()
1001995
}
1002-
1003-
// startProgressBar sets a terminal progress-bar indicator (ConEmu/Windows Terminal).
1004-
// See: https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC
1005-
func (p *chatPage) startProgressBar() {
1006-
fmt.Fprint(os.Stderr, "\x1b]9;4;3;0\x1b\\")
1007-
}
1008-
1009-
func (p *chatPage) stopProgressBar() {
1010-
fmt.Fprint(os.Stderr, "\x1b]9;4;0;0\x1b\\")
1011-
}

pkg/tui/page/chat/runtime_events.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ func (p *chatPage) handleStreamStarted(msg *runtime.StreamStartedEvent) tea.Cmd
186186
p.streamCancelled = false
187187
spinnerCmd := p.setWorking(true)
188188
pendingCmd := p.setPendingResponse(true)
189-
p.startProgressBar()
190189
sidebarCmd := p.forwardToSidebar(msg)
191190
return tea.Batch(pendingCmd, spinnerCmd, sidebarCmd)
192191
}
@@ -222,7 +221,6 @@ func (p *chatPage) handleStreamStopped(msg *runtime.StreamStoppedEvent) tea.Cmd
222221
p.msgCancel = nil
223222
}
224223
p.streamCancelled = false
225-
p.stopProgressBar()
226224
sidebarCmd := p.forwardToSidebar(msg)
227225

228226
// Check if there are queued messages to process

pkg/tui/tui.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ func (m *appModel) View() tea.View {
18911891
windowTitle := m.windowTitle()
18921892

18931893
if m.err != nil {
1894-
return toFullscreenView(styles.ErrorStyle.Render(m.err.Error()), windowTitle)
1894+
return toFullscreenView(styles.ErrorStyle.Render(m.err.Error()), windowTitle, false)
18951895
}
18961896

18971897
if !m.ready {
@@ -1901,6 +1901,7 @@ func (m *appModel) View() tea.View {
19011901
Height(m.wHeight).
19021902
Render(styles.MutedStyle.Render("Loading…")),
19031903
windowTitle,
1904+
false,
19041905
)
19051906
}
19061907

@@ -1957,10 +1958,10 @@ func (m *appModel) View() tea.View {
19571958
}
19581959

19591960
compositor := lipgloss.NewCompositor(allLayers...)
1960-
return toFullscreenView(compositor.Render(), windowTitle)
1961+
return toFullscreenView(compositor.Render(), windowTitle, m.chatPage.IsWorking())
19611962
}
19621963

1963-
return toFullscreenView(baseView, windowTitle)
1964+
return toFullscreenView(baseView, windowTitle, m.chatPage.IsWorking())
19641965
}
19651966

19661967
// windowTitle returns the terminal window title.
@@ -2136,11 +2137,14 @@ func getEditorDisplayNameFromEnv(visual, editorEnv string) string {
21362137
return "$EDITOR"
21372138
}
21382139

2139-
func toFullscreenView(content, windowTitle string) tea.View {
2140+
func toFullscreenView(content, windowTitle string, working bool) tea.View {
21402141
view := tea.NewView(content)
21412142
view.AltScreen = true
21422143
view.MouseMode = tea.MouseModeCellMotion
21432144
view.BackgroundColor = styles.Background
21442145
view.WindowTitle = windowTitle
2146+
if working {
2147+
view.ProgressBar = tea.NewProgressBar(tea.ProgressBarIndeterminate, 0)
2148+
}
21452149
return view
21462150
}

0 commit comments

Comments
 (0)