Skip to content

feat(tui): add balance status item#1970

Open
MoriTang wants to merge 7 commits into
Hmbown:mainfrom
MoriTang:feat/balance-status-item
Open

feat(tui): add balance status item#1970
MoriTang wants to merge 7 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 introduces a DeepSeek account balance display in the TUI footer. Key changes include the implementation of background fetching for balance information after each turn completion, localized strings for the balance prefix, and updates to the footer rendering logic to include the new balance chip. Additionally, the status picker was enhanced with provider-specific filtering and scrolling capabilities. Review feedback suggests adding a timeout to the background HTTP client to prevent stalled tasks, displaying the balance even when it is zero to notify users of empty accounts, and improving the currency symbol mapping to handle future currency additions more robustly.

Comment thread crates/tui/src/tui/ui.rs Outdated
Comment thread crates/tui/src/tui/footer_ui.rs Outdated
Comment thread crates/tui/src/tui/footer_ui.rs
@MoriTang MoriTang changed the title Feat/balance status item feat(tui): add balance status item May 24, 2026
@MoriTang MoriTang mentioned this pull request May 25, 2026
6 tasks
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.

1 participant