feat(tui): add balance status item#1970
Open
MoriTang wants to merge 7 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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.
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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