From 278a660d5a58eaa9f9c1ee6d6bcac25e6dc0dbe7 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Wed, 15 Jul 2026 22:10:26 +0200 Subject: [PATCH] Working inspector --- src/formatting.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++-- src/main.rs | 14 ++++++++--- src/types.rs | 35 +++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 13b7b8f..fa8aded 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,12 +1,69 @@ use crate::types::{ - ActivePosition, Alert, AlertLevel, EventLog, LogKind, MarketOverview, Signal, SignalKind, - Status, WatchListItem, + ActivePosition, Alert, AlertLevel, EventLog, InspectTarget, LogKind, MarketOverview, Signal, + SignalKind, Status, WatchListItem, }; pub trait Formatted { fn get_formatted(&self) -> Vec; } +impl Formatted for InspectTarget { + fn get_formatted(&self) -> Vec { + match self { + Self::None => vec!["\x1b[2mnothing to inspect\x1b[0m".to_string()], + + Self::Symbol { + symbol, + price, + trend, + market_trend, + volatility, + pressure, + alerts, + } => vec![ + Property("Symbol", format!("\x1b[35m{}\x1b[0m", symbol)), + Property("Price", format!("\x1b[96m{}\x1b[0m", format_f64(*price))), + Property("Trend", format!("{}", format_f64(*trend))), + Property("Market", format!("{:?}", market_trend)), + Property("Volatility", format!("{:?}", volatility)), + Property("Pressure", format!("{:+.2}%", pressure * 100.0)), + Property("Alerts", format!("{}", alerts.len())), + ] + .get_formatted(), + + Self::Position { + symbol, + profit, + amount, + } => vec![ + Property("Symbol", format!("\x1b[35m{}\x1b[0m", symbol)), + Property("Profit", format!("{:+.2}", profit)), + Property("Amount", format!("{}", amount)), + ] + .get_formatted(), + + Self::Signal { + kind, + symbol, + param, + price, + } => vec![ + Property("Type", format!("{:?}", kind)), + Property("Symbol", format!("\x1b[35m{}\x1b[0m", symbol)), + Property("Parameter", format!("{:?}", param)), + Property("Price", format!("\x1b[96m{}\x1b[0m", format_f64(*price))), + ] + .get_formatted(), + + Self::Alert { level, message } => vec![ + Property("Level", format!("{:?}", level)), + Property("Message", message.clone()), + ] + .get_formatted(), + } + } +} + impl Formatted for Alert { fn get_formatted(&self) -> Vec { vec![ diff --git a/src/main.rs b/src/main.rs index 746ad93..57033ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,13 +13,16 @@ use pulse_ui::{ align::End, input::{Input, InputState}, outline::{Outline, VLine}, - spaced::{SpacedColumns, SpacedColumns2, SpacedRows2}, + spaced::SpacedColumns, }, }; use crate::{ formatting::{Formatted, apply_padding}, - types::{ActivePosition, Alert, EventLog, MarketOverview, Signal, Status, WatchListItem}, + types::{ + ActivePosition, Alert, EventLog, InspectTarget, MarketOverview, Signal, Status, + WatchListItem, + }, }; pub struct PulseTradeApp { @@ -30,6 +33,7 @@ pub struct PulseTradeApp { signals: State>, market_overview: State, status: State, + inspect: State, } impl App for PulseTradeApp { @@ -232,7 +236,10 @@ impl App for PulseTradeApp { ), ( LayoutItem::Widget(Size::Flex(1)), - Box::new(vec![" INSPECTOR"].join("\n")), + Box::new(format!( + " INSPECTOR\n{}", + apply_padding(self.inspect.lock().await.get_formatted()).join("\n") + )), ), ( LayoutItem::Widget(Size::Flex(1)), @@ -264,6 +271,7 @@ async fn main() { active_positions: ctx.use_state(Vec::new()), signals: ctx.use_state(Vec::new()), logs: ctx.use_state(Vec::new()), + inspect: ctx.use_state(InspectTarget::None), market_overview: ctx.use_state(MarketOverview { trend: types::MarketTrend::Bullish, volatility: types::Volatility::High, diff --git a/src/types.rs b/src/types.rs index 9f9f1b3..f060b54 100644 --- a/src/types.rs +++ b/src/types.rs @@ -95,3 +95,38 @@ pub struct Alert { pub level: AlertLevel, pub message: String, } + +#[derive(Debug, Clone)] +pub enum InspectTarget { + None, + + Symbol { + symbol: String, + price: f64, + trend: f64, + + market_trend: MarketTrend, + volatility: Volatility, + pressure: f64, + + alerts: Vec, + }, + + Position { + symbol: String, + profit: f64, + amount: f64, + }, + + Signal { + kind: SignalKind, + symbol: String, + param: SignalParameter, + price: f64, + }, + + Alert { + level: AlertLevel, + message: String, + }, +}