Last active
January 5, 2016 19:49
-
-
Save ihrwein/a4558d63d9250ee0bbf6 to your computer and use it in GitHub Desktop.
getch() in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
1. copy getch() into getch.c from here: http://stackoverflow.com/a/912796/3989982 | |
2. compile getch.c with: gcc -o libgetch.so -shared -fPIC getch.c | |
3. create getch.rs with the below content | |
4. compile getch.rs: rustc -L. getch.rs | |
5. run it: LD_LIBRARY_PATH=. ./getch | |
You can extract these steps into a build script (or someone can make a platform independent getch based on this) | |
*/ | |
#[link(name="getch")] | |
extern { | |
fn getch() -> u8; | |
} | |
fn main() { | |
println!("Type something!"); | |
loop { | |
unsafe { | |
println!("{:?}", getch()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment