1 #ifndef __SYS_WIN_H__ 2 #define __SYS_WIN_H__ 3 4 typedef struct SWINDOW SWINDOW; 5 typedef unsigned long SWIN_CHTYPE; 6 7 /* From the ncurses doupdate() man page: 8 * 9 * The wnoutrefresh and doupdate routines allow multiple updates with more 10 * efficiency than wrefresh alone. In addition to all the window structures, 11 * curses keeps two data structures representing the terminal screen: a 12 * physical screen, describing what is actually on the screen, and a virtual 13 * screen, describing what the programmer wants to have on the screen. 14 * 15 * The routine wrefresh works by first calling wnoutrefresh, which copies the 16 * named window to the virtual screen, and then calling doupdate, which 17 * compares the virtual screen to the physical screen and does the actual 18 * update. If the programmer wishes to output several windows at once, a 19 * series of calls to wrefresh results in alternating calls to wnoutrefresh 20 * and doupdate, causing several bursts of output to the screen. By first 21 * calling wnoutrefresh for each window, it is then possible to call doupdate 22 * once, resulting in only one burst of output, with fewer total characters 23 * transmitted and less CPU time used. 24 * 25 * So we use the win_refresh option to tell the routine whether to use 26 * wrefresh() or wnoutrefresh(). This eliminates quite a bit of flashing as 27 * well. 28 */ 29 enum win_refresh { 30 /* Tells CGDB to use wnoutrefresh */ 31 WIN_NO_REFRESH, 32 /* Tells CGDB to use wrefresh */ 33 WIN_REFRESH 34 }; 35 36 37 #define COLOR_BLACK 0 38 #define COLOR_RED 1 39 #define COLOR_GREEN 2 40 #define COLOR_YELLOW 3 41 #define COLOR_BLUE 4 42 #define COLOR_MAGENTA 5 43 #define COLOR_CYAN 6 44 #define COLOR_WHITE 7 45 46 /* attributes */ 47 extern const int SWIN_A_NORMAL; 48 extern const int SWIN_A_STANDOUT; 49 extern const int SWIN_A_UNDERLINE; 50 extern const int SWIN_A_REVERSE; 51 extern const int SWIN_A_BLINK; 52 extern const int SWIN_A_DIM; 53 extern const int SWIN_A_BOLD; 54 55 extern const int SWIN_KEY_BACKSPACE; /* backspace key */ 56 57 extern SWIN_CHTYPE SWIN_SYM_VLINE; /* vertical line */ 58 extern SWIN_CHTYPE SWIN_SYM_HLINE; /* horizontal line */ 59 extern SWIN_CHTYPE SWIN_SYM_LTEE; /* tee pointing right */ 60 61 /** 62 * Initialize the system window. 63 * 64 * @return 65 * True if successful, otherwise False. On failure, logging will occur. 66 */ 67 bool swin_start(); 68 69 /* Determines the terminal type and initializes all data structures. */ 70 SWINDOW *swin_initscr(); 71 /* The program must call endwin for each terminal being used before exiting. */ 72 int swin_endwin(); 73 74 int swin_lines(); /* height of screen */ 75 int swin_cols(); /* width of screen */ 76 int swin_colors(); /* number of colors supported */ 77 int swin_color_pairs(); /* number of color pairs supported */ 78 79 int swin_has_colors(); 80 int swin_start_color(); 81 int swin_use_default_colors(); 82 83 /** 84 * Determine if ncurses supports the default color pairs extensions. 85 * 86 * Newer versions of ncurses support COLOR_PAIRS (ie. 64) pairs, but also 87 * support ladditional color pairs (ie. 16) for using the default background. 88 * According to the init_pair documentation, 89 * The value of the first argument must be between 1 and COLOR_PAIRS-1, 90 * except that if default colors are used (see use_default_colors) the 91 * upper limit is adjusted to allow for extra pairs which use a default 92 * color in foreground and/or background. 93 * 94 * @return 95 * True if init_pair supports the ncurses extension, False otherwise. 96 */ 97 bool swin_supports_default_color_pairs_extension(); 98 99 /* Resizes the standard and current windows to the specified dimensions, and 100 adjusts other bookkeeping data used by the ncurses library that record the 101 window dimensions such as the LINES and COLS variables. */ 102 int swin_resizeterm(int lines, int columns); 103 104 SWINDOW *swin_newwin(int nlines, int ncols, int begin_y, int begin_x); 105 int swin_delwin(SWINDOW *win); 106 107 /* Scroll window up n lines */ 108 int swin_scrl(int n); 109 110 /* The keypad option enables the keypad of the user's terminal. If enabled 111 the user can press a function key (such as an arrow key) and wgetch returns 112 a single value representing the function key, as in KEY_LEFT. If disabled 113 curses does not treat function keys specially and the program has to 114 interpret the escape sequences itself. */ 115 int swin_keypad(SWINDOW *win, int bf); 116 117 /* Get terminfo value capname capability */ 118 char *swin_tigetstr(const char *capname); 119 120 /* Move cursor */ 121 int swin_move(int y, int x); 122 int swin_wmove(SWINDOW *win, int y, int x); 123 124 /* Set cursor state */ 125 int swin_curs_set(int visibility); 126 127 /* Turns on/off named attributes */ 128 int swin_wattron(SWINDOW *win, int attrs); 129 int swin_wattroff(SWINDOW *win, int attrs); 130 131 int swin_getcurx(const SWINDOW *win); 132 int swin_getcury(const SWINDOW *win); 133 134 int swin_getbegx(const SWINDOW *win); 135 int swin_getbegy(const SWINDOW *win); 136 int swin_getmaxx(const SWINDOW *win); 137 int swin_getmaxy(const SWINDOW *win); 138 139 /* Copy blanks to every position in the window */ 140 int swin_werase(SWINDOW *win); 141 142 /* Draw a vertical (top to bottom) line using ch starting at the current cursor 143 position in the window. The current cursor position is not changed. The line is 144 at most n characters long, or as many as fit into the window. */ 145 int swin_wvline(SWINDOW *win, SWIN_CHTYPE ch, int n); 146 /* Draw ch and advance cursor */ 147 int swin_waddch(SWINDOW *win, const SWIN_CHTYPE ch); 148 /* Erase the current line to the right of the cursor, inclusive, to the end of the 149 current line. */ 150 int swin_wclrtoeol(SWINDOW *win); 151 152 int swin_waddnstr(SWINDOW *win, const char *str, int n); 153 int swin_wprintw(SWINDOW *win, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); 154 int swin_mvwprintw(SWINDOW *win, int y, int x, const char *fmt, ...) ATTRIBUTE_PRINTF(4, 5); 155 156 /* From the ncurses doupdate() man page: 157 * 158 * The routine wrefresh works by first calling wnoutrefresh, which copies the 159 * named window to the virtual screen, and then calling doupdate, which 160 * compares the virtual screen to the physical screen and does the actual 161 * update. If the programmer wishes to output several windows at once, a 162 * series of calls to wrefresh results in alternating calls to wnoutrefresh 163 * and doupdate, causing several bursts of output to the screen. By first 164 * calling wnoutrefresh for each window, it is then possible to call doupdate 165 * once, resulting in only one burst of output, with fewer total characters 166 * transmitted and less CPU time used. 167 */ 168 int swin_refresh(); 169 int swin_wrefresh(SWINDOW *win); 170 int swin_wnoutrefresh(SWINDOW *win); 171 int swin_doupdate(); 172 173 /* 174 * Curses supports color attributes on terminals with that capability. To use 175 * these routines start_color must be called, usually right after initscr. 176 * Colors are always used in pairs (referred to as color-pairs). A color-pair 177 * consists of a foreground color (for characters) and a background color 178 * (for the blank field on which the characters are displayed). A programmer 179 * initializes a color-pair with the routine init_pair. After it has been 180 * initialized, COLOR_PAIR(n), a macro defined in <curses.h>, can be used as 181 * a new video attribute. 182 */ 183 int swin_init_pair(int pair, int f, int b); 184 int swin_pair_content(int pair, int *f, int *b); 185 int swin_color_pair(int pair); /* COLOR_PAIR(n) */ 186 187 /** 188 * Put the keyboard into raw mode. 189 * 190 * This is currently only used by the kui_driver. 191 * 192 * @return 193 * 0 on succes or -1 on error 194 */ 195 int swin_raw(void); 196 197 #endif 198