diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-03-20 21:58:37 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-03-20 21:58:37 -0500 |
commit | 8192a07c2696b7313dd509a7e474ff7fc79d9bdb (patch) | |
tree | 0c6eaa1b69b2e0348f3485ae08e2e3b9bbf1aad1 /test/rl.rs | |
parent | d00c8ec76c498196be8bfe2d58f27697bda9de69 (diff) | |
download | rust-term-8192a07c2696b7313dd509a7e474ff7fc79d9bdb.tar.gz rust-term-8192a07c2696b7313dd509a7e474ff7fc79d9bdb.zip |
implement a bit more in the test
Diffstat (limited to 'test/rl.rs')
-rw-r--r-- | test/rl.rs | 52 |
1 files changed, 44 insertions, 8 deletions
@@ -1,18 +1,54 @@ extern mod term; use core::io::ReaderUtil; -fn main () { +fn term_app (body: &fn ()) { term::info::init(); - let (rows, cols) = term::ios::size(); do term::ios::preserve { - term::ios::cbreak(); do term::info::with_alternate_screen { - term::info::clear(); - for uint::range(0, rows) |i| { - term::info::move(0, i); - io::print(str::repeat(".", cols)); + body() + } + } +} + +fn draw_map (rows: uint, cols: uint) { + for uint::range(0, rows) |i| { + term::info::move(0, i); + io::print(str::repeat(".", cols)); + } +} + +fn draw_character (x: uint, y: uint) { + term::info::move(x, y); + io::print("@"); + term::info::move(x, y); +} + +fn draw_ground (x: uint, y: uint) { + term::info::move(x, y); + io::print("."); +} + +fn main () { + let (rows, cols) = term::ios::size(); + + do term_app { + term::ios::cbreak(); + term::ios::echo(false); + term::info::clear(); + + draw_map(rows, cols); + + let mut (x, y) = (0u, 0u); + loop { + draw_character(x, y); + match io::stdin().read_char() { + 'q' => { break } + 'h' if x > 0 => { draw_ground(x, y); x -= 1 } + 'j' if y < rows - 1 => { draw_ground(x, y); y += 1 } + 'k' if y > 0 => { draw_ground(x, y); y -= 1 } + 'l' if x < cols - 1 => { draw_ground(x, y); x += 1 } + _ => { } } - io::stdin().read_char(); } } } |