add curses.c WINDOW init funcs
This commit is contained in:
parent
a55c25d319
commit
4d7402fa52
2 changed files with 34 additions and 19 deletions
40
cli/curse.c
40
cli/curse.c
|
|
@ -9,15 +9,15 @@
|
||||||
/* Set ncurses terminal mode (buffering, character processing,
|
/* Set ncurses terminal mode (buffering, character processing,
|
||||||
* Key->SIG handling, and other termios(3) functionality).
|
* Key->SIG handling, and other termios(3) functionality).
|
||||||
*/
|
*/
|
||||||
inline int termmode(enum crs_mode mode) {
|
inline int termmode(enum crs_termmode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case WMODE_CBREAK:
|
case TMODE_CBREAK:
|
||||||
return cbreak();
|
return cbreak();
|
||||||
case WMODE_RAW:
|
case TMODE_RAW:
|
||||||
return raw();
|
return raw();
|
||||||
case WMODE_NOCBREAK:
|
case TMODE_NOCBREAK:
|
||||||
return nocbreak();
|
return nocbreak();
|
||||||
case WMODE_NORAW:
|
case TMODE_NORAW:
|
||||||
return noraw();
|
return noraw();
|
||||||
/* defaulting is not possible. */
|
/* defaulting is not possible. */
|
||||||
}
|
}
|
||||||
|
|
@ -34,28 +34,42 @@ inline void init_ncurses(void) {
|
||||||
start_color();
|
start_color();
|
||||||
|
|
||||||
/* Screen Configuration */
|
/* Screen Configuration */
|
||||||
termmode(WMODE_CBREAK);
|
termmode(TMODE_CBREAK);
|
||||||
noecho(); // manually echo <- getch(3x)
|
noecho(); // manually echo from getch(3x)
|
||||||
|
|
||||||
curs_set(0); // hide cursor
|
curs_set(0); // hide cursor
|
||||||
|
|
||||||
// init_pair(1, COLOR_BLACK, COLOR_CYAN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WINDOW *init_window(int x, int y, int width, int height) {
|
/* Apply a default IO configuration for an ncurses WINDOW.
|
||||||
WINDOW *win = newwin(height, width, y, x);
|
*/
|
||||||
|
static inline void __conf_window(WINDOW *win) {
|
||||||
nodelay(win, TRUE); // getch(3x) nonblocking IO
|
nodelay(win, TRUE); // getch(3x) nonblocking IO
|
||||||
keypad(win, TRUE); // allow function keys
|
keypad(win, TRUE); // allow function keys
|
||||||
// intrflush(3x) - flush terminal input buffer on interrupt key
|
// intrflush(3x) - flush terminal input buffer on interrupt key
|
||||||
intrflush(win, FALSE);
|
intrflush(win, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialise (with default IO configuration) a new ncruses WINDOW.
|
||||||
|
*/
|
||||||
|
WINDOW *new_window(int x, int y, int width, int height) {
|
||||||
|
WINDOW *win = newwin(height, width, y, x);
|
||||||
|
__conf_window(win);
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Initialise (with default IO configuration) the root ncurses WINDOW.
|
||||||
|
* NOTE: This is typically done via initscr(3x) and called "stdscr".
|
||||||
|
*/
|
||||||
|
inline WINDOW *root_window(void) {
|
||||||
|
WINDOW *rootwin = new_window(0, 0, 0, 0);
|
||||||
|
__conf_window(rootwin);
|
||||||
|
return rootwin;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
init_ncurses();
|
init_ncurses();
|
||||||
WINDOW *stdscr = init_window(0, 0, 0, 0);
|
WINDOW *stdscr = new_window(0, 0, 0, 0);
|
||||||
|
|
||||||
// Set background
|
// Set background
|
||||||
wbkgd(stdscr, COLOR_PAIR(1));
|
wbkgd(stdscr, COLOR_PAIR(1));
|
||||||
|
|
|
||||||
13
cli/curse.h
13
cli/curse.h
|
|
@ -4,19 +4,20 @@
|
||||||
/* libncurses with wide-character support. */
|
/* libncurses with wide-character support. */
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
|
|
||||||
enum crs_mode {
|
enum crs_termmode {
|
||||||
/* tty cbreak mode */
|
/* tty cbreak mode */
|
||||||
WMODE_CBREAK,
|
TMODE_CBREAK,
|
||||||
/* tty raw mode */
|
/* tty raw mode */
|
||||||
WMODE_RAW,
|
TMODE_RAW,
|
||||||
/* tty cooked mode (ISIG & IXON not modified)*/
|
/* tty cooked mode (ISIG & IXON not modified)*/
|
||||||
WMODE_NOCBREAK,
|
TMODE_NOCBREAK,
|
||||||
/* tty cooked mode (ISIG & IXON set) */
|
/* tty cooked mode (ISIG & IXON set) */
|
||||||
WMODE_NORAW,
|
TMODE_NORAW,
|
||||||
};
|
};
|
||||||
|
|
||||||
int termmode(enum crs_mode mode);
|
int termmode(enum crs_termmode mode);
|
||||||
void init_ncurses(void);
|
void init_ncurses(void);
|
||||||
WINDOW *init_window(int x, int y, int width, int height);
|
WINDOW *init_window(int x, int y, int width, int height);
|
||||||
|
WINDOW *root_window(void);
|
||||||
|
|
||||||
#endif /* DORNE_CURSE_H */
|
#endif /* DORNE_CURSE_H */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue