From ea156338a3423e279ce4e7b82c3928d6bd3151ec Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Wed, 15 Jul 2026 08:48:19 -0400 Subject: [PATCH] Event logs --- src/formatting.rs | 23 ++++++++++++++++++++++- src/main.rs | 12 +++++++++--- src/types.rs | 15 +++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index d01c9c3..00b677d 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,9 +1,30 @@ -use crate::types::{Account, ActivePosition, Signal, SignalKind, System, WatchListItem}; +use crate::types::{ + Account, ActivePosition, EventLog, LogKind, Signal, SignalKind, System, WatchListItem, +}; pub trait Formatted { fn get_formatted(&self) -> Vec; } +impl Formatted for EventLog { + fn get_formatted(&self) -> Vec { + vec![ + format!( + "{}{:?}\x1b[0m", + match &self.kind { + LogKind::INFO => "\x1b[34m", + LogKind::DEBUG => "\x1b[36m", + LogKind::ERR => "\x1b[31m", + LogKind::WARN => "\x1b[33m", + }, + self.kind + ), + format!("(\x1b[37m{}\x1b[0m)", self.name), + self.message.clone(), + ] + } +} + impl Formatted for Signal { fn get_formatted(&self) -> Vec { vec![ diff --git a/src/main.rs b/src/main.rs index 0406138..eadd47b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,13 +18,14 @@ use pulse_ui::{ use crate::{ formatting::{Formatted, apply_padding}, - types::{Account, ActivePosition, Signal, System, WatchListItem}, + types::{Account, ActivePosition, EventLog, Signal, System, WatchListItem}, }; pub struct PulseTradeApp { command: State, watch_list: State>, active_positions: State>, + logs: State>, signals: State>, account: State, system: State, @@ -193,8 +194,7 @@ impl App for PulseTradeApp { LayoutItem::Widget(Size::Flex(1)), Box::new(format!( " SIGNALS\n{}", - apply_padding(self.signals.lock().await.get_formatted()) - .join("\n") + apply_padding(self.signals.lock().await.get_formatted()).join("\n") )), ), ( @@ -207,6 +207,11 @@ impl App for PulseTradeApp { ]), ); + layout.draw( + 5, + apply_padding(self.logs.lock().await.get_formatted()).join("\n"), + ); + layout.draw(6, Input(" > ", &*self.command.lock().await)); } } @@ -218,6 +223,7 @@ async fn main() { watch_list: ctx.use_state(Vec::new()), active_positions: ctx.use_state(Vec::new()), signals: ctx.use_state(Vec::new()), + logs: ctx.use_state(Vec::new()), account: ctx.use_state(Account { equity: 25_483.21, liquid: 11_928.43, diff --git a/src/types.rs b/src/types.rs index d294fe9..758d400 100644 --- a/src/types.rs +++ b/src/types.rs @@ -53,3 +53,18 @@ pub struct Signal { pub param: SignalParameter, pub price: f64, } + +#[derive(Debug, Clone, Copy)] +pub enum LogKind { + INFO, + WARN, + ERR, + DEBUG, +} + +#[derive(Debug, Clone)] +pub struct EventLog { + pub kind: LogKind, + pub name: &'static str, + pub message: String, +}