2016-07-23 15:40:27 +01:00
|
|
|
extern crate termion;
|
|
|
|
|
2016-07-23 17:50:33 +01:00
|
|
|
use termion::event::Key;
|
|
|
|
use termion::input::TermRead;
|
2016-07-23 15:40:27 +01:00
|
|
|
use termion::raw::IntoRawMode;
|
|
|
|
use std::io::{Write, stdout, stdin};
|
|
|
|
|
|
|
|
fn rainbow<W: Write>(stdout: &mut W, blue: u8) {
|
2017-03-24 20:53:05 +00:00
|
|
|
write!(stdout,
|
|
|
|
"{}{}",
|
|
|
|
termion::cursor::Goto(1, 1),
|
|
|
|
termion::clear::All)
|
|
|
|
.unwrap();
|
2016-07-23 15:40:27 +01:00
|
|
|
|
2016-12-19 15:45:11 +00:00
|
|
|
for red in 0..32 {
|
|
|
|
let red = red * 8;
|
|
|
|
for green in 0..64 {
|
|
|
|
let green = green * 4;
|
2017-03-24 20:53:05 +00:00
|
|
|
write!(stdout,
|
|
|
|
"{} ",
|
|
|
|
termion::color::Bg(termion::color::Rgb(red, green, blue)))
|
|
|
|
.unwrap();
|
2016-07-23 15:40:27 +01:00
|
|
|
}
|
|
|
|
write!(stdout, "\n\r").unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
writeln!(stdout, "{}b = {}", termion::style::Reset, blue).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let stdin = stdin();
|
|
|
|
let mut stdout = stdout().into_raw_mode().unwrap();
|
|
|
|
|
2017-03-24 20:53:05 +00:00
|
|
|
writeln!(stdout,
|
|
|
|
"{}{}{}Use the up/down arrow keys to change the blue in the rainbow.",
|
|
|
|
termion::clear::All,
|
|
|
|
termion::cursor::Goto(1, 1),
|
|
|
|
termion::cursor::Hide)
|
|
|
|
.unwrap();
|
2016-07-23 15:40:27 +01:00
|
|
|
|
2016-07-23 16:32:08 +01:00
|
|
|
let mut blue = 172u8;
|
2016-07-23 15:40:27 +01:00
|
|
|
|
|
|
|
for c in stdin.keys() {
|
|
|
|
match c.unwrap() {
|
|
|
|
Key::Up => {
|
|
|
|
blue = blue.saturating_add(4);
|
|
|
|
rainbow(&mut stdout, blue);
|
2017-03-24 20:53:05 +00:00
|
|
|
}
|
2016-07-23 15:40:27 +01:00
|
|
|
Key::Down => {
|
|
|
|
blue = blue.saturating_sub(4);
|
|
|
|
rainbow(&mut stdout, blue);
|
2017-03-24 20:53:05 +00:00
|
|
|
}
|
2016-07-23 15:40:27 +01:00
|
|
|
Key::Char('q') => break,
|
2017-03-24 20:53:05 +00:00
|
|
|
_ => {}
|
2016-07-23 15:40:27 +01:00
|
|
|
}
|
|
|
|
stdout.flush().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
write!(stdout, "{}", termion::cursor::Show).unwrap();
|
|
|
|
}
|