feat(zsh): add currency conversion support for cost display#2382
feat(zsh): add currency conversion support for cost display#2382tusharmath merged 6 commits intomainfrom
Conversation
|
Tushar Mathur seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
| .conversion_ratio(83.5) | ||
| .to_string(); | ||
|
|
||
| let expected = " %B%F{15}\u{f167a} FORGE%f%b %B%F{15}1.5k%f%b %B%F{2}INR0.83%f%b %F{134}\u{ec19} gpt-4%f"; |
There was a problem hiding this comment.
Test expectation is mathematically incorrect. The calculation 0.01 * 83.5 = 0.835 will round to 0.84 when formatted with {:.2}, not 0.83. This test will fail.
let expected = " %B%F{15}\u{f167a} FORGE%f%b %B%F{15}1.5k%f%b %B%F{2}INR0.84%f%b %F{134}\u{ec19} gpt-4%f";| let expected = " %B%F{15}\u{f167a} FORGE%f%b %B%F{15}1.5k%f%b %B%F{2}INR0.83%f%b %F{134}\u{ec19} gpt-4%f"; | |
| let expected = " %B%F{15}\u{f167a} FORGE%f%b %B%F{15}1.5k%f%b %B%F{2}INR0.84%f%b %F{134}\u{ec19} gpt-4%f"; |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
| token_count: None, | ||
| cost: None, | ||
| use_nerd_font: true, | ||
| currency_symbol: "\u{f155}".to_string(), |
There was a problem hiding this comment.
Inconsistent default currency symbol. The Default impl sets currency_symbol to "\u{f155}" (a Nerd Font icon), but the UI code in ui.rs defaults to "$" when FORGE_CURRENCY_SYMBOL is not set, and all documentation states the default is "$". This creates inconsistent behavior depending on how ZshRPrompt is instantiated.
// Should be:
currency_symbol: "$".to_string(),This ensures consistency with the documented behavior and the UI code path. The Nerd Font icon \u{f155} should only be used when explicitly configured via the environment variable or builder method.
| currency_symbol: "\u{f155}".to_string(), | |
| currency_symbol: "$".to_string(), |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
Summary
Add configurable currency conversion support to zsh rprompt cost display, enabling users to view costs in their preferred currency and exchange rate.
Context
The zsh rprompt previously displayed costs only in USD with a hardcoded "$" symbol. Users in different regions needed to mentally convert costs to their local currency, which was inconvenient and error-prone. This change allows users to configure their preferred currency symbol and conversion rate via environment variables.
Changes
currency_symbolandconversion_ratiofields toZshRPromptstructFORGE_CURRENCY_SYMBOL(defaults to "$")FORGE_CURRENCY_CONVERSION_RATE(defaults to 1.0)Key Implementation Details
Use Cases
export FORGE_CURRENCY_SYMBOL=INR FORGE_CURRENCY_CONVERSION_RATE=83.5export FORGE_CURRENCY_SYMBOL=€ FORGE_CURRENCY_CONVERSION_RATE=0.92export FORGE_CURRENCY_SYMBOL=£ FORGE_CURRENCY_CONVERSION_RATE=0.79Testing
Links
crates/forge_main/src/zsh/rprompt.rs,crates/forge_main/src/ui.rs