14c8945a0SNathan Whitehorn /* 2*f4f33ea0SBaptiste Daroussin * $Id: tailbox.c,v 1.72 2018/06/19 22:57:01 tom Exp $ 34c8945a0SNathan Whitehorn * 44c8945a0SNathan Whitehorn * tailbox.c -- implements the tail box 54c8945a0SNathan Whitehorn * 6*f4f33ea0SBaptiste Daroussin * Copyright 2000-2012,2018 Thomas E. Dickey 74c8945a0SNathan Whitehorn * 84c8945a0SNathan Whitehorn * This program is free software; you can redistribute it and/or modify 94c8945a0SNathan Whitehorn * it under the terms of the GNU Lesser General Public License, version 2.1 104c8945a0SNathan Whitehorn * as published by the Free Software Foundation. 114c8945a0SNathan Whitehorn * 124c8945a0SNathan Whitehorn * This program is distributed in the hope that it will be useful, but 134c8945a0SNathan Whitehorn * WITHOUT ANY WARRANTY; without even the implied warranty of 144c8945a0SNathan Whitehorn * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 154c8945a0SNathan Whitehorn * Lesser General Public License for more details. 164c8945a0SNathan Whitehorn * 174c8945a0SNathan Whitehorn * You should have received a copy of the GNU Lesser General Public 184c8945a0SNathan Whitehorn * License along with this program; if not, write to 194c8945a0SNathan Whitehorn * Free Software Foundation, Inc. 204c8945a0SNathan Whitehorn * 51 Franklin St., Fifth Floor 214c8945a0SNathan Whitehorn * Boston, MA 02110, USA. 224c8945a0SNathan Whitehorn * 234c8945a0SNathan Whitehorn * An earlier version of this program lists as authors 244c8945a0SNathan Whitehorn * Pasquale De Marco (demarco_p@abramo.it) 254c8945a0SNathan Whitehorn */ 264c8945a0SNathan Whitehorn 274c8945a0SNathan Whitehorn #include <dialog.h> 284c8945a0SNathan Whitehorn #include <dlg_keys.h> 297a1c0d96SNathan Whitehorn #include <sys/stat.h> 304c8945a0SNathan Whitehorn 314c8945a0SNathan Whitehorn typedef struct { 324c8945a0SNathan Whitehorn DIALOG_CALLBACK obj; 334c8945a0SNathan Whitehorn WINDOW *text; 344c8945a0SNathan Whitehorn const char **buttons; 354c8945a0SNathan Whitehorn int hscroll; 364c8945a0SNathan Whitehorn int old_hscroll; 372a3e3873SBaptiste Daroussin char line[MAX_LEN + 2]; 387a1c0d96SNathan Whitehorn off_t last_pos; 394c8945a0SNathan Whitehorn } MY_OBJ; 404c8945a0SNathan Whitehorn 414c8945a0SNathan Whitehorn /* 424c8945a0SNathan Whitehorn * Return current line of text. 434c8945a0SNathan Whitehorn */ 444c8945a0SNathan Whitehorn static char * 454c8945a0SNathan Whitehorn get_line(MY_OBJ * obj) 464c8945a0SNathan Whitehorn { 474c8945a0SNathan Whitehorn FILE *fp = obj->obj.input; 484c8945a0SNathan Whitehorn int col = -(obj->hscroll); 494c8945a0SNathan Whitehorn int j, tmpint, ch; 504c8945a0SNathan Whitehorn 514c8945a0SNathan Whitehorn do { 524c8945a0SNathan Whitehorn if (((ch = getc(fp)) == EOF) && !feof(fp)) 534c8945a0SNathan Whitehorn dlg_exiterr("Error moving file pointer in get_line()."); 544c8945a0SNathan Whitehorn else if (!feof(fp) && (ch != '\n')) { 554c8945a0SNathan Whitehorn if ((ch == TAB) && (dialog_vars.tab_correct)) { 564c8945a0SNathan Whitehorn tmpint = dialog_state.tab_len 574c8945a0SNathan Whitehorn - ((col + obj->hscroll) % dialog_state.tab_len); 584c8945a0SNathan Whitehorn for (j = 0; j < tmpint; j++) { 594c8945a0SNathan Whitehorn if (col >= 0 && col < MAX_LEN) 604c8945a0SNathan Whitehorn obj->line[col] = ' '; 614c8945a0SNathan Whitehorn ++col; 624c8945a0SNathan Whitehorn } 634c8945a0SNathan Whitehorn } else { 644c8945a0SNathan Whitehorn if (col >= 0) 654c8945a0SNathan Whitehorn obj->line[col] = (char) ch; 664c8945a0SNathan Whitehorn ++col; 674c8945a0SNathan Whitehorn } 684c8945a0SNathan Whitehorn if (col >= MAX_LEN) 694c8945a0SNathan Whitehorn break; 704c8945a0SNathan Whitehorn } 714c8945a0SNathan Whitehorn } while (!feof(fp) && (ch != '\n')); 724c8945a0SNathan Whitehorn 734c8945a0SNathan Whitehorn if (col < 0) 744c8945a0SNathan Whitehorn col = 0; 754c8945a0SNathan Whitehorn obj->line[col] = '\0'; 764c8945a0SNathan Whitehorn 774c8945a0SNathan Whitehorn return obj->line; 784c8945a0SNathan Whitehorn } 794c8945a0SNathan Whitehorn 804c8945a0SNathan Whitehorn /* 814c8945a0SNathan Whitehorn * Print a new line of text. 824c8945a0SNathan Whitehorn */ 834c8945a0SNathan Whitehorn static void 844c8945a0SNathan Whitehorn print_line(MY_OBJ * obj, WINDOW *win, int row, int width) 854c8945a0SNathan Whitehorn { 864c8945a0SNathan Whitehorn int i, y, x; 874c8945a0SNathan Whitehorn char *line = get_line(obj); 884c8945a0SNathan Whitehorn 894c8945a0SNathan Whitehorn (void) wmove(win, row, 0); /* move cursor to correct line */ 904c8945a0SNathan Whitehorn (void) waddch(win, ' '); 914c8945a0SNathan Whitehorn (void) waddnstr(win, line, MIN((int) strlen(line), width - 2)); 924c8945a0SNathan Whitehorn 934c8945a0SNathan Whitehorn getyx(win, y, x); 942a3e3873SBaptiste Daroussin (void) y; 954c8945a0SNathan Whitehorn /* Clear 'residue' of previous line */ 964c8945a0SNathan Whitehorn for (i = 0; i < width - x; i++) 974c8945a0SNathan Whitehorn (void) waddch(win, ' '); 984c8945a0SNathan Whitehorn } 994c8945a0SNathan Whitehorn 1004c8945a0SNathan Whitehorn /* 1014c8945a0SNathan Whitehorn * Go back 'target' lines in text file. BUFSIZ has to be in 'size_t' range. 1024c8945a0SNathan Whitehorn */ 1034c8945a0SNathan Whitehorn static void 1044c8945a0SNathan Whitehorn last_lines(MY_OBJ * obj, int target) 1054c8945a0SNathan Whitehorn { 1064c8945a0SNathan Whitehorn FILE *fp = obj->obj.input; 1077a1c0d96SNathan Whitehorn size_t inx; 1084c8945a0SNathan Whitehorn int count = 0; 1094c8945a0SNathan Whitehorn char buf[BUFSIZ + 1]; 1107a1c0d96SNathan Whitehorn size_t size_to_read; 1117a1c0d96SNathan Whitehorn size_t size_as_read; 1124c8945a0SNathan Whitehorn long offset = 0; 1134c8945a0SNathan Whitehorn long fpos = 0; 1144c8945a0SNathan Whitehorn 1157a1c0d96SNathan Whitehorn if (fseek(fp, 0L, SEEK_END) == -1 1164c8945a0SNathan Whitehorn || (fpos = ftell(fp)) < 0) 1174c8945a0SNathan Whitehorn dlg_exiterr("Error moving file pointer in last_lines()."); 1184c8945a0SNathan Whitehorn 1194c8945a0SNathan Whitehorn if (fpos != 0) { 1204c8945a0SNathan Whitehorn ++target; 1214c8945a0SNathan Whitehorn for (;;) { 1224c8945a0SNathan Whitehorn if (fpos >= BUFSIZ) { 1234c8945a0SNathan Whitehorn size_to_read = BUFSIZ; 1244c8945a0SNathan Whitehorn } else { 1257a1c0d96SNathan Whitehorn size_to_read = (size_t) fpos; 1264c8945a0SNathan Whitehorn } 1277a1c0d96SNathan Whitehorn fpos = fpos - (long) size_to_read; 1284c8945a0SNathan Whitehorn if (fseek(fp, fpos, SEEK_SET) == -1) 1294c8945a0SNathan Whitehorn dlg_exiterr("Error moving file pointer in last_lines()."); 1307a1c0d96SNathan Whitehorn size_as_read = fread(buf, sizeof(char), size_to_read, fp); 1314c8945a0SNathan Whitehorn if (ferror(fp)) 1324c8945a0SNathan Whitehorn dlg_exiterr("Error reading file in last_lines()."); 1334c8945a0SNathan Whitehorn 1347a1c0d96SNathan Whitehorn if (size_as_read == 0) { 1357a1c0d96SNathan Whitehorn fpos = 0; 1367a1c0d96SNathan Whitehorn offset = 0; 1377a1c0d96SNathan Whitehorn break; 1387a1c0d96SNathan Whitehorn } 1397a1c0d96SNathan Whitehorn 1407a1c0d96SNathan Whitehorn offset += (long) size_as_read; 1417a1c0d96SNathan Whitehorn for (inx = size_as_read - 1; inx != 0; --inx) { 1424c8945a0SNathan Whitehorn if (buf[inx] == '\n') { 1434c8945a0SNathan Whitehorn if (++count > target) 1444c8945a0SNathan Whitehorn break; 1457a1c0d96SNathan Whitehorn offset = (long) (inx + 1); 1464c8945a0SNathan Whitehorn } 1474c8945a0SNathan Whitehorn } 1484c8945a0SNathan Whitehorn 1494c8945a0SNathan Whitehorn if (count > target) { 1504c8945a0SNathan Whitehorn break; 1514c8945a0SNathan Whitehorn } else if (fpos == 0) { 1524c8945a0SNathan Whitehorn offset = 0; 1534c8945a0SNathan Whitehorn break; 1544c8945a0SNathan Whitehorn } 1554c8945a0SNathan Whitehorn } 1564c8945a0SNathan Whitehorn 1574c8945a0SNathan Whitehorn if (fseek(fp, fpos + offset, SEEK_SET) == -1) 1584c8945a0SNathan Whitehorn dlg_exiterr("Error moving file pointer in last_lines()."); 1594c8945a0SNathan Whitehorn } 1604c8945a0SNathan Whitehorn } 1614c8945a0SNathan Whitehorn 1624c8945a0SNathan Whitehorn /* 1634c8945a0SNathan Whitehorn * Print a new page of text. 1644c8945a0SNathan Whitehorn */ 1654c8945a0SNathan Whitehorn static void 1664c8945a0SNathan Whitehorn print_page(MY_OBJ * obj, int height, int width) 1674c8945a0SNathan Whitehorn { 1684c8945a0SNathan Whitehorn int i; 1694c8945a0SNathan Whitehorn 1704c8945a0SNathan Whitehorn for (i = 0; i < height; i++) { 1714c8945a0SNathan Whitehorn print_line(obj, obj->text, i, width); 1724c8945a0SNathan Whitehorn } 1734c8945a0SNathan Whitehorn (void) wnoutrefresh(obj->text); 1744c8945a0SNathan Whitehorn } 1754c8945a0SNathan Whitehorn 1764c8945a0SNathan Whitehorn static void 1774c8945a0SNathan Whitehorn print_last_page(MY_OBJ * obj) 1784c8945a0SNathan Whitehorn { 1794c8945a0SNathan Whitehorn int high = getmaxy(obj->obj.win) - (2 * MARGIN + (obj->obj.bg_task ? 1 : 3)); 1804c8945a0SNathan Whitehorn int wide = getmaxx(obj->text); 1814c8945a0SNathan Whitehorn 1824c8945a0SNathan Whitehorn last_lines(obj, high); 1834c8945a0SNathan Whitehorn print_page(obj, high, wide); 1844c8945a0SNathan Whitehorn } 1854c8945a0SNathan Whitehorn 1864c8945a0SNathan Whitehorn static void 1874c8945a0SNathan Whitehorn repaint_text(MY_OBJ * obj) 1884c8945a0SNathan Whitehorn { 1897a1c0d96SNathan Whitehorn FILE *fp = obj->obj.input; 1904c8945a0SNathan Whitehorn int cur_y, cur_x; 1914c8945a0SNathan Whitehorn 1924c8945a0SNathan Whitehorn getyx(obj->obj.win, cur_y, cur_x); 1934c8945a0SNathan Whitehorn obj->old_hscroll = obj->hscroll; 1947a1c0d96SNathan Whitehorn 1954c8945a0SNathan Whitehorn print_last_page(obj); 1967a1c0d96SNathan Whitehorn obj->last_pos = ftell(fp); 1977a1c0d96SNathan Whitehorn 1984c8945a0SNathan Whitehorn (void) wmove(obj->obj.win, cur_y, cur_x); /* Restore cursor position */ 1994c8945a0SNathan Whitehorn wrefresh(obj->obj.win); 2004c8945a0SNathan Whitehorn } 2014c8945a0SNathan Whitehorn 2024c8945a0SNathan Whitehorn static bool 2037a1c0d96SNathan Whitehorn handle_input(DIALOG_CALLBACK * cb) 2047a1c0d96SNathan Whitehorn { 2057a1c0d96SNathan Whitehorn MY_OBJ *obj = (MY_OBJ *) cb; 2067a1c0d96SNathan Whitehorn FILE *fp = obj->obj.input; 2077a1c0d96SNathan Whitehorn struct stat sb; 2087a1c0d96SNathan Whitehorn 2097a1c0d96SNathan Whitehorn if (fstat(fileno(fp), &sb) == 0 2107a1c0d96SNathan Whitehorn && sb.st_size != obj->last_pos) { 2117a1c0d96SNathan Whitehorn repaint_text(obj); 2127a1c0d96SNathan Whitehorn } 2137a1c0d96SNathan Whitehorn 2147a1c0d96SNathan Whitehorn return TRUE; 2157a1c0d96SNathan Whitehorn } 2167a1c0d96SNathan Whitehorn 2177a1c0d96SNathan Whitehorn static bool 218*f4f33ea0SBaptiste Daroussin valid_callback(DIALOG_CALLBACK * cb) 219*f4f33ea0SBaptiste Daroussin { 220*f4f33ea0SBaptiste Daroussin bool valid = FALSE; 221*f4f33ea0SBaptiste Daroussin DIALOG_CALLBACK *p; 222*f4f33ea0SBaptiste Daroussin for (p = dialog_state.getc_callbacks; p != 0; p = p->next) { 223*f4f33ea0SBaptiste Daroussin if (p == cb) { 224*f4f33ea0SBaptiste Daroussin valid = TRUE; 225*f4f33ea0SBaptiste Daroussin break; 226*f4f33ea0SBaptiste Daroussin } 227*f4f33ea0SBaptiste Daroussin } 228*f4f33ea0SBaptiste Daroussin return valid; 229*f4f33ea0SBaptiste Daroussin } 230*f4f33ea0SBaptiste Daroussin 231*f4f33ea0SBaptiste Daroussin static bool 2324c8945a0SNathan Whitehorn handle_my_getc(DIALOG_CALLBACK * cb, int ch, int fkey, int *result) 2334c8945a0SNathan Whitehorn { 2344c8945a0SNathan Whitehorn MY_OBJ *obj = (MY_OBJ *) cb; 2354c8945a0SNathan Whitehorn bool done = FALSE; 2364c8945a0SNathan Whitehorn 237*f4f33ea0SBaptiste Daroussin if (!valid_callback(cb)) 238*f4f33ea0SBaptiste Daroussin return FALSE; 239*f4f33ea0SBaptiste Daroussin 2404c8945a0SNathan Whitehorn if (!fkey && dlg_char_to_button(ch, obj->buttons) == 0) { 2414c8945a0SNathan Whitehorn ch = DLGK_ENTER; 2424c8945a0SNathan Whitehorn fkey = TRUE; 2434c8945a0SNathan Whitehorn } 2444c8945a0SNathan Whitehorn 2454c8945a0SNathan Whitehorn if (fkey) { 2464c8945a0SNathan Whitehorn switch (ch) { 2474c8945a0SNathan Whitehorn case DLGK_ENTER: 2484c8945a0SNathan Whitehorn *result = DLG_EXIT_OK; 2494c8945a0SNathan Whitehorn done = TRUE; 2504c8945a0SNathan Whitehorn break; 2514c8945a0SNathan Whitehorn case DLGK_BEGIN: /* Beginning of line */ 2524c8945a0SNathan Whitehorn obj->hscroll = 0; 2534c8945a0SNathan Whitehorn break; 2544c8945a0SNathan Whitehorn case DLGK_GRID_LEFT: /* Scroll left */ 2554c8945a0SNathan Whitehorn if (obj->hscroll > 0) { 2564c8945a0SNathan Whitehorn obj->hscroll -= 1; 2574c8945a0SNathan Whitehorn } 2584c8945a0SNathan Whitehorn break; 2594c8945a0SNathan Whitehorn case DLGK_GRID_RIGHT: /* Scroll right */ 2604c8945a0SNathan Whitehorn if (obj->hscroll < MAX_LEN) 2614c8945a0SNathan Whitehorn obj->hscroll += 1; 2624c8945a0SNathan Whitehorn break; 2634c8945a0SNathan Whitehorn default: 2644c8945a0SNathan Whitehorn beep(); 2654c8945a0SNathan Whitehorn break; 2664c8945a0SNathan Whitehorn } 2674c8945a0SNathan Whitehorn if ((obj->hscroll != obj->old_hscroll)) 2684c8945a0SNathan Whitehorn repaint_text(obj); 2694c8945a0SNathan Whitehorn } else { 2704c8945a0SNathan Whitehorn switch (ch) { 2714c8945a0SNathan Whitehorn case ERR: 2724c8945a0SNathan Whitehorn clearerr(cb->input); 2734c8945a0SNathan Whitehorn ch = getc(cb->input); 2744c8945a0SNathan Whitehorn (void) ungetc(ch, cb->input); 2757a1c0d96SNathan Whitehorn if (ch != EOF) { 2767a1c0d96SNathan Whitehorn handle_input(cb); 2774c8945a0SNathan Whitehorn } 2784c8945a0SNathan Whitehorn break; 2794c8945a0SNathan Whitehorn case ESC: 2804c8945a0SNathan Whitehorn done = TRUE; 2814c8945a0SNathan Whitehorn *result = DLG_EXIT_ESC; 2824c8945a0SNathan Whitehorn break; 2834c8945a0SNathan Whitehorn default: 2844c8945a0SNathan Whitehorn beep(); 2854c8945a0SNathan Whitehorn break; 2864c8945a0SNathan Whitehorn } 2874c8945a0SNathan Whitehorn } 2884c8945a0SNathan Whitehorn 2894c8945a0SNathan Whitehorn return !done; 2904c8945a0SNathan Whitehorn } 2914c8945a0SNathan Whitehorn 2924c8945a0SNathan Whitehorn /* 2934c8945a0SNathan Whitehorn * Display text from a file in a dialog box, like in a "tail -f". 2944c8945a0SNathan Whitehorn */ 2954c8945a0SNathan Whitehorn int 296*f4f33ea0SBaptiste Daroussin dialog_tailbox(const char *title, 297*f4f33ea0SBaptiste Daroussin const char *filename, 298*f4f33ea0SBaptiste Daroussin int height, 299*f4f33ea0SBaptiste Daroussin int width, 300*f4f33ea0SBaptiste Daroussin int bg_task) 3014c8945a0SNathan Whitehorn { 3024c8945a0SNathan Whitehorn /* *INDENT-OFF* */ 3034c8945a0SNathan Whitehorn static DLG_KEYS_BINDING binding[] = { 304682c9e0fSNathan Whitehorn HELPKEY_BINDINGS, 3054c8945a0SNathan Whitehorn ENTERKEY_BINDINGS, 3064c8945a0SNathan Whitehorn DLG_KEYS_DATA( DLGK_BEGIN, '0' ), 3074c8945a0SNathan Whitehorn DLG_KEYS_DATA( DLGK_BEGIN, KEY_BEG ), 3084c8945a0SNathan Whitehorn DLG_KEYS_DATA( DLGK_GRID_LEFT, 'H' ), 3094c8945a0SNathan Whitehorn DLG_KEYS_DATA( DLGK_GRID_LEFT, 'h' ), 3104c8945a0SNathan Whitehorn DLG_KEYS_DATA( DLGK_GRID_LEFT, KEY_LEFT ), 3114c8945a0SNathan Whitehorn DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'L' ), 3124c8945a0SNathan Whitehorn DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'l' ), 3134c8945a0SNathan Whitehorn DLG_KEYS_DATA( DLGK_GRID_RIGHT, KEY_RIGHT ), 3144c8945a0SNathan Whitehorn END_KEYS_BINDING 3154c8945a0SNathan Whitehorn }; 3164c8945a0SNathan Whitehorn /* *INDENT-ON* */ 3174c8945a0SNathan Whitehorn 3184c8945a0SNathan Whitehorn #ifdef KEY_RESIZE 3194c8945a0SNathan Whitehorn int old_height = height; 3204c8945a0SNathan Whitehorn int old_width = width; 3214c8945a0SNathan Whitehorn #endif 3224c8945a0SNathan Whitehorn int fkey; 3234c8945a0SNathan Whitehorn int x, y, result, thigh; 3244c8945a0SNathan Whitehorn WINDOW *dialog, *text; 3254c8945a0SNathan Whitehorn const char **buttons = 0; 3264c8945a0SNathan Whitehorn MY_OBJ *obj; 3274c8945a0SNathan Whitehorn FILE *fd; 3284c8945a0SNathan Whitehorn int min_width = 12; 3294c8945a0SNathan Whitehorn 330*f4f33ea0SBaptiste Daroussin DLG_TRACE(("# tailbox args:\n")); 331*f4f33ea0SBaptiste Daroussin DLG_TRACE2S("title", title); 332*f4f33ea0SBaptiste Daroussin DLG_TRACE2S("filename", filename); 333*f4f33ea0SBaptiste Daroussin DLG_TRACE2N("height", height); 334*f4f33ea0SBaptiste Daroussin DLG_TRACE2N("width", width); 335*f4f33ea0SBaptiste Daroussin DLG_TRACE2N("bg_task", bg_task); 336*f4f33ea0SBaptiste Daroussin 3374c8945a0SNathan Whitehorn /* Open input file for reading */ 338*f4f33ea0SBaptiste Daroussin if ((fd = fopen(filename, "rb")) == NULL) 3394c8945a0SNathan Whitehorn dlg_exiterr("Can't open input file in dialog_tailbox()."); 3404c8945a0SNathan Whitehorn 3414c8945a0SNathan Whitehorn #ifdef KEY_RESIZE 3424c8945a0SNathan Whitehorn retry: 3434c8945a0SNathan Whitehorn #endif 344*f4f33ea0SBaptiste Daroussin dlg_auto_sizefile(title, filename, &height, &width, 2, min_width); 3454c8945a0SNathan Whitehorn dlg_print_size(height, width); 3464c8945a0SNathan Whitehorn dlg_ctl_size(height, width); 3474c8945a0SNathan Whitehorn 3484c8945a0SNathan Whitehorn x = dlg_box_x_ordinate(width); 3494c8945a0SNathan Whitehorn y = dlg_box_y_ordinate(height); 3504c8945a0SNathan Whitehorn thigh = height - ((2 * MARGIN) + (bg_task ? 0 : 2)); 3514c8945a0SNathan Whitehorn 3524c8945a0SNathan Whitehorn dialog = dlg_new_window(height, width, y, x); 3534c8945a0SNathan Whitehorn 3544c8945a0SNathan Whitehorn dlg_mouse_setbase(x, y); 3554c8945a0SNathan Whitehorn 3564c8945a0SNathan Whitehorn /* Create window for text region, used for scrolling text */ 3574c8945a0SNathan Whitehorn text = dlg_sub_window(dialog, 3584c8945a0SNathan Whitehorn thigh, 3594c8945a0SNathan Whitehorn width - (2 * MARGIN), 3604c8945a0SNathan Whitehorn y + MARGIN, 3614c8945a0SNathan Whitehorn x + MARGIN); 3624c8945a0SNathan Whitehorn 3632a3e3873SBaptiste Daroussin dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr); 3642a3e3873SBaptiste Daroussin dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr); 3654c8945a0SNathan Whitehorn dlg_draw_title(dialog, title); 366682c9e0fSNathan Whitehorn dlg_draw_helpline(dialog, FALSE); 3674c8945a0SNathan Whitehorn 3684c8945a0SNathan Whitehorn if (!bg_task) { 3694c8945a0SNathan Whitehorn buttons = dlg_exit_label(); 3704c8945a0SNathan Whitehorn dlg_button_layout(buttons, &min_width); 3714c8945a0SNathan Whitehorn dlg_draw_buttons(dialog, height - (2 * MARGIN), 0, buttons, FALSE, 3724c8945a0SNathan Whitehorn FALSE, width); 3734c8945a0SNathan Whitehorn } 3744c8945a0SNathan Whitehorn 3754c8945a0SNathan Whitehorn (void) wmove(dialog, thigh, (MARGIN + 1)); 3764c8945a0SNathan Whitehorn (void) wnoutrefresh(dialog); 3774c8945a0SNathan Whitehorn 3784c8945a0SNathan Whitehorn obj = dlg_calloc(MY_OBJ, 1); 3794c8945a0SNathan Whitehorn assert_ptr(obj, "dialog_tailbox"); 3804c8945a0SNathan Whitehorn 3814c8945a0SNathan Whitehorn obj->obj.input = fd; 3824c8945a0SNathan Whitehorn obj->obj.win = dialog; 3834c8945a0SNathan Whitehorn obj->obj.handle_getc = handle_my_getc; 3847a1c0d96SNathan Whitehorn obj->obj.handle_input = bg_task ? handle_input : 0; 3854c8945a0SNathan Whitehorn obj->obj.keep_bg = bg_task && dialog_vars.cant_kill; 3864c8945a0SNathan Whitehorn obj->obj.bg_task = bg_task; 3874c8945a0SNathan Whitehorn obj->text = text; 3884c8945a0SNathan Whitehorn obj->buttons = buttons; 3894c8945a0SNathan Whitehorn dlg_add_callback(&(obj->obj)); 3904c8945a0SNathan Whitehorn 3914c8945a0SNathan Whitehorn dlg_register_window(dialog, "tailbox", binding); 3924c8945a0SNathan Whitehorn dlg_register_buttons(dialog, "tailbox", buttons); 3934c8945a0SNathan Whitehorn 3944c8945a0SNathan Whitehorn /* Print last page of text */ 3954c8945a0SNathan Whitehorn dlg_attr_clear(text, thigh, getmaxx(text), dialog_attr); 3964c8945a0SNathan Whitehorn repaint_text(obj); 3974c8945a0SNathan Whitehorn 3982a3e3873SBaptiste Daroussin dlg_trace_win(dialog); 3994c8945a0SNathan Whitehorn if (bg_task) { 4004c8945a0SNathan Whitehorn result = DLG_EXIT_OK; 4014c8945a0SNathan Whitehorn } else { 4024c8945a0SNathan Whitehorn int ch; 4034c8945a0SNathan Whitehorn do { 4044c8945a0SNathan Whitehorn ch = dlg_getc(dialog, &fkey); 4054c8945a0SNathan Whitehorn #ifdef KEY_RESIZE 4064c8945a0SNathan Whitehorn if (fkey && ch == KEY_RESIZE) { 407*f4f33ea0SBaptiste Daroussin dlg_will_resize(dialog); 4084c8945a0SNathan Whitehorn /* reset data */ 4094c8945a0SNathan Whitehorn height = old_height; 4104c8945a0SNathan Whitehorn width = old_width; 4114c8945a0SNathan Whitehorn /* repaint */ 4124c8945a0SNathan Whitehorn dlg_clear(); 4134c8945a0SNathan Whitehorn dlg_del_window(dialog); 4144c8945a0SNathan Whitehorn refresh(); 4154c8945a0SNathan Whitehorn dlg_mouse_free_regions(); 4164c8945a0SNathan Whitehorn dlg_button_layout(buttons, &min_width); 4174c8945a0SNathan Whitehorn goto retry; 4184c8945a0SNathan Whitehorn } 4194c8945a0SNathan Whitehorn #endif 4204c8945a0SNathan Whitehorn } 4214c8945a0SNathan Whitehorn while (handle_my_getc(&(obj->obj), ch, fkey, &result)); 4224c8945a0SNathan Whitehorn } 4234c8945a0SNathan Whitehorn dlg_mouse_free_regions(); 4244c8945a0SNathan Whitehorn return result; 4254c8945a0SNathan Whitehorn } 426