feat(tui): add balance status item#1705
Conversation
There was a problem hiding this comment.
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.
|
This PR was opened before the v0.8.41 rebrand and is now stale. Feel free to rebase onto current |
I have rebased new main branch and PR again. |
Summary
支持底部状态栏自定义配置([statusline]),显示 API 余额等实时信息 #1551
Adds a DeepSeek account balance chip to the footer status bar. The balance
is fetched from
GET /user/balanceonce per turn completion and displayedalongside 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
StatusItem::Balancepricing.rsBalanceResponse/BalanceInfodeserialization structstui/ui.rsfetch_deepseek_balance()— async HTTP fetch using the configured API keytui/footer_ui.rsfooter_balance_spans()— formats balance with currency-appropriate precisiontui/widgets/footer.rsFooterProps.balancefield, left-cluster rendering in the footer widgettui/views/status_picker.rsStatusPickerView::new(active, provider)filters rows byis_available_forconfig.rsdefault_footer()excludes Balance (provider-specific); it must be opted in via/statuslineProvider gating
Deepseek/DeepseekCNprovidersStatusItem::is_available_for()returnsfalsefor Balance on all other providers/statuslinepicker filters unavailable items so non-DeepSeek users never see the toggleTests
New tests in
pricing.rs,ui/tests.rs,config.rs, andstatus_picker.rs: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_fromwith/without Balance in items (2 cases)is_available_foracross all known providers (1 case)No regressions: 191 tests in the impacted modules pass.
Testing
cargo test --all-featurescargo fmt --all -- --checkcargo clippy --all-targets --all-featuresChecklist