Skip to content

Commit

Permalink
Fix input multiple chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Sellig6792 committed Dec 31, 2022
1 parent 5bc82ef commit 22059f1
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/evaluation/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::ast::{InstructionTrait, InstructionType, PatternType};
use crate::evaluation::{Cell, Scopes};

pub struct Evaluator<T: InstructionTrait<T>>
where
T: Clone,
where
T: Clone,
{
program: Vec<T>,

Expand All @@ -17,8 +17,8 @@ where
}

impl<T: InstructionTrait<T> + 'static> Evaluator<T>
where
T: Clone,
where
T: Clone,
{
pub fn new(instructions: Vec<T>) -> Evaluator<T> {
Evaluator {
Expand Down Expand Up @@ -58,15 +58,17 @@ where
}

InstructionType::Input => {
if self.input.is_empty() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
// Convert the input to a vector of u8
self.input = input.trim().bytes().collect();
for _ in 0..instruction.get_amount() {
if self.input.is_empty() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
// Convert the input to a vector of u8
self.input = input.trim().bytes().collect();
}
self.scopes
.get_current_cell_mut()
.set_value(self.input.remove(0));
}
self.scopes
.get_current_cell_mut()
.set_value(self.input.remove(0));
}
InstructionType::Output => {
for _ in 0..instruction.get_amount() {
Expand Down

0 comments on commit 22059f1

Please sign in to comment.