diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-03-21 01:14:23 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-03-21 01:14:23 -0500 |
commit | 50db2cec5f96d2f26ab5363a1beb870ed6482abc (patch) | |
tree | 3e3668fcdf96ead4e06dbf176b6b2a17bd5175de /test/rl.rs | |
parent | 0896e60afd21c9c6724fb06c6328bb890c4f911d (diff) | |
download | rust-term-50db2cec5f96d2f26ab5363a1beb870ed6482abc.tar.gz rust-term-50db2cec5f96d2f26ab5363a1beb870ed6482abc.zip |
turn this into an object
Diffstat (limited to 'test/rl.rs')
-rw-r--r-- | test/rl.rs | 41 |
1 files changed, 20 insertions, 21 deletions
@@ -1,54 +1,53 @@ extern mod term; use core::io::ReaderUtil; -fn term_app (body: &fn ()) { - term::info::init(); +fn term_app (body: &fn (w: &mut term::Writer)) { + let mut writer = term::Writer(true); do term::ios::preserve { - do term::info::with_alternate_screen { - body() - } + writer.alternate_screen(true); + body(&mut writer); } } -fn draw_map (rows: uint, cols: uint) { +fn draw_map (w: &term::Writer, rows: uint, cols: uint) { for uint::range(0, rows) |i| { - term::info::move(0, i); + w.move(0, i); io::print(str::repeat(".", cols)); } } -fn draw_character (x: uint, y: uint) { - term::info::move(x, y); +fn draw_character (w: &term::Writer, x: uint, y: uint) { + w.move(x, y); io::print("@"); - term::info::move(x, y); + w.move(x, y); } -fn draw_ground (x: uint, y: uint) { - term::info::move(x, y); +fn draw_ground (w: &term::Writer, x: uint, y: uint) { + w.move(x, y); io::print("."); } fn main () { let (cols, rows) = term::size(); - do term_app { + do term_app |w| { term::cbreak(); term::echo(false); - term::info::clear(); + w.clear(); - draw_map(rows, cols); + draw_map(w, rows, cols); let mut (x, y) = (0u, 0u); let mut cursor = true; loop { - draw_character(x, y); + draw_character(w, 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 } - ' ' => { term::info::cursor(cursor); cursor = !cursor } + 'h' if x > 0 => { draw_ground(w, x, y); x -= 1 } + 'j' if y < rows - 1 => { draw_ground(w, x, y); y += 1 } + 'k' if y > 0 => { draw_ground(w, x, y); y -= 1 } + 'l' if x < cols - 1 => { draw_ground(w, x, y); x += 1 } + ' ' => { w.cursor(cursor); cursor = !cursor } _ => { } } } |