X-Git-Url: http://nitlanguage.org diff --git a/lib/curses/curses.nit b/lib/curses/curses.nit index 11d5ab6..688493e 100644 --- a/lib/curses/curses.nit +++ b/lib/curses/curses.nit @@ -13,25 +13,52 @@ # limitations under the License. # Curses for Nit -module curses +module curses is pkgconfig("ncurses") + +in "C header" `{ + #include +`} # A curse windows -extern Window +extern class Window `{WINDOW *`} # Initialize the screen - new is extern "initscr" + new `{ + WINDOW *res; + res = initscr(); + if (res == NULL) { + fprintf(stderr, "Error initialising ncurses.\n"); + exit(EXIT_FAILURE); + } + raw(); + keypad(res, TRUE); + noecho(); + return res; + `} - # print a string somewhere + # Move the cursor at the position (y,x) and print a string # NOTE: as with the curses API, the position is (y,x) - fun mvaddstr(y,x: Int, str: String) is extern import String::to_cstring + fun mvaddstr(y,x: Int, str: String) import String.to_cstring `{ + char *c_string = String_to_cstring( str ); + mvaddstr(y, x, c_string); + `} - fun refresh is extern - fun wclear is extern - fun delwin is extern - fun endwin is extern -end + # Update the window + fun refresh `{ + refresh(); + `} + + # Clear the entire window so it can be repainted from scratch with a refresh + fun wclear `{ + wclear(self); + `} + + # Delete the window + fun delwin `{ + delwin(self); + `} -redef class Stdin - # Is these something to read? (non blocking) - # FIXME: should not be in the curses module - fun poll_in: Bool is extern + # Suspend the curses session and restore the previous terminal + fun endwin `{ + endwin(); + `} end