summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-12 14:08:57 -0500
committeradamdottv <[email protected]>2025-05-12 14:08:57 -0500
commitc9b90dd184084a2a3669db49717eb485c8861ee4 (patch)
treee5d4f1ba678d6c5626f9e7cc68047705c66ed1f9
parent8270a1e4b133b44b4b68c8b52567200fc69343e6 (diff)
downloadopencode-c9b90dd184084a2a3669db49717eb485c8861ee4.tar.gz
opencode-c9b90dd184084a2a3669db49717eb485c8861ee4.zip
fix: show context %
-rw-r--r--internal/tui/components/core/status.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/internal/tui/components/core/status.go b/internal/tui/components/core/status.go
index 5de0b852e..d6612fed4 100644
--- a/internal/tui/components/core/status.go
+++ b/internal/tui/components/core/status.go
@@ -110,7 +110,7 @@ func getHelpWidget(helpText string) string {
Render(helpText)
}
-func formatTokensAndCost(tokens int64, cost float64) string {
+func formatTokensAndCost(tokens int64, contextWindow int64, cost float64) string {
// Format tokens in human-readable format (e.g., 110K, 1.2M)
var formattedTokens string
switch {
@@ -133,17 +133,21 @@ func formatTokensAndCost(tokens int64, cost float64) string {
// Format cost with $ symbol and 2 decimal places
formattedCost := fmt.Sprintf("$%.2f", cost)
- return fmt.Sprintf("Tokens: %s, Cost: %s", formattedTokens, formattedCost)
+ percentage := (float64(tokens) / float64(contextWindow)) * 100
+
+ return fmt.Sprintf("Tokens: %s (%d%%), Cost: %s", formattedTokens, int(percentage), formattedCost)
}
func (m statusCmp) View() string {
t := theme.CurrentTheme()
+ modelID := config.Get().Agents[config.AgentCoder].Model
+ model := models.SupportedModels[modelID]
// Initialize the help widget
status := getHelpWidget("")
if m.session.ID != "" {
- tokens := formatTokensAndCost(m.session.PromptTokens+m.session.CompletionTokens, m.session.Cost)
+ tokens := formatTokensAndCost(m.session.PromptTokens+m.session.CompletionTokens, model.ContextWindow, m.session.Cost)
tokensStyle := styles.Padded().
Background(t.Text()).
Foreground(t.BackgroundSecondary()).
@@ -153,13 +157,13 @@ func (m statusCmp) View() string {
diagnostics := styles.Padded().Background(t.BackgroundDarker()).Render(m.projectDiagnostics())
- model := m.model()
+ modelName := m.model()
statusWidth := max(
0,
m.width-
lipgloss.Width(status)-
- lipgloss.Width(model)-
+ lipgloss.Width(modelName)-
lipgloss.Width(diagnostics),
)
@@ -198,7 +202,7 @@ func (m statusCmp) View() string {
}
status += diagnostics
- status += model
+ status += modelName
return status
}