Skip to content

Instantly share code, notes, and snippets.

@benaryorg
Last active October 4, 2015 10:38
Show Gist options
  • Save benaryorg/fd48a5907b2df3ef2650 to your computer and use it in GitHub Desktop.
Save benaryorg/fd48a5907b2df3ef2650 to your computer and use it in GitHub Desktop.
extern crate rustbox;
use rustbox::{Color,RustBox,Key};
use rustbox::Event::*;
fn main()
{
let term = RustBox::init(std::default::Default::default()).unwrap();
term.print(1,1,rustbox::RB_BOLD,Color::White,Color::Default,"Hello, world!");
let (mut x,mut y) = (0,3);
loop
{
term.present();
if let Ok(event) = term.poll_event(false)
{
match event
{
KeyEvent(Key::Esc) => break,
KeyEvent(Key::Backspace)|KeyEvent(Key::Ctrl('h')) =>
{
if x > 0
{
x -= 1;
term.print(x,y,rustbox::RB_NORMAL,Color::Green,Color::Default," ");
}
}
KeyEvent(Key::Enter) =>
{
y += 1;
x = 0;
}
KeyEvent(Key::Char(key)) =>
{
term.print(x,y,rustbox::RB_NORMAL,Color::Green,Color::Blue,&format!("{}",key));
x += 1;
},
_ => {},
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment