diff --git a/src/config.rs b/src/config.rs index 3273077..ea53c33 100644 --- a/src/config.rs +++ b/src/config.rs @@ -47,6 +47,10 @@ pub struct CostConfig { pub critical_threshold: Option, pub critical_style: Option, pub format: Option, + /// Currency symbol to display instead of `$`. Defaults to `$`. + pub currency_symbol: Option, + /// Conversion rate from USD to the target currency. Defaults to 1.0 (no conversion). + pub conversion_rate: Option, // Sub-field per-display configs (map to [cship.cost.total_cost_usd] etc.) pub total_cost_usd: Option, pub total_duration_ms: Option, diff --git a/src/modules/cost.rs b/src/modules/cost.rs index f44851c..22950fd 100644 --- a/src/modules/cost.rs +++ b/src/modules/cost.rs @@ -29,7 +29,10 @@ pub fn render(ctx: &Context, cfg: &CshipConfig) -> Option { let symbol = cost_cfg.and_then(|c| c.symbol.as_deref()); let style = cost_cfg.and_then(|c| c.style.as_deref()); - let formatted = format!("${:.2}", val); + let currency_symbol = cost_cfg.and_then(|c| c.currency_symbol.as_deref()).unwrap_or("$"); + let conversion_rate = cost_cfg.and_then(|c| c.conversion_rate).unwrap_or(1.0); + let converted_val = val * conversion_rate; + let formatted = format!("{}{:.2}", currency_symbol, converted_val); // Extract threshold variables FIRST (before format check) let warn_threshold = cost_cfg.and_then(|c| c.warn_threshold); @@ -323,6 +326,35 @@ mod tests { assert_eq!(result, Some("$0.01".to_string())); } + #[test] + fn test_cost_renders_custom_currency_symbol() { + let ctx = ctx_with_cost(1.50); + let cfg = CshipConfig { + cost: Some(CostConfig { + currency_symbol: Some("£".to_string()), + ..Default::default() + }), + ..Default::default() + }; + let result = render(&ctx, &cfg); + assert_eq!(result, Some("£1.50".to_string())); + } + + #[test] + fn test_cost_renders_with_conversion_rate() { + let ctx = ctx_with_cost(1.00); + let cfg = CshipConfig { + cost: Some(CostConfig { + currency_symbol: Some("£".to_string()), + conversion_rate: Some(0.79), + ..Default::default() + }), + ..Default::default() + }; + let result = render(&ctx, &cfg); + assert_eq!(result, Some("£0.79".to_string())); + } + #[test] fn test_cost_disabled_returns_none() { let ctx = ctx_with_cost(5.0);