extern crate termion; use termion::event::Key; use termion::input::TermRead; use termion::raw::IntoRawMode; use termion::screen::AlternateScreen; use std::io::{self, Write}; use std::thread; use std::time::Duration; static SNEK: &'static [u8] = include_bytes!("snek.six"); fn main() { let input = termion::async_stdin(); let mut keys = input.keys(); let mut output = io::stdout().into_raw_mode().unwrap(); let mut screen = Vec::new(); let mut size = termion::terminal_size().expect("Can't get terminal size"); write!(screen, "{}", termion::clear::All); loop { let new_size = termion::terminal_size().unwrap(); if new_size != size { write!(screen, "{}", termion::clear::All); size = new_size; } write!(screen, "{}", termion::cursor::Goto(20, 20)); screen.write_all(SNEK).expect("Can't write snek"); match keys.next() { Some(Ok(Key::Char('q'))) => break, Some(k) => println!("{:?}", k), None => () } output.write_all(&screen).expect("Can't write screen"); screen.clear(); thread::sleep(Duration::from_millis(16)); } }