diff --git a/src/terminal/formatting.rs b/src/terminal/formatting.rs index ba695f4..80e7847 100644 --- a/src/terminal/formatting.rs +++ b/src/terminal/formatting.rs @@ -53,8 +53,8 @@ impl Formatted for SignalStatus { } else { format!("\x1b[31mSELL\x1b[0m") }, - format!("\x1b[35m{}\x1b[0m", signal.symbol), - signal.price.to_string(), + format_symbol(&signal.symbol), + format_usd(signal.price.as_f64()), format!("\x1b[33mAPR {}\x1b[0m", signal.confidence), ] } @@ -67,8 +67,8 @@ impl Formatted for SignalStatus { } else { format!("\x1b[31mSELL\x1b[0m") }, - format!("\x1b[35m{}\x1b[0m", signal.symbol), - signal.price.to_string(), + format_symbol(&signal.symbol), + format_usd(signal.price.as_f64()), format!("\x1b[33mAPR {}\x1b[0m", signal.confidence), ] } @@ -79,9 +79,9 @@ impl Formatted for SignalStatus { impl Formatted for MarketItem { fn get_formatted(&self) -> Vec { vec![ - self.symbol.to_string(), - self.price.to_string(), - self.volume_24h.to_string(), + format_symbol(&self.symbol), + format_usd(self.price.as_f64()), + format_usd(self.volume_24h.as_f64()), format!( "{} {}%", if self.trend.is_sign_positive() { @@ -98,7 +98,7 @@ impl Formatted for MarketItem { impl Formatted for Position { fn get_formatted(&self) -> Vec { vec![ - self.symbol.to_string(), + format_symbol(&self.symbol), format_f64(self.size.as_f64()), self.entry_price.to_string(), format!( @@ -232,6 +232,18 @@ pub fn apply_padding(mut items: Vec) -> Vec { items } +pub fn format_symbol(value: &str) -> String { + format!("\x1b[35m{value}\x1b[0m") +} + +pub fn format_usd(value: f64) -> String { + if value.is_sign_positive() { + format!("\x1b[32m${}\x1b[0m", format_f64(value)) + } else { + format!("\x1b[31m${}\x1b[0m", format_f64(value)) + } +} + pub fn format_f64(value: f64) -> String { let abs = value.abs();