diff options
| -rw-r--r-- | src/chip8.rs | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/chip8.rs b/src/chip8.rs index eacc1e3..c1f78b7 100644 --- a/src/chip8.rs +++ b/src/chip8.rs @@ -135,24 +135,21 @@ impl Chip8 { } fn draw(&self) -> std::io::Result<()> { - let lines: String = std::iter::once("\x1B[2J\n") - .chain((0..HEIGHT).flat_map(|y| { - (0..WIDTH) - .map(move |x| { - let si = x + y * WIDTH; - if self.screen[si as usize] == 0 { - "░" - } else { - "█" - } - }) - .chain(std::iter::once("\n")) - })) - .collect(); - let stdout = std::io::stdout(); let mut handle = stdout.lock(); - handle.write_all(lines.as_bytes())?; + handle.write_all(b"\x1B[2J\n")?; + for y in 0..HEIGHT { + for x in 0..WIDTH { + let si = x + y * WIDTH; + let buf = if self.screen[si as usize] == 0 { + "░".as_bytes() + } else { + "█".as_bytes() + }; + handle.write_all(buf)?; + } + handle.write_all(b"\n")?; + } handle.flush() } } |
