Event logs

This commit is contained in:
2026-07-15 08:48:19 -04:00
parent a37d21afd1
commit ea156338a3
3 changed files with 46 additions and 4 deletions
+22 -1
View File
@@ -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<String>;
}
impl Formatted for EventLog {
fn get_formatted(&self) -> Vec<String> {
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<String> {
vec![
+9 -3
View File
@@ -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<InputState>,
watch_list: State<Vec<WatchListItem>>,
active_positions: State<Vec<ActivePosition>>,
logs: State<Vec<EventLog>>,
signals: State<Vec<Signal>>,
account: State<Account>,
system: State<System>,
@@ -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,
+15
View File
@@ -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,
}