Skip to content

Open source AI coding agent. Designed for large projects and real world tasks.

changes tui mostly working

Dane Schneidereb0afe879769
diff --git a/cli/changes_tui/actions.go b/cli/changes_tui/actions.go
index 3cd74941..3e432677 100644
--- a/cli/changes_tui/actions.go
+++ b/cli/changes_tui/actions.go
@@ -5,7 +5,7 @@ import (
"strings"
"github.com/atotto/clipboard"
- "github.com/charmbracelet/bubbles/viewport"
+ "github.com/fatih/color"
"github.com/muesli/reflow/wrap"
"github.com/plandex/plandex/shared"
)
@@ -74,7 +74,13 @@ func (m *changesUIModel) down() {
currentReplacements = m.selectionInfo.currentReplacements
}
- if m.selectedReplacementIndex < len(currentReplacements) {
+ // allow for selection of 'full file' option at bottom of replacement list in sidebar
+ max := len(currentReplacements) - 1
+ if m.selectionInfo.currentPlanBeforeReplacement.NumPendingForPath(m.selectionInfo.currentPath) > 0 {
+ max++
+ }
+
+ if m.selectedReplacementIndex < max {
m.selectedReplacementIndex++
}
m.setSelectionInfo()
@@ -140,46 +146,54 @@ func (m *changesUIModel) windowResized(w, h int) {
}
func (m *changesUIModel) updateMainView(scrollReplacement bool) {
- updatedFile := m.selectionInfo.currentPlanBeforeReplacement.CurrentPlanFiles.Files[m.selectionInfo.currentPath]
-
- oldRes := m.getReplacementOldDisplay()
-
- m.changeOldViewport.SetContent(oldRes.oldDisplay)
-
- newContent, newContentDisplay := m.getReplacementNewDisplay(oldRes.prependContent, oldRes.appendContent)
- m.changeNewViewport.SetContent(newContentDisplay)
-
- m.fileViewport.SetContent(wrap.String(updatedFile, m.fileViewport.Width-2))
-
- m.updateViewportSizes()
+ if m.selectedFullFile() {
+ updatedFile := m.currentPlan.CurrentPlanFiles.Files[m.selectionInfo.currentPath]
+
+ wrapWidth := m.fileViewport.Width - 2
+
+ replacements := m.selectionInfo.currentReplacements
+ fileSegments := []string{}
+ replacementSegments := map[int]bool{}
+ lastReplacementIdx := 0
+ for _, rep := range replacements {
+ idx := strings.Index(updatedFile, rep.New)
+ if idx == -1 || idx < lastReplacementIdx {
+ continue
+ }
+
+ fileSegments = append(fileSegments, updatedFile[lastReplacementIdx:idx])
+ fileSegments = append(fileSegments, rep.New)
+ replacementSegments[len(fileSegments)-1] = true
+ lastReplacementIdx = idx + len(rep.New)
+ }
+ fileSegments = append(fileSegments, updatedFile[lastReplacementIdx:])
+
+ for i, segment := range fileSegments {
+ wrapped := wrap.String(segment, wrapWidth)
+ isReplacement := replacementSegments[i]
+ if isReplacement {
+ lines := strings.Split(wrapped, "\n")
+ for j, line := range lines {
+ lines[j] = color.New(color.FgHiGreen).Sprint(line)
+ }
+ wrapped = strings.Join(lines, "\n")
+ }
+ fileSegments[i] = wrapped
+ }
- if scrollReplacement {
- m.scrollReplacementIntoView(oldRes.old, newContent, oldRes.numLinesPrepended)
- }
-}
+ m.fileViewport.SetContent(strings.Join(fileSegments, ""))
+ m.updateViewportSizes()
-func (m *changesUIModel) scrollReplacementIntoView(oldContent, newContent string, numLinesPrepended int) {
- if numLinesPrepended <= 3 {
- return
- }
+ } else {
+ oldRes := m.getReplacementOldDisplay()
+ m.changeOldViewport.SetContent(oldRes.oldDisplay)
+ newContent, newContentDisplay := m.getReplacementNewDisplay(oldRes.prependContent, oldRes.appendContent)
+ m.changeNewViewport.SetContent(newContentDisplay)
- scrollView := func(content string, view *viewport.Model) {
- visibleLines := view.VisibleLineCount()
- contentLines := len(strings.Split(content, "\n"))
+ m.updateViewportSizes()
- if contentLines >= (visibleLines - 3) {
- view.LineDown(numLinesPrepended - 3)
- } else {
- diffAround := visibleLines - contentLines
- toScroll := numLinesPrepended - diffAround/2
- view.LineDown(toScroll)
+ if scrollReplacement {
+ m.scrollReplacementIntoView(oldRes.old, newContent, oldRes.numLinesPrepended)
}
}
-
- if m.oldScrollable() {
- scrollView(oldContent, &m.changeOldViewport)
- }
- if m.newScrollable() {
- scrollView(newContent, &m.changeNewViewport)
- }
}
diff --git a/cli/changes_tui/main_viewport.go b/cli/changes_tui/main_viewport.go
index a5944bee..9c9d5e34 100644
--- a/cli/changes_tui/main_viewport.go
+++ b/cli/changes_tui/main_viewport.go
@@ -1,44 +1,63 @@
package changes_tui
import (
+ "fmt"
+
"github.com/charmbracelet/lipgloss"
)
func (m changesUIModel) renderMainView() string {
- oldView := m.changeOldViewport.View()
- newView := m.changeNewViewport.View()
+ mainViewHeader := m.renderMainViewHeader()
- oldViews := []string{oldView}
- newViews := []string{newView}
+ if m.selectedFullFile() {
+ fileView := m.fileViewport.View()
- if m.oldScrollable() && m.selectedViewport == 0 {
- oldViews = append(oldViews, m.renderScrollFooter())
- } else if m.newScrollable() {
- newViews = append(newViews, m.renderScrollFooter())
- }
+ fileViews := []string{fileView}
- oldContainer := lipgloss.JoinVertical(lipgloss.Left, oldViews...)
- newContainer := lipgloss.JoinVertical(lipgloss.Left, newViews...)
+ if m.fileScrollable() {
+ fileViews = append(fileViews, m.renderScrollFooter())
+ }
- oldContainerStyle := lipgloss.NewStyle().Width(m.changeOldViewport.Width)
- oldContainer = oldContainerStyle.Render(oldContainer)
+ fileContainer := lipgloss.JoinVertical(lipgloss.Left, fileViews...)
+
+ fileContainerStyle := lipgloss.NewStyle().Width(m.fileViewport.Width)
+ fileContainer = fileContainerStyle.Render(fileContainer)
+
+ return lipgloss.JoinVertical(lipgloss.Left, mainViewHeader, fileContainer)
+ } else {
+ oldView := m.changeOldViewport.View()
+ newView := m.changeNewViewport.View()
+
+ oldViews := []string{oldView}
+ newViews := []string{newView}
+
+ if m.oldScrollable() && m.selectedViewport == 0 {
+ oldViews = append(oldViews, m.renderScrollFooter())
+ } else if m.newScrollable() {
+ newViews = append(newViews, m.renderScrollFooter())
+ }
+
+ oldContainer := lipgloss.JoinVertical(lipgloss.Left, oldViews...)
+ newContainer := lipgloss.JoinVertical(lipgloss.Left, newViews...)
+
+ oldContainerStyle := lipgloss.NewStyle().Width(m.changeOldViewport.Width)
+ oldContainer = oldContainerStyle.Render(oldContainer)
+
+ newContainerStyle := lipgloss.NewStyle().
+ BorderStyle(lipgloss.NormalBorder()).
+ BorderLeft(true).
+ BorderForeground(lipgloss.Color(borderColor)).
+ Width(m.changeNewViewport.Width)
+
+ newContainer = newContainerStyle.Render(newContainer)
+
+ return lipgloss.JoinVertical(lipgloss.Left,
+ mainViewHeader,
+ lipgloss.JoinHorizontal(lipgloss.Top, oldContainer, newContainer),
+ m.renderMainViewFooter(),
+ )
+ }
- newContainerStyle := lipgloss.NewStyle().
- BorderStyle(lipgloss.NormalBorder()).
- BorderLeft(true).
- BorderForeground(lipgloss.Color(borderColor)).
- Width(m.changeNewViewport.Width)
-
- newContainer = newContainerStyle.Render(newContainer)
-
- return lipgloss.JoinVertical(lipgloss.Left,
- m.renderMainViewHeader(),
- lipgloss.JoinHorizontal(lipgloss.Top,
- oldContainer,
- newContainer,
- ),
- m.renderMainViewFooter(),
- )
}
func (m changesUIModel) renderMainViewHeader() string {
@@ -53,14 +72,29 @@ func (m changesUIModel) renderMainViewHeader() string {
BorderBottom(true).
BorderForeground(borderColor)
- header := " πŸ“ " + m.selectionInfo.currentRep.Summary
+ var header string
+ if m.selectedFullFile() {
+ numChanges := m.selectionInfo.currentPlanBeforeReplacement.NumPendingForPath(m.selectionInfo.currentPath)
+ suffix := "s"
+ if numChanges == 1 {
+ suffix = ""
+ }
+ header = fmt.Sprintf(" βœ… "+"Final state of file including %d change%s", numChanges, suffix)
+ } else {
+ header = " πŸ‘‰ " + m.selectionInfo.currentRep.Summary
+ }
+
return style.Render(header)
}
func (m changesUIModel) renderMainViewFooter() string {
+ if m.selectedFullFile() {
+ return ""
+ }
+
sidebarWidth := lipgloss.Width(m.renderSidebar())
style := lipgloss.NewStyle().Width(m.width - sidebarWidth).Inherit(topBorderStyle).Foreground(lipgloss.Color(helpTextColor))
- footer := ` (d)iscard selected change β€’ (c)opy to clipboard`
+ footer := ` (d)rop selected change β€’ (c)opy to clipboard`
return style.Render(footer)
}
@@ -75,10 +109,17 @@ func (m changesUIModel) renderScrollFooter() string {
width = width / 2
}
- footer := ` (j/k) scroll`
-
- if m.oldScrollable() && m.newScrollable() {
- footer += ` β€’ (tab) switch view`
+ var footer string
+
+ if m.selectedFullFile() {
+ footer = `(j/k) scroll down/up β€’ (J/K) page down/up`
+ } else {
+ footer = ` (j/k) scroll`
+ if m.oldScrollable() && m.newScrollable() {
+ footer += ` β€’ (tab) switch view`
+ } else {
+ footer += ` down/up`
+ }
}
style := lipgloss.NewStyle().Width(width).Inherit(topBorderStyle).Foreground(lipgloss.Color(helpTextColor))
diff --git a/cli/changes_tui/model.go b/cli/changes_tui/model.go
index 2eb89d27..b6d85221 100644
--- a/cli/changes_tui/model.go
+++ b/cli/changes_tui/model.go
@@ -84,13 +84,13 @@ func initialModel() *changesUIModel {
),
pageDown: bubbleKey.NewBinding(
- bubbleKey.WithKeys("enter", "pageDown"),
- bubbleKey.WithHelp("enter", "page down"),
+ bubbleKey.WithKeys("J", "pageDown"),
+ bubbleKey.WithHelp("J", "page down"),
),
pageUp: bubbleKey.NewBinding(
- bubbleKey.WithKeys("shift+enter", "pageUp"),
- bubbleKey.WithHelp("shift+enter", "page up"),
+ bubbleKey.WithKeys("K", "pageUp"),
+ bubbleKey.WithHelp("K", "page up"),
),
switchView: bubbleKey.NewBinding(
@@ -100,7 +100,7 @@ func initialModel() *changesUIModel {
reject: bubbleKey.NewBinding(
bubbleKey.WithKeys("d"),
- bubbleKey.WithHelp("d", "discard change"),
+ bubbleKey.WithHelp("d", "drop change"),
),
copy: bubbleKey.NewBinding(
diff --git a/cli/changes_tui/path_tabs.go b/cli/changes_tui/path_tabs.go
index 755be47a..0aae64c8 100644
--- a/cli/changes_tui/path_tabs.go
+++ b/cli/changes_tui/path_tabs.go
@@ -51,6 +51,10 @@ func (m changesUIModel) renderPathTabs() string {
tabWidth := lipgloss.Width(tab)
+ if tabWidth > m.width {
+ return ""
+ }
+
if lineWidth+tabWidth > m.width {
lineWidth = 0
lineNum++
diff --git a/cli/changes_tui/replacement.go b/cli/changes_tui/replace.go
similarity index 91%
rename from cli/changes_tui/replacement.go
rename to cli/changes_tui/replace.go
index 90d0403e..d4be017a 100644
--- a/cli/changes_tui/replacement.go
+++ b/cli/changes_tui/replace.go
@@ -43,8 +43,12 @@ func (m changesUIModel) getReplacementOldDisplay() oldReplacementRes {
}
}
}
+ prependedToStart := strings.Index(originalFile, toPrepend) == 0
toPrepend = strings.TrimLeft(toPrepend, "\n")
+ if !prependedToStart {
+ toPrepend = "…\n" + toPrepend
+ }
toAppend := ""
numLinesAppended := 0
@@ -61,9 +65,14 @@ func (m changesUIModel) getReplacementOldDisplay() oldReplacementRes {
}
}
}
+ appendedToEnd := strings.Index(originalFile, toAppend) == len(originalFile)-len(toAppend)
toAppend = strings.TrimRight(toAppend, "\n")
+ if !appendedToEnd {
+ toAppend += "\n…"
+ }
+
wrapWidth := m.changeOldViewport.Width - 6
toPrepend = wrap.String(toPrepend, wrapWidth)
oldContent = wrap.String(oldContent, wrapWidth)
diff --git a/cli/changes_tui/sidebar.go b/cli/changes_tui/sidebar.go
index 423cc3b7..c0272325 100644
--- a/cli/changes_tui/sidebar.go
+++ b/cli/changes_tui/sidebar.go
@@ -21,6 +21,7 @@ func (m changesUIModel) renderSidebar() string {
for _, path := range paths {
results := m.currentPlan.PlanResByPath[path]
anyFailed := false
+ anyApplied := false
// Change entries
for i, result := range results {
@@ -29,20 +30,34 @@ func (m changesUIModel) renderSidebar() string {
selected := currentRep != nil && rep.Id == currentRep.Id
s := ""
- labelColor := color.FgHiGreen
+ fgColor := color.FgHiGreen
+ bgColor := color.BgGreen
if rep.Failed {
- labelColor = color.FgHiRed
+ fgColor = color.FgHiRed
+ bgColor = color.BgRed
anyFailed = true
+ } else if rep.RejectedAt != "" {
+ fgColor = color.FgWhite
+ bgColor = color.BgBlack
}
- if selected {
- s += color.New(color.Bold, labelColor).Sprintf(" > ") + color.New(color.Bold, labelColor).Sprintf("%d", flatIndex)
+ var icon string
+ if rep.RejectedAt != "" {
+ icon = "πŸ‘Ž"
+ } else if rep.Failed {
+ icon = "🚫"
} else {
- s += color.New(labelColor).Sprintf(" - %d", flatIndex)
+ icon = "πŸ“"
}
- if result.RejectedAt != "" {
- s += " 🚫"
+ if !rep.Failed && rep.RejectedAt == "" {
+ anyApplied = true
+ }
+
+ if selected {
+ s += color.New(color.Bold, bgColor, color.FgHiWhite).Sprintf(" > %s %d ", icon, flatIndex+1)
+ } else {
+ s += color.New(fgColor).Sprintf(" - %s %d ", icon, flatIndex+1)
}
s += "\n"
@@ -52,15 +67,21 @@ func (m changesUIModel) renderSidebar() string {
}
- labelColor := color.FgHiGreen
+ if !anyApplied {
+ continue
+ }
+
+ fgColor := color.FgHiGreen
+ bgColor := color.BgGreen
if anyFailed {
- labelColor = color.FgHiRed
+ fgColor = color.FgHiRed
+ bgColor = color.BgRed
}
if m.selectedFullFile() {
- sb.WriteString(color.New(color.Bold, labelColor).Sprint(" > πŸ“„ \n "))
+ sb.WriteString(color.New(color.Bold, bgColor, color.FgHiWhite).Sprint(" > πŸ”€ "))
} else {
- sb.WriteString(color.New(labelColor).Sprint(" - πŸ“„ \n"))
+ sb.WriteString(color.New(fgColor).Sprint(" - πŸ”€ "))
}
}
diff --git a/cli/changes_tui/view.go b/cli/changes_tui/view.go
index 54d008f1..692d8a5c 100644
--- a/cli/changes_tui/view.go
+++ b/cli/changes_tui/view.go
@@ -1,6 +1,8 @@
package changes_tui
import (
+ "strings"
+
"github.com/charmbracelet/bubbles/viewport"
"github.com/charmbracelet/lipgloss"
)
@@ -34,8 +36,17 @@ func (m changesUIModel) getMainViewDims() (int, int) {
tabsHeight := lipgloss.Height(m.renderPathTabs())
helpHeight := lipgloss.Height(m.renderHelp())
sidebarWidth := lipgloss.Width(m.renderSidebar())
+ mainViewHeaderHeight := lipgloss.Height(m.renderMainViewHeader())
+ mainViewFooterHeight := lipgloss.Height(m.renderMainViewFooter())
mainViewWidth := m.width - sidebarWidth
- mainViewHeight := m.height - (helpHeight + tabsHeight + lipgloss.Height(m.renderMainViewHeader()) + lipgloss.Height(m.renderMainViewFooter()))
+
+ mainViewHeight := m.height - (helpHeight + tabsHeight)
+
+ if m.selectedFullFile() {
+ mainViewHeight -= mainViewHeaderHeight
+ } else {
+ mainViewHeight -= (mainViewHeaderHeight + mainViewFooterHeight)
+ }
return mainViewWidth, mainViewHeight
}
@@ -43,47 +54,51 @@ func (m changesUIModel) getMainViewDims() (int, int) {
func (m *changesUIModel) initViewports() {
mainViewWidth, mainViewHeight := m.getMainViewDims()
m.changeOldViewport = viewport.New(mainViewWidth/2, mainViewHeight)
- m.changeOldViewport.Style = lipgloss.NewStyle().Padding(1)
+ m.changeOldViewport.Style = lipgloss.NewStyle().Padding(0, 1, 0, 1)
m.changeNewViewport = viewport.New(mainViewWidth/2, mainViewHeight)
- m.changeNewViewport.Style = lipgloss.NewStyle().Padding(1)
+ m.changeNewViewport.Style = lipgloss.NewStyle().Padding(0, 1, 0, 1)
m.fileViewport = viewport.New(mainViewWidth, mainViewHeight)
- m.fileViewport.Style = lipgloss.NewStyle().Padding(1)
+ m.fileViewport.Style = lipgloss.NewStyle().Padding(0, 1, 0, 1)
}
func (m *changesUIModel) updateViewportSizes() {
mainViewWidth, mainViewHeight := m.getMainViewDims()
- oldViewHeight := mainViewHeight
+ if m.selectedFullFile() {
+ fileViewHeight := mainViewHeight
- if m.oldScrollable() && (m.selectedViewport == 0 || !m.newScrollable()) {
- footerHeight := lipgloss.Height(m.renderScrollFooter())
- oldViewHeight -= footerHeight
- }
+ if m.fileScrollable() {
+ footerHeight := lipgloss.Height(m.renderScrollFooter())
+ fileViewHeight -= footerHeight
+ }
- newViewHeight := mainViewHeight
+ m.fileViewport.Width = mainViewWidth
+ m.fileViewport.Height = fileViewHeight
- if m.newScrollable() && (m.selectedViewport == 1 || !m.oldScrollable()) {
- footerHeight := lipgloss.Height(m.renderScrollFooter())
- newViewHeight -= footerHeight
- }
+ } else {
+ oldViewHeight := mainViewHeight
- fileViewHeight := mainViewHeight
+ if m.oldScrollable() && (m.selectedViewport == 0 || !m.newScrollable()) {
+ footerHeight := lipgloss.Height(m.renderScrollFooter())
+ oldViewHeight -= footerHeight
+ }
- if m.fileScrollable() {
- footerHeight := lipgloss.Height(m.renderScrollFooter())
- fileViewHeight -= footerHeight
- }
+ newViewHeight := mainViewHeight
- m.changeOldViewport.Width = mainViewWidth / 2
- m.changeOldViewport.Height = oldViewHeight
- m.changeNewViewport.Width = mainViewWidth / 2
- m.changeNewViewport.Height = newViewHeight
- m.fileViewport.Width = mainViewWidth
- m.fileViewport.Height = fileViewHeight
+ if m.newScrollable() && (m.selectedViewport == 1 || !m.oldScrollable()) {
+ footerHeight := lipgloss.Height(m.renderScrollFooter())
+ newViewHeight -= footerHeight
+ }
+
+ m.changeOldViewport.Width = mainViewWidth / 2
+ m.changeOldViewport.Height = oldViewHeight
+ m.changeNewViewport.Width = mainViewWidth / 2
+ m.changeNewViewport.Height = newViewHeight
+ }
}
func (m changesUIModel) renderHelp() string {
- help := ` (↑/↓) select change β€’ (ctrl+a) apply pending β€’ (ctrl+d) discard all β€’ (q)uit`
+ help := ` (↑/↓) select change β€’ (ctrl+a) apply pending β€’ (ctrl+d) drop all β€’ (q)uit`
style := lipgloss.NewStyle().Width(m.width).Inherit(topBorderStyle).Foreground(lipgloss.Color(helpTextColor))
return style.Render(help)
}
@@ -103,3 +118,31 @@ func (m changesUIModel) fileScrollable() bool {
func (m changesUIModel) selectedFullFile() bool {
return m.selectionInfo != nil && m.selectionInfo.currentRep == nil
}
+
+func (m *changesUIModel) scrollReplacementIntoView(oldContent, newContent string, numLinesPrepended int) {
+ scrollView := func(content string, view *viewport.Model) {
+ view.GotoTop()
+
+ if numLinesPrepended <= 2 {
+ return
+ }
+
+ visibleLines := view.VisibleLineCount()
+ contentLines := len(strings.Split(content, "\n"))
+
+ if contentLines >= (visibleLines - 2) {
+ view.LineDown(numLinesPrepended - 2)
+ } else {
+ diffAround := visibleLines - contentLines
+ toScroll := numLinesPrepended - diffAround/2
+ view.LineDown(toScroll)
+ }
+ }
+
+ if m.oldScrollable() {
+ scrollView(oldContent, &m.changeOldViewport)
+ }
+ if m.newScrollable() {
+ scrollView(newContent, &m.changeNewViewport)
+ }
+}