Open source AI coding agent. Designed for large projects and real world tasks.
Go aiai-agentsai-developer-toolsai-toolsclicommand-linedeveloper-toolsgitgolanggpt-4llmopenaipolyglot-programmingterminalterminal-basedterminal-ui
stream tui rendering fixes
Dane Schneider4a2d36ec78ef
diff --git a/app/cli/stream_tui/update.go b/app/cli/stream_tui/update.goindex aa4bd486..7209a4b9 100644--- a/app/cli/stream_tui/update.go+++ b/app/cli/stream_tui/update.go@@ -63,6 +63,7 @@ func (m streamUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {log.Println("stop plan api error:", apiErr)m.apiErr = apiErr}+ m.stopped = truereturn m, tea.Quitcase bubbleKey.Matches(msg, m.keymap.scrollDown) && !m.promptingMissingFile:@@ -140,6 +141,8 @@ func (m *streamUIModel) updateReplyDisplay() {}func (m *streamUIModel) updateViewportDimensions() {+ // log.Println("updateViewportDimensions")+w, h := m.getViewportDimensions()m.mainViewport.Width = wm.mainViewport.Height = h@@ -153,9 +156,12 @@ func (m *streamUIModel) getViewportDimensions() (int, int) {var buildHeight intif m.building {- buildHeight = lipgloss.Height(m.renderBuild())+ buildHeight = len(m.getRows(false))}+ // log.Println("building:", m.building)+ // log.Println("buildHeight:", buildHeight)+var processingHeight intif m.starting || m.processing {processingHeight = lipgloss.Height(m.renderProcessing())diff --git a/app/cli/stream_tui/view.go b/app/cli/stream_tui/view.goindex 6e68d258..977f9ac9 100644--- a/app/cli/stream_tui/view.go+++ b/app/cli/stream_tui/view.go@@ -15,11 +15,12 @@ var borderColor = lipgloss.Color("#444")var helpTextColor = lipgloss.Color("#ddd")func (m streamUIModel) View() string {+if m.promptingMissingFile {return m.renderMissingFilePrompt()}- var views []string+ views := []string{}if !m.buildOnly {views = append(views, m.renderMainView())}@@ -80,30 +81,43 @@ func (m streamUIModel) doRenderBuild(outputStatic bool) string {style = lipgloss.NewStyle().Width(m.width).BorderStyle(lipgloss.NormalBorder()).BorderTop(true).BorderForeground(lipgloss.Color(borderColor))}+ // log.Println("filePaths:", filePaths)+ // log.Println("len(resRows):", len(resRows))++ resRows := m.getRows(outputStatic)++ res := style.Render(strings.Join(resRows, "\n"))++ // log.Println("\n\n", res, "\n\n")++ return res+}++func (m streamUIModel) getRows(static bool) []string {+ filePaths := make([]string, 0, len(m.tokensByPath))+ for filePath := range m.tokensByPath {+ filePaths = append(filePaths, filePath)+ }++ sort.Strings(filePaths)+lbl := "Building plan "bgColor := color.BgGreenbuilt := false- if outputStatic {- // log.Printf("m.finished: %v, len(m.finishedByPath): %d, len(m.tokensByPath): %d", m.finished, len(m.finishedByPath), len(m.tokensByPath))+ if static {+ // log.Printf("m.finished: %v, m.stopped: %v, len(m.finishedByPath): %d, len(m.tokensByPath): %d", m.finished, len(m.finishedByPath), len(m.tokensByPath))- if m.finished || len(m.finishedByPath) == len(m.tokensByPath) {- lbl = "Built plan "- built = true- } else if m.stopped || m.err != nil || m.apiErr != nil {+ if m.stopped || m.err != nil || m.apiErr != nil {lbl = "Build incomplete "bgColor = color.BgRed+ } else {+ lbl = "Built plan "+ built = true}}head := color.New(bgColor, color.FgHiWhite, color.Bold).Sprint(" 🏗 ") + color.New(bgColor, color.FgHiWhite).Sprint(lbl)- filePaths := make([]string, 0, len(m.tokensByPath))- for filePath := range m.tokensByPath {- filePaths = append(filePaths, filePath)- }-- sort.Strings(filePaths)-var rows [][]stringrows = append(rows, []string{})lineWidth := 0@@ -123,7 +137,7 @@ func (m streamUIModel) doRenderBuild(outputStatic bool) string {maybeBlockWidth := lipgloss.Width(block)if maybeBlockWidth > m.width {- maxWidth := m.width - lipgloss.Width("⋯")+ maxWidth := m.width - (lipgloss.Width("⋯"))runes := []rune(block)firstHalf := string(runes[:maxWidth/2])secondHalf := string(runes[len(runes)-maxWidth/2:])@@ -159,10 +173,10 @@ func (m streamUIModel) doRenderBuild(outputStatic bool) string {resRows[0] = headfor i, row := range rows {- resRows[i+1] = strings.Join(row, "")+ resRows[i+1] = lipgloss.JoinHorizontal(lipgloss.Left, row...)}- return style.Render(strings.Join(resRows, "\n"))+ return resRows}func (m streamUIModel) renderMissingFilePrompt() string {