-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconsole.rs
35 lines (35 loc) · 1.19 KB
/
console.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright © 2016, Peter Atashian
// Licensed under the MIT License <LICENSE.md>
extern crate rand;
extern crate wio;
use std::mem::swap;
use wio::console::{CharInfo, Input, InputBuffer, ScreenBuffer};
fn main() {
let stdin = InputBuffer::from_conin().unwrap();
let mut backbuf = ScreenBuffer::new().unwrap();
let mut frontbuf = ScreenBuffer::new().unwrap();
loop {
if stdin.available_input().unwrap() > 0 {
let input = stdin.read_input().unwrap();
for i in input {
if let Input::Key { key_code, .. } = i {
if key_code == 0x1B {
return;
}
}
}
}
let info = backbuf.info().unwrap();
let size = info.size();
let buf: Vec<_> = (0..(size.0 * size.1))
.map(|_| {
let ch = (rand::random::<u8>() % 26) + 0x41;
let color = rand::random::<u16>() & 0xff;
CharInfo::new(ch as u16, color)
})
.collect();
backbuf.write_output(&buf, size, (0, 0)).unwrap();
swap(&mut backbuf, &mut frontbuf);
frontbuf.set_active().unwrap();
}
}