aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main.rs48
1 files changed, 22 insertions, 26 deletions
diff --git a/src/main.rs b/src/main.rs
index 71408ae..bd9d00d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,10 +1,6 @@
-use rand::{thread_rng, Rng};
-use std::{
- io::{stdout, Read, Write},
- thread::sleep,
- time::Duration,
-};
-use termion::{async_stdin, raw::IntoRawMode, terminal_size};
+use rand::Rng as _;
+use std::io::{Read as _, Write as _};
+use termion::raw::IntoRawMode as _;
const N_FISH: usize = 64;
@@ -38,8 +34,8 @@ impl Turbofish {
}
}
-fn clear(mut stdout: impl Write) {
- write!(stdout, "{}", termion::clear::All).unwrap();
+fn clear(mut output: impl std::io::Write) {
+ write!(output, "{}", termion::clear::All).unwrap();
}
fn update(school_of_fish: &mut [Turbofish], columns: u16) {
@@ -51,15 +47,15 @@ fn update(school_of_fish: &mut [Turbofish], columns: u16) {
}
}
-fn render(mut stdout: impl Write, school_of_fish: &Vec<Turbofish>, columns: u16) {
+fn render(mut output: impl std::io::Write, school_of_fish: &Vec<Turbofish>, columns: u16) {
for fish in school_of_fish {
let x = fish.x;
let y = fish.y;
if fish.blink {
- write!(stdout, "{}", termion::color::Fg(termion::color::LightBlack)).unwrap();
+ write!(output, "{}", termion::color::Fg(termion::color::LightBlack)).unwrap();
}
write!(
- stdout,
+ output,
"{}{}{}",
termion::cursor::Goto(x.clamp(0, columns as i16 - 1) as u16 + 1, y + 1),
fish.text(if x < 0 {
@@ -76,12 +72,12 @@ fn render(mut stdout: impl Write, school_of_fish: &Vec<Turbofish>, columns: u16)
}
fn main() {
- let mut rng = thread_rng();
- let mut stdin = async_stdin().bytes();
- let mut stdout = stdout().into_raw_mode().unwrap();
- let mut stdout = termion::cursor::HideCursor::from(stdout);
+ let mut rng = rand::thread_rng();
+ let mut input = termion::async_stdin().bytes();
+ let output = std::io::stdout().into_raw_mode().unwrap();
+ let mut output = termion::cursor::HideCursor::from(output);
- let (columns, lines) = terminal_size().unwrap();
+ let (columns, lines) = termion::terminal_size().unwrap();
let mut school_of_fish = Vec::with_capacity(N_FISH);
for _i in 0..N_FISH {
@@ -96,22 +92,22 @@ fn main() {
});
}
- clear(&mut stdout);
- stdout.flush().unwrap();
+ clear(&mut output);
+ output.flush().unwrap();
loop {
- if let Some(Ok(b'q')) = stdin.next() {
+ if let Some(Ok(b'q')) = input.next() {
break;
}
- clear(&mut stdout);
+ clear(&mut output);
update(&mut school_of_fish, columns);
- render(&mut stdout, &school_of_fish, columns);
- stdout.flush().unwrap();
+ render(&mut output, &school_of_fish, columns);
+ output.flush().unwrap();
- sleep(Duration::from_millis(100));
+ std::thread::sleep(std::time::Duration::from_millis(100));
}
- clear(&mut stdout);
- stdout.flush().unwrap();
+ clear(&mut output);
+ output.flush().unwrap();
}