9 #include "ncurses-console.h"
11 extern int setupterm(char* term
, int fildes
, int* errret
);
13 // this is a copy paste from boot.c
15 error (const char * message
, ...)
19 va_start (args
, message
);
20 fprintf (stderr
, "Slate: ");
21 vfprintf (stderr
, message
, args
);
32 if (setupterm((char *)0, 1, &err
) == ERR
)
35 return tigetstr("cup") != NULL
;
39 sc_enterStructuredMode ()
41 if (initscr() == NULL
)
46 scrollok(stdscr
, TRUE
);
47 immedok(stdscr
, FALSE
);
48 leaveok(stdscr
, FALSE
);
51 intrflush(stdscr
, FALSE
);
52 keypad(stdscr
, FALSE
);
54 notimeout(stdscr
, FALSE
);
64 sc_leaveStructuredMode ()
66 return (endwin() != ERR
);
69 // TODO: this assumes string = byte array vm setup
71 sc_keySequenceOf(char *keyName
)
73 char *keySequence
= tigetstr(keyName
);
74 if ((int)keySequence
== -1 || (int)keySequence
== 0)
77 if (strlen(keySequence
) > 1 && keySequence
[0] == 27)
87 getmaxyx(stdscr
, lines
, cols
);
96 getmaxyx(stdscr
, rows
, cols
);
102 sc_write (void *bytes
, int size
, int offset
)
104 return (waddnstr(stdscr
, ((const char *)bytes
) + offset
, size
) != ERR
);
108 sc_scroll (int lines
)
110 return (wscrl(stdscr
, lines
) != ERR
);
116 return (wclear(stdscr
) != ERR
);
122 return (wclrtobot(stdscr
) != ERR
);
128 return (wclrtoeol(stdscr
) != ERR
);
132 sc_moveToXY (int x
, int y
)
134 return (wmove(stdscr
, y
, x
) != ERR
);
154 sc_nextEvent (int blockingMillisecs
)
158 wtimeout(stdscr
, blockingMillisecs
);
162 if (blockingMillisecs
< 0)
163 error("Error reading console?!");
191 return (wrefresh(stdscr
) != ERR
);
197 return (wdelch(stdscr
) != ERR
);
201 sc_deleteLines(int lines
)
203 return (winsdelln(stdscr
, -lines
) != ERR
);
207 sc_insertLines(int lines
)
209 return (winsdelln(stdscr
, lines
) != ERR
);
225 sc_initColorPair(int pair
, int fg
, int bg
)
227 return (init_pair(pair
, fg
, bg
) != ERR
);
237 sc_setAttributes(int mode
, int pair
)
239 wattrset(stdscr
, (mode
<< 16) | COLOR_PAIR(pair
));
244 sc_setColor(int foreground, int background)
247 init_pair(color, foreground, background);
249 wcolor_set(stdscr, color, NULL);
253 sc_turnOnAttribute(int attribute)
255 wattron(stdscr, attribute);
259 sc_turnOffAttribute(int attribute)
261 wattr_off(stdscr, attribute);