Skip to content

Commit

Permalink
fixed bug with step x input
Browse files Browse the repository at this point in the history
  • Loading branch information
Jadens-arc committed Mar 15, 2024
1 parent 4817c4c commit 579b09b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ironmind"
version = "0.3.15"
version = "0.3.16"
edition = "2021"
authors = ["Jaden Arceneaux <[email protected]>"]
description = "A Brainf*ck interpreter and code execution visualizer built in Rust"
Expand Down
2 changes: 1 addition & 1 deletion snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ironmind # you probably want to 'snapcraft register <name>'
base: core22 # the base snap is the execution environment for this snap
version: '0.3.15' # just for humans, typically '1.2+git' or '1.3.2'
version: '0.3.16' # just for humans, typically '1.2+git' or '1.3.2'
summary: Brainf*ck interpreter and code execution visualizer # 79 char long summary
description: |
Built in Rust.
Expand Down
26 changes: 16 additions & 10 deletions src/visualize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ fn update_display(cursive: &mut Cursive) {
}

/// Prompt user to input character and set current cell to the value of that character
fn get_input(cursive: &mut Cursive) {
fn get_input(cursive: &mut Cursive, remaining: i32) {
cursive.add_layer(
Dialog::around(
LinearLayout::vertical()
.child(TextView::new("What character do you want to input?"))
.child(EditView::new().on_submit(|cursive, char| {
.child(EditView::new().on_submit(move |cursive, char| {
cursive.pop_layer();
if let Some(data) = cursive.user_data::<Parser>() {
if let Some(user_char) = char.chars().nth(0) {
data.set_current_cell(user_char as u8);
step(cursive, 0, remaining.clone());
} else {
get_input(cursive);
get_input(cursive, remaining);
}
}
update_display(cursive);
Expand All @@ -51,7 +52,10 @@ fn get_input(cursive: &mut Cursive) {
}

/// Iterate program to next instruction and update TUI
fn step(cursive: &mut Cursive) {
fn step(cursive: &mut Cursive, cur: i32, target: i32) {
if cur == target {
return;
}
let mut exit_type = ParserExit::None;

match cursive.user_data::<Parser>() {
Expand All @@ -67,19 +71,19 @@ fn step(cursive: &mut Cursive) {
None => { return; }
};

update_display(cursive);
if exit_type == ParserExit::InputNeeded {
get_input(cursive);
get_input(cursive, target - cur);
} else {
step(cursive, cur + 1, target)
}

update_display(cursive);
}

fn handle_count_submit(cursive: &mut Cursive, count: &str) {
cursive.pop_layer();
if let Ok(count) = String::from(count).parse::<i32>() {
for _ in 0.. count {
step(cursive);
}
step(cursive, 0, count);
return;
}
cursive.add_layer(
Expand Down Expand Up @@ -115,7 +119,9 @@ pub fn visualize (parser: Parser) {
cursive.quit();
}
))
.child(Button::new("Step One", step))
.child(Button::new("Step One", |cursive| {
step(cursive, 0, 1);
}))
.child(Button::new("Step X", step_x));

let main = LinearLayout::vertical()
Expand Down

0 comments on commit 579b09b

Please sign in to comment.