Skip to content
Merged
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
45 changes: 22 additions & 23 deletions pkg/tui/components/sidebar/sidebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,16 @@ func formatCost(cost float64) string {
}

// contextPercent returns a context usage percentage string when a single session has a limit.
func (m *model) contextPercent() (string, bool) {
if len(m.sessionUsage) != 1 {
return "", false
}
for _, usage := range m.sessionUsage {
if usage.ContextLimit > 0 {
percent := (float64(usage.ContextLength) / float64(usage.ContextLimit)) * 100
return fmt.Sprintf("%.0f%%", percent), true
func (m *model) contextPercent() string {
if len(m.sessionUsage) == 1 {
for _, usage := range m.sessionUsage {
if usage.ContextLimit > 0 {
percent := (float64(usage.ContextLength) / float64(usage.ContextLimit)) * 100
return fmt.Sprintf("%.0f%%", percent)
}
}
}
return "", false
return "0%"
}

// getCurrentWorkingDirectory returns the current working directory with home directory replaced by ~/
Expand Down Expand Up @@ -272,15 +271,15 @@ func (m *model) verticalView() string {
if sessionInfo := m.sessionInfo(); sessionInfo != "" {
main = append(main, sessionInfo)
}
if usage := m.tokenUsage(); usage != "" {
main = append(main, usage)
}
if agentInfo := m.agentInfo(); agentInfo != "" {
main = append(main, agentInfo)
}
if toolsetInfo := m.toolsetInfo(); toolsetInfo != "" {
main = append(main, toolsetInfo)
}
if usage := m.tokenUsage(); usage != "" {
main = append(main, usage)
}

m.todoComp.SetSize(m.width)
todoContent := strings.TrimSuffix(m.todoComp.Render(), "\n")
Expand Down Expand Up @@ -441,10 +440,6 @@ func (m *model) workingIndicatorHorizontal() string {
}

func (m *model) tokenUsage() string {
if len(m.sessionUsage) == 0 {
return ""
}

var totalTokens int64
var totalCost float64
for _, usage := range m.sessionUsage {
Expand All @@ -454,7 +449,7 @@ func (m *model) tokenUsage() string {

var tokenUsage strings.Builder
fmt.Fprintf(&tokenUsage, "%s", formatTokenCount(totalTokens))
if ctxText, ok := m.contextPercent(); ok {
if ctxText := m.contextPercent(); ctxText != "" {
fmt.Fprintf(&tokenUsage, " (%s)", ctxText)
}
fmt.Fprintf(&tokenUsage, " %s", styles.TabAccentStyle.Render("$"+formatCost(totalCost)))
Expand All @@ -475,23 +470,22 @@ func (m *model) tokenUsageSummary() string {
totalCost += usage.Cost
}

if ctxText, ok := m.contextPercent(); ok {
if ctxText := m.contextPercent(); ctxText != "" {
return fmt.Sprintf("Tokens: %s | Cost: $%s | Context: %s", formatTokenCount(totalTokens), formatCost(totalCost), ctxText)
}

return fmt.Sprintf("Tokens: %s | Cost: $%s", formatTokenCount(totalTokens), formatCost(totalCost))
}

func (m *model) sessionInfo() string {
var lines []string
lines := []string{
m.sessionTitle,
"",
}

lines = append(lines, m.sessionTitle, "")
if pwd := getCurrentWorkingDirectory(); pwd != "" {
lines = append(lines, styles.TabAccentStyle.Render("█")+styles.TabPrimaryStyle.Render(" "+pwd))
}
if working := m.workingIndicator(); working != "" {
lines = append(lines, working)
}

return m.renderTab("Session", strings.Join(lines, "\n"))
}
Expand Down Expand Up @@ -552,12 +546,17 @@ func (m *model) toolsetInfo() string {
shortcut := lipgloss.PlaceHorizontal(m.width-lipgloss.Width(indicator)-2, lipgloss.Right, styles.MutedStyle.Render("^y"))
lines = append(lines, indicator+shortcut)
}

if m.sessionState.SplitDiffView {
indicator := styles.TabAccentStyle.Render("✓") + styles.TabPrimaryStyle.Render(" Split Diff View enabled")
shortcut := lipgloss.PlaceHorizontal(m.width-lipgloss.Width(indicator)-2, lipgloss.Right, styles.MutedStyle.Render("^t"))
lines = append(lines, indicator+shortcut)
}

if working := m.workingIndicator(); working != "" {
lines = append(lines, working)
}

return m.renderTab("Tools", lipgloss.JoinVertical(lipgloss.Top, lines...))
}

Expand Down