Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Cleanup #18

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion blast_cli/src/blast_cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Standard libraries
use std::env;
use std::path::PathBuf;

// Blast libraries
use blast_core::Blast;

Expand All @@ -18,8 +22,18 @@ pub struct BlastCli {

impl BlastCli {
pub fn new() -> Self {
// Get the model directory
let mut current_dir = match env::current_dir() {
Ok(d) => d,
Err(_) => {
PathBuf::new()
}
};
current_dir.push("../blast_models/");
let model_dir = current_dir.to_string_lossy().into_owned();

// Create the blast core object
let blast = Blast::new();
let blast = Blast::new(model_dir);

// Get a list of the available models
let mut model_list: Vec<Model> = Vec::new();
Expand Down
18 changes: 9 additions & 9 deletions blast_cli/src/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,48 +101,48 @@ impl BlastTab for ConfigureTab {
[Constraint::Percentage(5), Constraint::Percentage(95)],
)
.split(area);

let layout1 = Layout::new(
Direction::Horizontal,
[Constraint::Percentage(50), Constraint::Percentage(50)],
)
.split(l[1]);

let layout = Layout::new(
Direction::Vertical,
[Constraint::Percentage(33), Constraint::Percentage(33), Constraint::Percentage(33)],
).split(layout1[1]);

let e: Vec<ListItem> = self.events.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let etasks = List::new(e)
.block(Block::bordered().title("Events"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(etasks, layout[0], &mut self.events.state);

let c: Vec<ListItem> = self.channels.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let ctasks = List::new(c)
.block(Block::bordered().title("Channels"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(ctasks, layout[1], &mut self.channels.state);

let a: Vec<ListItem> = self.activity.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let atasks = List::new(a)
.block(Block::bordered().title("Activity"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(atasks, layout[2], &mut self.activity.state);

let vertical = Layout::vertical([
Constraint::Length(3),
Constraint::Min(1),
]);
let [input_area, messages_area] = vertical.areas(layout1[0]);

let msg = vec![
"Use ".into(),
"stop".bold(),
Expand All @@ -157,15 +157,15 @@ impl BlastTab for ConfigureTab {
let text = Text::from(Line::from(msg)).patch_style(Style::default());
let help_message = Paragraph::new(text);
frame.render_widget(help_message, l[0]);

let input = Paragraph::new(self.input.as_str())
.style(match self.current_section {
ConfigureSection::Command => Style::default().fg(Color::LightYellow),
_ => Style::default(),
})
.block(Block::bordered().title("Command"));
frame.render_widget(input, input_area);

match self.current_section {
ConfigureSection::Command => {
#[allow(clippy::cast_possible_truncation)]
Expand Down
2 changes: 1 addition & 1 deletion blast_cli/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl BlastTab for LoadTab {
.iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))]))
.collect();

let tasks = List::new(tasks)
.block(Block::bordered().title("Simulations"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
Expand Down
6 changes: 3 additions & 3 deletions blast_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ async fn run<B: Backend>(terminal: &mut Terminal<B>, mut blast_cli: BlastCli) ->
Err(e) => {
failed = true;
error_str = e;
}
}
}

// Start the simulation
Expand Down Expand Up @@ -375,7 +375,7 @@ fn ui(frame: &mut Frame, tab: &mut dyn BlastTab, error: Option<String>) {
.block(Block::bordered().title("Error"));
let area = centered_rect(60, 20, chunks[1]);
frame.render_widget(Clear, area);
frame.render_widget(error_msg, area);
frame.render_widget(error_msg, area);
},
None => {
// Draw the current page
Expand Down Expand Up @@ -572,7 +572,7 @@ async fn run_command(blast: &mut blast_core::Blast, cmd: String) -> Vec<String>
let msg = format!("Unable to open channel: {}", e);
output.push(msg);
}
}
}
},
"connect_peer" => {
let source = String::from(words.next().unwrap_or(""));
Expand Down
2 changes: 1 addition & 1 deletion blast_cli/src/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl BlastTab for NewTab {
.iter()
.map(|i| ListItem::new(i.clone()))
.collect();

let tasks = List::new(tasks)
.block(Block::bordered().title("Models"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
Expand Down
18 changes: 9 additions & 9 deletions blast_cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl BlastTab for RunTab {
[Constraint::Percentage(5), Constraint::Percentage(10), Constraint::Percentage(85)],
)
.split(area);

let msg = vec![
"Press ".into(),
"s".bold(),
Expand All @@ -61,50 +61,50 @@ impl BlastTab for RunTab {
let text = Text::from(Line::from(msg)).patch_style(Style::default());
let help_message = Paragraph::new(text);
frame.render_widget(help_message, layout[0]);

let line_gauge = LineGauge::default()
.block(Block::new().title("Simulation Progress:"))
.filled_style(Style::default().fg(Color::LightBlue))
.line_set(symbols::line::THICK)
.ratio(self.progress);
frame.render_widget(line_gauge, layout[1]);

let layout2 = Layout::new(
Direction::Horizontal,
[Constraint::Percentage(50), Constraint::Percentage(50)],
)
.split(layout[2]);

let layout3 = Layout::new(
Direction::Vertical,
[Constraint::Percentage(33), Constraint::Percentage(50), Constraint::Percentage(33)],
)
.split(layout2[0]);

let e: Vec<ListItem> = self.events.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let etasks = List::new(e)
.block(Block::bordered().title("Events"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(etasks, layout3[0], &mut self.events.state);

let a: Vec<ListItem> = self.activity.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let atasks = List::new(a)
.block(Block::bordered().title("Activity"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(atasks, layout3[1], &mut self.activity.state);

let s: Vec<ListItem> = self.stats.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let stasks = List::new(s)
.block(Block::bordered().title("Stats"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(stasks, layout3[2], &mut self.stats.state);

let x_labels = vec![
Span::styled(
format!("{}", self.window[0]),
Expand Down Expand Up @@ -259,7 +259,7 @@ impl BlastTab for RunTab {
for i in 0..20 {
self.success_rate_data[i] = self.success_rate_data[i + 1];
}

self.success_rate_data[20] = (frame as f64, succes_rate);
}
}
Expand Down
8 changes: 4 additions & 4 deletions blast_cli/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use ratatui::{

// BLAST constants
pub const BANNER: &str = r"
____ _ _____ _______
____ _ _____ _______
| _ \| | /\ / ____|__ __|
| |_) | | / \ | (___ | |
| _ <| | / /\ \ \___ \ | |
| |_) | |____ / ____ \ ____) | | |
| |_) | | / \ | (___ | |
| _ <| | / /\ \ \___ \ | |
| |_) | |____ / ____ \ ____) | | |
|____/|______/_/ \_\_____/ |_| ";

pub const TAB_TITLES: [&'static str; 4] = ["New", "Load", "Configure", "Run"];
Expand Down
4 changes: 2 additions & 2 deletions blast_core/src/blast_event_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl BlastEventManager {
Ok(n) => n,
Err(e) => return Err(format!("Error parsing argument: {}", e))
};

let blast_event = BlastEvent::CloseChannelEvent(arg0, arg1);
self.push_event(frame_num, blast_event);
Ok(())
Expand All @@ -208,7 +208,7 @@ impl BlastEventManager {
Ok(n) => n,
Err(e) => return Err(format!("Error parsing argument: {}", e))
};

let blast_event = BlastEvent::OnChainTransaction(arg0, arg1, arg2);
self.push_event(frame_num, blast_event);
Ok(())
Expand Down
Loading
Loading