Using Option for statuses
This commit is contained in:
+27
-16
@@ -30,12 +30,14 @@ pub struct PulseTradeApp {
|
||||
|
||||
command: State<InputState>,
|
||||
scroll: State<ScrollState<7>>,
|
||||
|
||||
market_overview: State<Option<MarketOverview>>,
|
||||
status: State<Option<Status>>,
|
||||
|
||||
watch_list: State<Vec<WatchListItem>>,
|
||||
active_positions: State<Vec<ActivePosition>>,
|
||||
logs: State<Vec<EventLog>>,
|
||||
signals: State<Vec<Signal>>,
|
||||
market_overview: State<MarketOverview>,
|
||||
status: State<Status>,
|
||||
inspect: State<InspectTarget>,
|
||||
}
|
||||
|
||||
@@ -135,7 +137,7 @@ impl App for PulseTradeApp {
|
||||
(
|
||||
LayoutItem::Widget(Size::Flex(1)),
|
||||
Box::new(
|
||||
advanced_draw(&self.scroll, 2, "MARKET OVERVIEW", &self.market_overview)
|
||||
advanced_option_draw(&self.scroll, 2, "MARKET OVERVIEW", &self.market_overview)
|
||||
.await,
|
||||
),
|
||||
),
|
||||
@@ -155,7 +157,7 @@ impl App for PulseTradeApp {
|
||||
),
|
||||
(
|
||||
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()),
|
||||
logs: ctx.use_state(Vec::new()),
|
||||
inspect: ctx.use_state(InspectTarget::None),
|
||||
market_overview: ctx.use_state(MarketOverview {
|
||||
trend: pulse_wire::terminal::MarketTrend::Bullish,
|
||||
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,
|
||||
}),
|
||||
market_overview: ctx.use_state(None),
|
||||
status: ctx.use_state(None),
|
||||
})
|
||||
})
|
||||
.await;
|
||||
@@ -216,3 +208,22 @@ pub async fn advanced_draw<const N: usize, T: Formatted>(
|
||||
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()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user