Skip to content

Commit

Permalink
feat: introduce --no-tui flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Feb 2, 2025
1 parent 70ca28c commit b8f1d73
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
3 changes: 3 additions & 0 deletions crates/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ pub struct StartSimnet {
/// Set the ip
#[arg(long = "ip", short = 'i', default_value = DEFAULT_BINDING_ADDRESS )]
pub network_binding_ip_address: String,
/// Display streams of logs instead of terminal UI dashboard
#[clap(long = "no-tui")]
pub no_tui: bool,
}

#[derive(Parser, PartialEq, Clone, Debug)]
Expand Down
45 changes: 41 additions & 4 deletions crates/cli/src/cli/simnet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::sync::mpsc::channel;
use std::sync::mpsc::{channel, Receiver};

use crate::tui;

use super::{Context, StartSimnet};
use surfpool_core::start_simnet;
use surfpool_core::{simnet::SimnetEvent, start_simnet};

pub fn handle_start_simnet_command(_cmd: &StartSimnet, ctx: &Context) -> Result<(), String> {
pub fn handle_start_simnet_command(cmd: &StartSimnet, ctx: &Context) -> Result<(), String> {
let (simnet_events_tx, simnet_events_rx) = channel();
let ctx_cloned = ctx.clone();
// Start backend - background task
Expand All @@ -21,6 +21,43 @@ pub fn handle_start_simnet_command(_cmd: &StartSimnet, ctx: &Context) -> Result<
})
.map_err(|e| format!("{}", e))?;
// Start frontend - kept on main thread
tui::simnet::start_app(simnet_events_rx).map_err(|e| format!("{}", e))?;
if cmd.no_tui {
log_events(simnet_events_rx, ctx);
} else {
tui::simnet::start_app(simnet_events_rx).map_err(|e| format!("{}", e))?;
}
handle.join().map_err(|_e| format!("unable to terminate"))?
}

fn log_events(simnet_events_rx: Receiver<SimnetEvent>, ctx: &Context) {
info!(
ctx.expect_logger(),
"Surfpool: The best place to train before surfing Solana"
);
while let Ok(event) = simnet_events_rx.recv() {
match event {
SimnetEvent::AccountUpdate(account) => {
info!(
ctx.expect_logger(),
"Account retrieved from Mainnet {}", account
);
}
SimnetEvent::ClockUpdate(clock) => {
info!(ctx.expect_logger(), "Slot #{} ", clock.slot);
}
SimnetEvent::ErroLog(log) => {
error!(ctx.expect_logger(), "{} ", log);
}
SimnetEvent::InfoLog(log) => {
info!(ctx.expect_logger(), "{} ", log);
}
SimnetEvent::WarnLog(log) => {
warn!(ctx.expect_logger(), "{} ", log);
}
SimnetEvent::TransactionReceived(transaction) => {
info!(ctx.expect_logger(), "Transaction received");
}
SimnetEvent::BlockHashExpired => {}
}
}
}

0 comments on commit b8f1d73

Please sign in to comment.