Created
August 14, 2012 06:21
-
-
Save eevee/3346875 to your computer and use it in GitHub Desktop.
ncurses hello world
This file contains 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
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