Using Option for statuses
This commit is contained in:
@@ -19,7 +19,7 @@ pub enum TerminalServerMessage {
|
|||||||
Inspect(InspectTarget),
|
Inspect(InspectTarget),
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
SetStatus(Status),
|
StatusUpdated(Status),
|
||||||
|
|
||||||
// Logs
|
// Logs
|
||||||
SetLogs(Vec<EventLog>),
|
SetLogs(Vec<EventLog>),
|
||||||
|
|||||||
+27
-16
@@ -30,12 +30,14 @@ pub struct PulseTradeApp {
|
|||||||
|
|
||||||
command: State<InputState>,
|
command: State<InputState>,
|
||||||
scroll: State<ScrollState<7>>,
|
scroll: State<ScrollState<7>>,
|
||||||
|
|
||||||
|
market_overview: State<Option<MarketOverview>>,
|
||||||
|
status: State<Option<Status>>,
|
||||||
|
|
||||||
watch_list: State<Vec<WatchListItem>>,
|
watch_list: State<Vec<WatchListItem>>,
|
||||||
active_positions: State<Vec<ActivePosition>>,
|
active_positions: State<Vec<ActivePosition>>,
|
||||||
logs: State<Vec<EventLog>>,
|
logs: State<Vec<EventLog>>,
|
||||||
signals: State<Vec<Signal>>,
|
signals: State<Vec<Signal>>,
|
||||||
market_overview: State<MarketOverview>,
|
|
||||||
status: State<Status>,
|
|
||||||
inspect: State<InspectTarget>,
|
inspect: State<InspectTarget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +137,7 @@ impl App for PulseTradeApp {
|
|||||||
(
|
(
|
||||||
LayoutItem::Widget(Size::Flex(1)),
|
LayoutItem::Widget(Size::Flex(1)),
|
||||||
Box::new(
|
Box::new(
|
||||||
advanced_draw(&self.scroll, 2, "MARKET OVERVIEW", &self.market_overview)
|
advanced_option_draw(&self.scroll, 2, "MARKET OVERVIEW", &self.market_overview)
|
||||||
.await,
|
.await,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -155,7 +157,7 @@ impl App for PulseTradeApp {
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
LayoutItem::Widget(Size::Flex(1)),
|
LayoutItem::Widget(Size::Flex(1)),
|
||||||
Box::new(advanced_draw(&self.scroll, 5, "STATUS", &self.status).await),
|
Box::new(advanced_option_draw(&self.scroll, 5, "STATUS", &self.status).await),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
@@ -183,18 +185,8 @@ async fn main() -> tokio::io::Result<()> {
|
|||||||
signals: ctx.use_state(Vec::new()),
|
signals: ctx.use_state(Vec::new()),
|
||||||
logs: ctx.use_state(Vec::new()),
|
logs: ctx.use_state(Vec::new()),
|
||||||
inspect: ctx.use_state(InspectTarget::None),
|
inspect: ctx.use_state(InspectTarget::None),
|
||||||
market_overview: ctx.use_state(MarketOverview {
|
market_overview: ctx.use_state(None),
|
||||||
trend: pulse_wire::terminal::MarketTrend::Bullish,
|
status: ctx.use_state(None),
|
||||||
volatility: pulse_wire::terminal::Volatility::High,
|
|
||||||
pressure: 0.324,
|
|
||||||
alerts: Vec::new(),
|
|
||||||
}),
|
|
||||||
status: ctx.use_state(Status {
|
|
||||||
feed: pulse_wire::terminal::Feed::Connected,
|
|
||||||
exchange: "Binance".to_string(),
|
|
||||||
dex: "DEX SCREENER".to_string(),
|
|
||||||
latency: 18,
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
@@ -216,3 +208,22 @@ pub async fn advanced_draw<const N: usize, T: Formatted>(
|
|||||||
apply_padding(state.lock().await.get_formatted()).join("\n"),
|
apply_padding(state.lock().await.get_formatted()).join("\n"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn advanced_option_draw<const N: usize, T: Formatted>(
|
||||||
|
scroll: &State<ScrollState<N>>,
|
||||||
|
index: usize,
|
||||||
|
title: &'static str,
|
||||||
|
state: &State<Option<T>>,
|
||||||
|
) -> ScrollText {
|
||||||
|
let scroll = scroll.lock().await;
|
||||||
|
|
||||||
|
scroll.scroll(
|
||||||
|
index,
|
||||||
|
format!(" {}{title}\x1b[0m", scroll.get_selected(index)),
|
||||||
|
if let Some(state) = &*state.lock().await {
|
||||||
|
apply_padding(state.get_formatted()).join("\n")
|
||||||
|
} else {
|
||||||
|
" Loading..".to_string()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ impl TerminalClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TerminalServerMessage::OverviewUpdated(v) => {
|
TerminalServerMessage::OverviewUpdated(v) => {
|
||||||
*market_overview.lock().await = v;
|
*market_overview.lock().await = Some(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalServerMessage::SignalsUpdated(v) => {
|
TerminalServerMessage::SignalsUpdated(v) => {
|
||||||
@@ -89,8 +89,8 @@ impl TerminalClient {
|
|||||||
*inspect.lock().await = v;
|
*inspect.lock().await = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalServerMessage::SetStatus(v) => {
|
TerminalServerMessage::StatusUpdated(v) => {
|
||||||
*status.lock().await = v;
|
*status.lock().await = Some(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
TerminalServerMessage::SetLogs(v) => {
|
TerminalServerMessage::SetLogs(v) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user