Skip to content

feat(tui): add balance status item#1705

Closed
MoriTang wants to merge 6 commits into
Hmbown:mainfrom
MoriTang:feat/balance-status-item
Closed

feat(tui): add balance status item#1705
MoriTang wants to merge 6 commits into
Hmbown:mainfrom
MoriTang:feat/balance-status-item

Conversation

@MoriTang
Copy link
Copy Markdown

Summary

支持底部状态栏自定义配置([statusline]),显示 API 余额等实时信息 #1551

Adds a DeepSeek account balance chip to the footer status bar. The balance
is fetched from GET /user/balance once per turn completion and displayed
alongside mode, model, and session cost.

Non-DeepSeek providers never see the Balance toggle — the picker and default
footer both hide it behind StatusItem::is_available_for(provider).

Changes

Area Description
StatusItem::Balance New variant with key/label/description/hint
pricing.rs BalanceResponse / BalanceInfo deserialization structs
tui/ui.rs fetch_deepseek_balance() — async HTTP fetch using the configured API key
tui/footer_ui.rs footer_balance_spans() — formats balance with currency-appropriate precision
tui/widgets/footer.rs FooterProps.balance field, left-cluster rendering in the footer widget
tui/views/status_picker.rs StatusPickerView::new(active, provider) filters rows by is_available_for
config.rs default_footer() excludes Balance (provider-specific); it must be opted in via /statusline

Provider gating

  • Fetch triggers only for Deepseek / DeepseekCN providers
  • StatusItem::is_available_for() returns false for Balance on all other providers
  • The /statusline picker filters unavailable items so non-DeepSeek users never see the toggle

Tests

New tests in pricing.rs, ui/tests.rs, config.rs, and status_picker.rs:

  • BalanceResponse JSON deserialization (3 cases)
  • total_balance_f64() parsing — valid / empty / invalid (3 cases)
  • footer_balance_spans() — empty cell, zero, CNY, USD, large-amount rounding, unknown currency (6 cases)
  • render_footer_from with/without Balance in items (2 cases)
  • is_available_for across all known providers (1 case)
  • Picker row filtering for non-DeepSeek provider (1 case)

No regressions: 191 tests in the impacted modules pass.

Testing

  • cargo test --all-features
  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features

Checklist

  • Updated docs or comments as needed
  • Added or updated tests where relevant
  • Verified TUI behavior manually if UI changes

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a feature to display DeepSeek account balances in the TUI footer. Key changes include the addition of balance-related data structures, background fetching logic triggered after turn completions, and updates to the footer and status picker UI to accommodate the new balance chip. The status picker now supports scrolling and filters items based on the active API provider. Review feedback highlights several areas for improvement: preventing state overwrites on fetch failures to maintain UI stability, correcting height calculations in the status picker to prevent clipping, refining currency symbol logic for non-CNY currencies, localizing hardcoded strings, and optimizing network performance by reusing the HTTP client.

Comment thread crates/tui/src/tui/ui.rs
Comment thread crates/tui/src/tui/views/status_picker.rs Outdated
Comment thread crates/tui/src/tui/footer_ui.rs
Comment thread crates/tui/src/tui/footer_ui.rs Outdated
Comment thread crates/tui/src/tui/ui.rs Outdated
@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented May 23, 2026

This PR was opened before the v0.8.41 rebrand and is now stale. Feel free to rebase onto current main and reopen. 鲸鱼兄弟们等你 🐋

@Hmbown Hmbown closed this May 23, 2026
@MoriTang
Copy link
Copy Markdown
Author

MoriTang commented May 25, 2026

This PR was opened before the v0.8.41 rebrand and is now stale. Feel free to rebase onto current main and reopen. 鲸鱼兄弟们等你 🐋

I have rebased new main branch and PR again.

#1970

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants