Skip to content

Instantly share code, notes, and snippets.

@eevee
Created August 14, 2012 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eevee/3346875 to your computer and use it in GitHub Desktop.
Save eevee/3346875 to your computer and use it in GitHub Desktop.
ncurses hello world
use std;
import libc::types::common::c95::c_void;
import libc::types::os::arch::c95::c_char;
import libc::types::os::arch::c95::c_int;
type SCREEN = c_void;
type WINDOW = c_void;
extern mod ncurses {
fn initscr() -> *WINDOW;
fn printw(fmt: *c_char) -> c_int;
fn refresh() -> c_int;
fn getch() -> c_int;
fn endwin() -> c_int;
}
class window {
let window : *WINDOW;
new() {
self.window = ncurses::initscr();
}
fn printw(msg: str) {
do str::as_c_str(msg) |bytes| {
ncurses::printw(bytes);
};
}
fn refresh() {
ncurses::refresh();
}
fn getch() -> char {
ret ncurses::getch() as char;
}
drop {
ncurses::endwin();
io::println("done");
}
}
fn main(args: ~[str]) {
let win: window = window();
win.printw("hello world");
win.refresh();
let n: char = win.getch();
io::println(str::from_char(n));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment