nitweb: fix access to query results count
[nit.git] / lib / curses / curses.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Curses for Nit
16 module curses is pkgconfig("ncurses")
17
18 in "C header" `{
19 #include <ncurses.h>
20 `}
21
22 # A curse windows
23 extern class Window `{WINDOW *`}
24 # Initialize the screen
25 new `{
26 WINDOW *res;
27 res = initscr();
28 if (res == NULL) {
29 fprintf(stderr, "Error initialising ncurses.\n");
30 exit(EXIT_FAILURE);
31 }
32 raw();
33 keypad(res, TRUE);
34 noecho();
35 return res;
36 `}
37
38 # Move the cursor at the position (y,x) and print a string
39 # NOTE: as with the curses API, the position is (y,x)
40 fun mvaddstr(y,x: Int, str: String) import String.to_cstring `{
41 char *c_string = String_to_cstring( str );
42 mvaddstr(y, x, c_string);
43 `}
44
45 # Update the window
46 fun refresh `{
47 refresh();
48 `}
49
50 # Clear the entire window so it can be repainted from scratch with a refresh
51 fun wclear `{
52 wclear(self);
53 `}
54
55 # Delete the window
56 fun delwin `{
57 delwin(self);
58 `}
59
60 # Suspend the curses session and restore the previous terminal
61 fun endwin `{
62 endwin();
63 `}
64 end