23 static void set_normal_colors(
void)
68 static void normal_color_theme(
void)
71 #define mkattr(name, attr) do { \
72 attributes[name] = attr | COLOR_PAIR(name); } while (0)
100 static void no_colors_theme(
void)
103 #define mkattrn(name, attr) { attributes[name] = attr; }
135 use_default_colors();
138 normal_color_theme();
168 temp = (width -
length) / 2;
169 x = startx + (
int)temp;
170 (
void) wattrset(win, color);
171 mvwprintw(win, y, x,
"%s",
string);
183 for (i = 0; text[
i] !=
'\0'; i++)
197 for (i = 0; text[
i] !=
'\0' && lines < line_no; i++)
206 while (*line !=
'\0' && *line !=
'\n') {
222 total_lines =
min(total_lines, y);
223 for (i = 0; i < total_lines; i++) {
229 mvwprintw(win, i, 0,
"%s", tmp);
254 ITEM *btns[btn_num+1];
260 for (i = 0; i < btn_num; i++) {
262 btns[
i] = new_item(btn,
"");
263 btns_width +=
strlen(btn)+1;
266 btns[btn_num] =
NULL;
270 for (i = 0; i < msg_lines; i++) {
277 total_width =
max(msg_width, btns_width);
279 y = (LINES-(msg_lines+4))/2;
280 x = (
COLS-(total_width+4))/2;
285 win_rows = msg_lines+4;
287 win_rows = msg_lines+2;
289 win = newwin(win_rows, total_width+4, y, x);
291 menu_win = derwin(win, 1, btns_width, win_rows-2,
292 1+(total_width+2-btns_width)/2);
293 menu = new_menu(btns);
294 msg_win = derwin(win, win_rows-2, msg_width, 1,
295 1+(total_width+2-msg_width)/2);
307 set_menu_win(menu, win);
308 set_menu_sub(menu, menu_win);
309 set_menu_format(menu, 1, btn_num);
310 menu_opts_off(menu, O_SHOWDESC);
311 menu_opts_off(menu, O_SHOWMATCH);
312 menu_opts_on(menu, O_ONEVALUE);
313 menu_opts_on(menu, O_NONCYCLIC);
314 set_menu_mark(menu,
"");
320 while ((res = wgetch(win))) {
323 menu_driver(menu, REQ_LEFT_ITEM);
326 menu_driver(menu, REQ_RIGHT_ITEM);
338 if (res == 10 || res ==
' ') {
339 res = item_index(current_item(menu));
350 for (i = 0; i < btn_num; i++)
358 const char *title,
const char *prompt,
359 const char *
init,
char **resultp,
int *result_len)
361 int prompt_lines = 0;
362 int prompt_width = 0;
369 int cursor_position =
strlen(init);
373 if (
strlen(init)+1 > *result_len) {
374 *result_len =
strlen(init)+1;
375 *resultp = result = realloc(result, *result_len);
380 for (i = 0; i < prompt_lines; i++) {
383 prompt_width =
max(prompt_width, len);
387 prompt_width =
max(prompt_width,
strlen(title));
390 y = (LINES-(prompt_lines+4))/2;
391 x = (
COLS-(prompt_width+4))/2;
393 strncpy(result, init, *result_len);
396 win = newwin(prompt_lines+6, prompt_width+7, y, x);
397 prompt_win = derwin(win, prompt_lines+1, prompt_width, 2, 2);
398 form_win = derwin(win, 1, prompt_width, prompt_lines+3, 2);
399 keypad(form_win,
TRUE);
407 mvwprintw(win, 0, 3,
"%s", title);
413 mvwprintw(form_win, 0, 0,
"%*s", prompt_width,
" ");
414 cursor_form_win =
min(cursor_position, prompt_width-1);
415 mvwprintw(form_win, 0, 0,
"%s",
416 result + cursor_position-cursor_form_win);
419 panel = new_panel(win);
426 while ((res = wgetch(form_win))) {
437 if (cursor_position > 0) {
438 memmove(&result[cursor_position-1],
439 &result[cursor_position],
440 len-cursor_position+1);
447 if (cursor_position >= 0 && cursor_position < len) {
448 memmove(&result[cursor_position],
449 &result[cursor_position+1],
450 len-cursor_position+1);
456 if (cursor_position < len) {
463 if (cursor_position > 0) {
473 cursor_position = len;
474 cursor_form_win =
min(cursor_position, prompt_width-1);
479 if (len+2 > *result_len) {
481 *resultp = result = realloc(result,
485 memmove(&result[cursor_position+1],
486 &result[cursor_position],
487 len-cursor_position+1);
488 result[cursor_position] =
res;
493 mvprintw(0, 0,
"unknown key: %d\n", res);
497 if (cursor_form_win < 0)
499 else if (cursor_form_win > prompt_width-1)
500 cursor_form_win = prompt_width-1;
502 wmove(form_win, 0, 0);
504 mvwprintw(form_win, 0, 0,
"%*s", prompt_width,
" ");
505 mvwprintw(form_win, 0, 0,
"%s",
506 result + cursor_position-cursor_form_win);
507 wmove(form_win, 0, cursor_form_win);
537 touchwin(main_window);
549 int start_x = 0, start_y = 0;
550 int text_lines = 0, text_cols = 0;
561 for (i = 0; i < total_lines; i++) {
564 total_cols =
max(total_cols, len+2);
568 pad = newpad(total_lines+10, total_cols+10);
572 win_lines =
min(total_lines+4, LINES-2);
573 win_cols =
min(total_cols+2,
COLS-2);
574 text_lines =
max(win_lines-4, 0);
575 text_cols =
max(win_cols-2, 0);
578 y = (LINES-win_lines)/2;
579 x = (
COLS-win_cols)/2;
581 win = newwin(win_lines, win_cols, y, x);
587 mvwprintw(win, 0, 3,
" %s ", title);
588 panel = new_panel(win);
593 copywin(pad, win, start_y, start_x, 2, 2, text_lines,
608 start_y += text_lines-2;
612 start_y -= text_lines+2;
618 start_y = total_lines-text_lines;
637 if (res == 10 || res == 27 || res ==
'q' ||
643 if (start_y >= total_lines-text_lines)
644 start_y = total_lines-text_lines;
647 if (start_x >= total_cols-text_cols)
648 start_x = total_cols-text_cols;