Skip to content

Commit

Permalink
Cleaning up some ui things
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohnson5 committed Sep 25, 2024
1 parent 4c5a720 commit cfc1333
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 8 deletions.
6 changes: 6 additions & 0 deletions blast_cli/src/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ impl BlastTab for ConfigureTab {
" command to stop network, ".into(),
"start".bold(),
" command to start simulation, ".into(),
"help".bold(),
" command to show commands,".into(),
"Tab".bold(),
" to change sections".into()
];
Expand Down Expand Up @@ -332,4 +334,8 @@ impl BlastTab for ConfigureTab {
fn esc_operation(&mut self) -> ProcessResult {
ProcessResult::NoOp
}

fn quit_operation(&mut self) -> ProcessResult {
ProcessResult::NoOp
}
}
4 changes: 4 additions & 0 deletions blast_cli/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ impl BlastTab for LoadTab {
fn esc_operation(&mut self) -> ProcessResult {
ProcessResult::ExitPage
}

fn quit_operation(&mut self) -> ProcessResult {
ProcessResult::Quit
}
}
29 changes: 25 additions & 4 deletions blast_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ async fn run<B: Backend>(terminal: &mut Terminal<B>, mut blast_cli: BlastCli) ->
match key.code {
// Quit the BlastCli
KeyCode::Char('q') => {
return Ok(());
match current.quit_operation() {
ProcessResult::Quit => {
return Ok(());
},
_ => {}
}
}
KeyCode::Esc => {
match current.esc_operation() {
Expand Down Expand Up @@ -393,11 +398,27 @@ fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
async fn run_command(blast: &mut blast_core::Blast, cmd: String) -> Vec<String> {
let mut output: Vec<String> = Vec::new();
let mut words = cmd.split_whitespace();

// TODO: error handling and easier use of command parameters

if let Some(first_word) = words.next() {
match first_word {
"help" => {
output.push(String::from("Command Parameters "));
output.push(String::from("-----------------------------"));
output.push(String::from("save simulation_name"));
output.push(String::from("add_activity source_node dest_node start_secs count interval amount"));
output.push(String::from("add_event frame event_type event_args ..."));
output.push(String::from("get_nodes"));
output.push(String::from("get_pub_key node_name"));
output.push(String::from("list_peers node_name"));
output.push(String::from("wallet_balance node_name"));
output.push(String::from("channel_balance node_name"));
output.push(String::from("list_channels node_name"));
output.push(String::from("open_channel"));
output.push(String::from("close_channel"));
output.push(String::from("connect_peer"));
output.push(String::from("disconnect_peer"));
output.push(String::from("fund_node"));
}
"save" => {
match blast.save(words.next().unwrap_or("simulation1")).await {
Ok(()) => {
Expand Down Expand Up @@ -445,8 +466,8 @@ async fn run_command(blast: &mut blast_core::Blast, cmd: String) -> Vec<String>
event_args.push(String::from(w));
}

// TODO: easier use event command parameters
let args = if event_args.len() == 0 { None } else { Some(event_args) };

match blast.add_event(frame, &event, args) {
Ok(()) => {
output.push(String::from("Successfully added event."));
Expand Down
4 changes: 4 additions & 0 deletions blast_cli/src/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,8 @@ impl BlastTab for NewTab {
fn esc_operation(&mut self) -> ProcessResult {
ProcessResult::ExitPage
}

fn quit_operation(&mut self) -> ProcessResult {
ProcessResult::Quit
}
}
6 changes: 4 additions & 2 deletions blast_cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ impl BlastTab for RunTab {

let msg = vec![
"Press ".into(),
"q".bold(),
" to exit, ".into(),
"s".bold(),
" to stop sim, ".into(),
"Tab".bold(),
Expand Down Expand Up @@ -265,4 +263,8 @@ impl BlastTab for RunTab {
fn esc_operation(&mut self) -> ProcessResult {
ProcessResult::NoOp
}

fn quit_operation(&mut self) -> ProcessResult {
ProcessResult::NoOp
}
}
2 changes: 2 additions & 0 deletions blast_cli/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub enum ProcessResult {
StopSim,
Command(String),
ExitPage,
Quit,
NoOp,
}

Expand Down Expand Up @@ -99,4 +100,5 @@ pub trait BlastTab {
fn update_runtime_data(&mut self, events: Option<Vec<String>>, activity: Option<Vec<String>>, stats: Option<Vec<String>>, frame: u64, num_frames: u64, succes_rate: f64);
fn update_config_data(&mut self, data1: Option<Vec<String>>, data2: Option<Vec<String>>, data3: Option<Vec<String>>, data4: Option<Vec<String>>);
fn esc_operation(&mut self) -> ProcessResult;
fn quit_operation(&mut self) -> ProcessResult;
}
4 changes: 4 additions & 0 deletions blast_cli/src/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ impl BlastTab for WaitTab {
fn esc_operation(&mut self) -> ProcessResult {
ProcessResult::ExitPage
}

fn quit_operation(&mut self) -> ProcessResult {
ProcessResult::NoOp
}
}
7 changes: 5 additions & 2 deletions blast_core/src/blast_model_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,11 @@ impl BlastModelManager {
}
};

let mut c: Vec<String> = response.get_ref().channels.split(',').map(|s| s.trim().to_string()).collect();
chans.append(&mut c);
let chan_string = response.get_ref().channels.clone();
if chan_string != "" {
let mut c: Vec<String> = chan_string.split(',').map(|s| s.trim().to_string()).collect();
chans.append(&mut c);
}
}

chans
Expand Down
8 changes: 8 additions & 0 deletions blast_models/blast_lnd/blast_rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,15 @@ func (s *BlastRpcServer) CloseChannel(ctx context.Context, request *pb.BlastClos
return response, err_val
}

// Create a comma separated list of open channels that this model has control over
func (s *BlastRpcServer) GetModelChannels(ctx context.Context, request *pb.BlastGetModelChannelsRequest) (*pb.BlastGetModelChannelsResponse, error) {
if len(s.blast_lnd.open_channels) == 0 {
response := &pb.BlastGetModelChannelsResponse{
Channels: "",
}
return response, nil
}

var sb strings.Builder
for key, value := range s.blast_lnd.open_channels {
sb.WriteString(fmt.Sprintf("%s: %s -> %s,", key, value.Source, value.Dest))
Expand Down

0 comments on commit cfc1333

Please sign in to comment.