Skip to content

Commit 4488a2f

Browse files
committed
Mostly Ready
1 parent 92711e8 commit 4488a2f

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

perf.data

-576 KB
Binary file not shown.

perf.data.old

-329 KB
Binary file not shown.

src/main.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use libc::{fcntl, F_GETFL, F_SETFL, O_NONBLOCK};
66
use std::io::Stdout;
77
use std::io::{stdout, Read, Write};
88
use std::os::unix::io::AsRawFd;
9-
use std::sync::mpsc;
10-
use std::thread;
119
use termion::clear;
1210
use termion::cursor;
1311
use termion::cursor::{Goto, Hide, Show};
@@ -16,7 +14,6 @@ use termion::style;
1614
use termion::terminal_size;
1715

1816
fn main() {
19-
let mut stdin = std::io::stdin();
2017
let mut stdout = std::io::stdout().into_raw_mode().unwrap();
2118
write!(stdout, "{}", termion::cursor::Hide).unwrap();
2219

@@ -37,24 +34,16 @@ fn main() {
3734
let mut buffer = [0u8; 1];
3835

3936
let mut on = false;
40-
let read_char_time = 100;
41-
let mut read_char_timer = 0;
42-
let mut read_char = true;
37+
4338
world.randomize();
4439
home(width, height, &mut stdout);
4540
loop {
46-
read_char_timer -= 1;
47-
if read_char_timer <= 0 {
48-
read_char = true;
49-
read_char_timer = read_char_time;
50-
}
51-
if read_char {
52-
match std::io::stdin().read(&mut buffer) {
53-
Ok(0) => {
54-
// std::thread::sleep(std::time::Duration::from_millis(100));
55-
}
56-
Ok(_) => {
57-
match buffer[0] {
41+
match std::io::stdin().read(&mut buffer) {
42+
Ok(0) => {
43+
// std::thread::sleep(std::time::Duration::from_millis(100));
44+
}
45+
Ok(_) => {
46+
match buffer[0] {
5847
b'q' => break, // Exit the loop when 'q' is pressed.
5948
b'r' => world.randomize(), // Randomize the world when 'r' is pressed
6049
b' ' => on = !on, // Start/stop the world when 's' is pressed
@@ -64,21 +53,19 @@ fn main() {
6453
, // Home screen when 'h' is pressed
6554
_ => {} // Ignore other inputs
6655
}
67-
}
68-
Err(e) => {
69-
// eprintln!("Error reading from stdin: {}", e);
70-
// std::thread::sleep(std::time::Duration::from_millis(100));
71-
}
56+
}
57+
Err(e) => {
58+
// eprintln!("Error reading from stdin: {}", e);
59+
// std::thread::sleep(std::time::Duration::from_millis(100));
7260
}
7361
}
74-
7562
// when user presses q, exit the loop
7663
if on {
7764
world.next_generation();
7865
write!(stdout, "{}{}", clear::All, world).unwrap();
7966
stdout.flush().unwrap();
80-
std::thread::sleep(std::time::Duration::from_millis(100));
8167
}
68+
std::thread::sleep(std::time::Duration::from_millis(100));
8269
}
8370
quit(stdout);
8471
}

0 commit comments

Comments
 (0)