xref: /freebsd/contrib/dialog/tailbox.c (revision 4c8945a06b01a5c8122cdeb402af36bb46a06acc)
1*4c8945a0SNathan Whitehorn /*
2*4c8945a0SNathan Whitehorn  *  $Id: tailbox.c,v 1.56 2010/04/28 20:52:20 tom Exp $
3*4c8945a0SNathan Whitehorn  *
4*4c8945a0SNathan Whitehorn  * tailbox.c -- implements the tail box
5*4c8945a0SNathan Whitehorn  *
6*4c8945a0SNathan Whitehorn  * Copyright 2000-2009,2010 Thomas E. Dickey
7*4c8945a0SNathan Whitehorn  *
8*4c8945a0SNathan Whitehorn  *  This program is free software; you can redistribute it and/or modify
9*4c8945a0SNathan Whitehorn  *  it under the terms of the GNU Lesser General Public License, version 2.1
10*4c8945a0SNathan Whitehorn  *  as published by the Free Software Foundation.
11*4c8945a0SNathan Whitehorn  *
12*4c8945a0SNathan Whitehorn  *  This program is distributed in the hope that it will be useful, but
13*4c8945a0SNathan Whitehorn  *  WITHOUT ANY WARRANTY; without even the implied warranty of
14*4c8945a0SNathan Whitehorn  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15*4c8945a0SNathan Whitehorn  *  Lesser General Public License for more details.
16*4c8945a0SNathan Whitehorn  *
17*4c8945a0SNathan Whitehorn  *  You should have received a copy of the GNU Lesser General Public
18*4c8945a0SNathan Whitehorn  *  License along with this program; if not, write to
19*4c8945a0SNathan Whitehorn  *	Free Software Foundation, Inc.
20*4c8945a0SNathan Whitehorn  *	51 Franklin St., Fifth Floor
21*4c8945a0SNathan Whitehorn  *	Boston, MA 02110, USA.
22*4c8945a0SNathan Whitehorn  *
23*4c8945a0SNathan Whitehorn  *  An earlier version of this program lists as authors
24*4c8945a0SNathan Whitehorn  *	Pasquale De Marco (demarco_p@abramo.it)
25*4c8945a0SNathan Whitehorn  */
26*4c8945a0SNathan Whitehorn 
27*4c8945a0SNathan Whitehorn #include <dialog.h>
28*4c8945a0SNathan Whitehorn #include <dlg_keys.h>
29*4c8945a0SNathan Whitehorn 
30*4c8945a0SNathan Whitehorn typedef struct {
31*4c8945a0SNathan Whitehorn     DIALOG_CALLBACK obj;
32*4c8945a0SNathan Whitehorn     WINDOW *text;
33*4c8945a0SNathan Whitehorn     const char **buttons;
34*4c8945a0SNathan Whitehorn     int hscroll;
35*4c8945a0SNathan Whitehorn     int old_hscroll;
36*4c8945a0SNathan Whitehorn     char line[MAX_LEN + 1];
37*4c8945a0SNathan Whitehorn } MY_OBJ;
38*4c8945a0SNathan Whitehorn 
39*4c8945a0SNathan Whitehorn /*
40*4c8945a0SNathan Whitehorn  * Return current line of text.
41*4c8945a0SNathan Whitehorn  */
42*4c8945a0SNathan Whitehorn static char *
43*4c8945a0SNathan Whitehorn get_line(MY_OBJ * obj)
44*4c8945a0SNathan Whitehorn {
45*4c8945a0SNathan Whitehorn     FILE *fp = obj->obj.input;
46*4c8945a0SNathan Whitehorn     int col = -(obj->hscroll);
47*4c8945a0SNathan Whitehorn     int j, tmpint, ch;
48*4c8945a0SNathan Whitehorn 
49*4c8945a0SNathan Whitehorn     do {
50*4c8945a0SNathan Whitehorn 	if (((ch = getc(fp)) == EOF) && !feof(fp))
51*4c8945a0SNathan Whitehorn 	    dlg_exiterr("Error moving file pointer in get_line().");
52*4c8945a0SNathan Whitehorn 	else if (!feof(fp) && (ch != '\n')) {
53*4c8945a0SNathan Whitehorn 	    if ((ch == TAB) && (dialog_vars.tab_correct)) {
54*4c8945a0SNathan Whitehorn 		tmpint = dialog_state.tab_len
55*4c8945a0SNathan Whitehorn 		    - ((col + obj->hscroll) % dialog_state.tab_len);
56*4c8945a0SNathan Whitehorn 		for (j = 0; j < tmpint; j++) {
57*4c8945a0SNathan Whitehorn 		    if (col >= 0 && col < MAX_LEN)
58*4c8945a0SNathan Whitehorn 			obj->line[col] = ' ';
59*4c8945a0SNathan Whitehorn 		    ++col;
60*4c8945a0SNathan Whitehorn 		}
61*4c8945a0SNathan Whitehorn 	    } else {
62*4c8945a0SNathan Whitehorn 		if (col >= 0)
63*4c8945a0SNathan Whitehorn 		    obj->line[col] = (char) ch;
64*4c8945a0SNathan Whitehorn 		++col;
65*4c8945a0SNathan Whitehorn 	    }
66*4c8945a0SNathan Whitehorn 	    if (col >= MAX_LEN)
67*4c8945a0SNathan Whitehorn 		break;
68*4c8945a0SNathan Whitehorn 	}
69*4c8945a0SNathan Whitehorn     } while (!feof(fp) && (ch != '\n'));
70*4c8945a0SNathan Whitehorn 
71*4c8945a0SNathan Whitehorn     if (col < 0)
72*4c8945a0SNathan Whitehorn 	col = 0;
73*4c8945a0SNathan Whitehorn     obj->line[col] = '\0';
74*4c8945a0SNathan Whitehorn 
75*4c8945a0SNathan Whitehorn     return obj->line;
76*4c8945a0SNathan Whitehorn }
77*4c8945a0SNathan Whitehorn 
78*4c8945a0SNathan Whitehorn /*
79*4c8945a0SNathan Whitehorn  * Print a new line of text.
80*4c8945a0SNathan Whitehorn  */
81*4c8945a0SNathan Whitehorn static void
82*4c8945a0SNathan Whitehorn print_line(MY_OBJ * obj, WINDOW *win, int row, int width)
83*4c8945a0SNathan Whitehorn {
84*4c8945a0SNathan Whitehorn     int i, y, x;
85*4c8945a0SNathan Whitehorn     char *line = get_line(obj);
86*4c8945a0SNathan Whitehorn 
87*4c8945a0SNathan Whitehorn     (void) wmove(win, row, 0);	/* move cursor to correct line */
88*4c8945a0SNathan Whitehorn     (void) waddch(win, ' ');
89*4c8945a0SNathan Whitehorn #ifdef NCURSES_VERSION
90*4c8945a0SNathan Whitehorn     (void) waddnstr(win, line, MIN((int) strlen(line), width - 2));
91*4c8945a0SNathan Whitehorn #else
92*4c8945a0SNathan Whitehorn     line[MIN((int) strlen(line), width - 2)] = '\0';
93*4c8945a0SNathan Whitehorn     waddstr(win, line);
94*4c8945a0SNathan Whitehorn #endif
95*4c8945a0SNathan Whitehorn 
96*4c8945a0SNathan Whitehorn     getyx(win, y, x);
97*4c8945a0SNathan Whitehorn     /* Clear 'residue' of previous line */
98*4c8945a0SNathan Whitehorn     for (i = 0; i < width - x; i++)
99*4c8945a0SNathan Whitehorn 	(void) waddch(win, ' ');
100*4c8945a0SNathan Whitehorn }
101*4c8945a0SNathan Whitehorn 
102*4c8945a0SNathan Whitehorn /*
103*4c8945a0SNathan Whitehorn  * Go back 'target' lines in text file.  BUFSIZ has to be in 'size_t' range.
104*4c8945a0SNathan Whitehorn  */
105*4c8945a0SNathan Whitehorn static void
106*4c8945a0SNathan Whitehorn last_lines(MY_OBJ * obj, int target)
107*4c8945a0SNathan Whitehorn {
108*4c8945a0SNathan Whitehorn     FILE *fp = obj->obj.input;
109*4c8945a0SNathan Whitehorn     long inx;
110*4c8945a0SNathan Whitehorn     int count = 0;
111*4c8945a0SNathan Whitehorn     char buf[BUFSIZ + 1];
112*4c8945a0SNathan Whitehorn     long size_to_read;
113*4c8945a0SNathan Whitehorn     long offset = 0;
114*4c8945a0SNathan Whitehorn     long fpos = 0;
115*4c8945a0SNathan Whitehorn 
116*4c8945a0SNathan Whitehorn     if (fseek(fp, 0, SEEK_END) == -1
117*4c8945a0SNathan Whitehorn 	|| (fpos = ftell(fp)) < 0)
118*4c8945a0SNathan Whitehorn 	dlg_exiterr("Error moving file pointer in last_lines().");
119*4c8945a0SNathan Whitehorn 
120*4c8945a0SNathan Whitehorn     if (fpos != 0) {
121*4c8945a0SNathan Whitehorn 	++target;
122*4c8945a0SNathan Whitehorn 	for (;;) {
123*4c8945a0SNathan Whitehorn 	    if (fpos >= BUFSIZ) {
124*4c8945a0SNathan Whitehorn 		size_to_read = BUFSIZ;
125*4c8945a0SNathan Whitehorn 	    } else {
126*4c8945a0SNathan Whitehorn 		size_to_read = fpos;
127*4c8945a0SNathan Whitehorn 	    }
128*4c8945a0SNathan Whitehorn 	    fpos = fpos - size_to_read;
129*4c8945a0SNathan Whitehorn 	    if (fseek(fp, fpos, SEEK_SET) == -1)
130*4c8945a0SNathan Whitehorn 		dlg_exiterr("Error moving file pointer in last_lines().");
131*4c8945a0SNathan Whitehorn 	    (void) fread(buf, (size_t) size_to_read, 1, fp);
132*4c8945a0SNathan Whitehorn 	    if (ferror(fp))
133*4c8945a0SNathan Whitehorn 		dlg_exiterr("Error reading file in last_lines().");
134*4c8945a0SNathan Whitehorn 
135*4c8945a0SNathan Whitehorn 	    offset += size_to_read;
136*4c8945a0SNathan Whitehorn 	    for (inx = size_to_read - 1; inx >= 0; --inx) {
137*4c8945a0SNathan Whitehorn 		if (buf[inx] == '\n') {
138*4c8945a0SNathan Whitehorn 		    if (++count > target)
139*4c8945a0SNathan Whitehorn 			break;
140*4c8945a0SNathan Whitehorn 		    offset = inx + 1;
141*4c8945a0SNathan Whitehorn 		}
142*4c8945a0SNathan Whitehorn 	    }
143*4c8945a0SNathan Whitehorn 
144*4c8945a0SNathan Whitehorn 	    if (count > target) {
145*4c8945a0SNathan Whitehorn 		break;
146*4c8945a0SNathan Whitehorn 	    } else if (fpos == 0) {
147*4c8945a0SNathan Whitehorn 		offset = 0;
148*4c8945a0SNathan Whitehorn 		break;
149*4c8945a0SNathan Whitehorn 	    }
150*4c8945a0SNathan Whitehorn 	}
151*4c8945a0SNathan Whitehorn 
152*4c8945a0SNathan Whitehorn 	if (fseek(fp, fpos + offset, SEEK_SET) == -1)
153*4c8945a0SNathan Whitehorn 	    dlg_exiterr("Error moving file pointer in last_lines().");
154*4c8945a0SNathan Whitehorn     }
155*4c8945a0SNathan Whitehorn }
156*4c8945a0SNathan Whitehorn 
157*4c8945a0SNathan Whitehorn /*
158*4c8945a0SNathan Whitehorn  * Print a new page of text.
159*4c8945a0SNathan Whitehorn  */
160*4c8945a0SNathan Whitehorn static void
161*4c8945a0SNathan Whitehorn print_page(MY_OBJ * obj, int height, int width)
162*4c8945a0SNathan Whitehorn {
163*4c8945a0SNathan Whitehorn     int i;
164*4c8945a0SNathan Whitehorn 
165*4c8945a0SNathan Whitehorn     for (i = 0; i < height; i++) {
166*4c8945a0SNathan Whitehorn 	print_line(obj, obj->text, i, width);
167*4c8945a0SNathan Whitehorn     }
168*4c8945a0SNathan Whitehorn     (void) wnoutrefresh(obj->text);
169*4c8945a0SNathan Whitehorn }
170*4c8945a0SNathan Whitehorn 
171*4c8945a0SNathan Whitehorn static void
172*4c8945a0SNathan Whitehorn print_last_page(MY_OBJ * obj)
173*4c8945a0SNathan Whitehorn {
174*4c8945a0SNathan Whitehorn     int high = getmaxy(obj->obj.win) - (2 * MARGIN + (obj->obj.bg_task ? 1 : 3));
175*4c8945a0SNathan Whitehorn     int wide = getmaxx(obj->text);
176*4c8945a0SNathan Whitehorn 
177*4c8945a0SNathan Whitehorn     last_lines(obj, high);
178*4c8945a0SNathan Whitehorn     print_page(obj, high, wide);
179*4c8945a0SNathan Whitehorn }
180*4c8945a0SNathan Whitehorn 
181*4c8945a0SNathan Whitehorn static void
182*4c8945a0SNathan Whitehorn repaint_text(MY_OBJ * obj)
183*4c8945a0SNathan Whitehorn {
184*4c8945a0SNathan Whitehorn     int cur_y, cur_x;
185*4c8945a0SNathan Whitehorn 
186*4c8945a0SNathan Whitehorn     getyx(obj->obj.win, cur_y, cur_x);
187*4c8945a0SNathan Whitehorn     obj->old_hscroll = obj->hscroll;
188*4c8945a0SNathan Whitehorn     print_last_page(obj);
189*4c8945a0SNathan Whitehorn     (void) wmove(obj->obj.win, cur_y, cur_x);	/* Restore cursor position */
190*4c8945a0SNathan Whitehorn     wrefresh(obj->obj.win);
191*4c8945a0SNathan Whitehorn }
192*4c8945a0SNathan Whitehorn 
193*4c8945a0SNathan Whitehorn static bool
194*4c8945a0SNathan Whitehorn handle_my_getc(DIALOG_CALLBACK * cb, int ch, int fkey, int *result)
195*4c8945a0SNathan Whitehorn {
196*4c8945a0SNathan Whitehorn     MY_OBJ *obj = (MY_OBJ *) cb;
197*4c8945a0SNathan Whitehorn     bool done = FALSE;
198*4c8945a0SNathan Whitehorn 
199*4c8945a0SNathan Whitehorn     if (!fkey && dlg_char_to_button(ch, obj->buttons) == 0) {
200*4c8945a0SNathan Whitehorn 	ch = DLGK_ENTER;
201*4c8945a0SNathan Whitehorn 	fkey = TRUE;
202*4c8945a0SNathan Whitehorn     }
203*4c8945a0SNathan Whitehorn 
204*4c8945a0SNathan Whitehorn     if (fkey) {
205*4c8945a0SNathan Whitehorn 	switch (ch) {
206*4c8945a0SNathan Whitehorn 	case DLGK_ENTER:
207*4c8945a0SNathan Whitehorn 	    *result = DLG_EXIT_OK;
208*4c8945a0SNathan Whitehorn 	    done = TRUE;
209*4c8945a0SNathan Whitehorn 	    break;
210*4c8945a0SNathan Whitehorn 	case DLGK_BEGIN:	/* Beginning of line */
211*4c8945a0SNathan Whitehorn 	    obj->hscroll = 0;
212*4c8945a0SNathan Whitehorn 	    break;
213*4c8945a0SNathan Whitehorn 	case DLGK_GRID_LEFT:	/* Scroll left */
214*4c8945a0SNathan Whitehorn 	    if (obj->hscroll > 0) {
215*4c8945a0SNathan Whitehorn 		obj->hscroll -= 1;
216*4c8945a0SNathan Whitehorn 	    }
217*4c8945a0SNathan Whitehorn 	    break;
218*4c8945a0SNathan Whitehorn 	case DLGK_GRID_RIGHT:	/* Scroll right */
219*4c8945a0SNathan Whitehorn 	    if (obj->hscroll < MAX_LEN)
220*4c8945a0SNathan Whitehorn 		obj->hscroll += 1;
221*4c8945a0SNathan Whitehorn 	    break;
222*4c8945a0SNathan Whitehorn 	default:
223*4c8945a0SNathan Whitehorn 	    beep();
224*4c8945a0SNathan Whitehorn 	    break;
225*4c8945a0SNathan Whitehorn 	}
226*4c8945a0SNathan Whitehorn 	if ((obj->hscroll != obj->old_hscroll))
227*4c8945a0SNathan Whitehorn 	    repaint_text(obj);
228*4c8945a0SNathan Whitehorn     } else {
229*4c8945a0SNathan Whitehorn 	switch (ch) {
230*4c8945a0SNathan Whitehorn 	case ERR:
231*4c8945a0SNathan Whitehorn 	    clearerr(cb->input);
232*4c8945a0SNathan Whitehorn 	    ch = getc(cb->input);
233*4c8945a0SNathan Whitehorn 	    (void) ungetc(ch, cb->input);
234*4c8945a0SNathan Whitehorn 	    if ((ch != EOF) || (obj->hscroll != obj->old_hscroll)) {
235*4c8945a0SNathan Whitehorn 		repaint_text(obj);
236*4c8945a0SNathan Whitehorn 	    }
237*4c8945a0SNathan Whitehorn 	    break;
238*4c8945a0SNathan Whitehorn 	case ESC:
239*4c8945a0SNathan Whitehorn 	    done = TRUE;
240*4c8945a0SNathan Whitehorn 	    *result = DLG_EXIT_ESC;
241*4c8945a0SNathan Whitehorn 	    break;
242*4c8945a0SNathan Whitehorn 	default:
243*4c8945a0SNathan Whitehorn 	    beep();
244*4c8945a0SNathan Whitehorn 	    break;
245*4c8945a0SNathan Whitehorn 	}
246*4c8945a0SNathan Whitehorn     }
247*4c8945a0SNathan Whitehorn 
248*4c8945a0SNathan Whitehorn     return !done;
249*4c8945a0SNathan Whitehorn }
250*4c8945a0SNathan Whitehorn 
251*4c8945a0SNathan Whitehorn /*
252*4c8945a0SNathan Whitehorn  * Display text from a file in a dialog box, like in a "tail -f".
253*4c8945a0SNathan Whitehorn  */
254*4c8945a0SNathan Whitehorn int
255*4c8945a0SNathan Whitehorn dialog_tailbox(const char *title, const char *file, int height, int width, int bg_task)
256*4c8945a0SNathan Whitehorn {
257*4c8945a0SNathan Whitehorn     /* *INDENT-OFF* */
258*4c8945a0SNathan Whitehorn     static DLG_KEYS_BINDING binding[] = {
259*4c8945a0SNathan Whitehorn 	ENTERKEY_BINDINGS,
260*4c8945a0SNathan Whitehorn 	DLG_KEYS_DATA( DLGK_BEGIN,      '0' ),
261*4c8945a0SNathan Whitehorn 	DLG_KEYS_DATA( DLGK_BEGIN,      KEY_BEG ),
262*4c8945a0SNathan Whitehorn 	DLG_KEYS_DATA( DLGK_GRID_LEFT,  'H' ),
263*4c8945a0SNathan Whitehorn 	DLG_KEYS_DATA( DLGK_GRID_LEFT,  'h' ),
264*4c8945a0SNathan Whitehorn 	DLG_KEYS_DATA( DLGK_GRID_LEFT,  KEY_LEFT ),
265*4c8945a0SNathan Whitehorn 	DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'L' ),
266*4c8945a0SNathan Whitehorn 	DLG_KEYS_DATA( DLGK_GRID_RIGHT, 'l' ),
267*4c8945a0SNathan Whitehorn 	DLG_KEYS_DATA( DLGK_GRID_RIGHT, KEY_RIGHT ),
268*4c8945a0SNathan Whitehorn 	END_KEYS_BINDING
269*4c8945a0SNathan Whitehorn     };
270*4c8945a0SNathan Whitehorn     /* *INDENT-ON* */
271*4c8945a0SNathan Whitehorn 
272*4c8945a0SNathan Whitehorn #ifdef KEY_RESIZE
273*4c8945a0SNathan Whitehorn     int old_height = height;
274*4c8945a0SNathan Whitehorn     int old_width = width;
275*4c8945a0SNathan Whitehorn #endif
276*4c8945a0SNathan Whitehorn     int fkey;
277*4c8945a0SNathan Whitehorn     int x, y, result, thigh;
278*4c8945a0SNathan Whitehorn     WINDOW *dialog, *text;
279*4c8945a0SNathan Whitehorn     const char **buttons = 0;
280*4c8945a0SNathan Whitehorn     MY_OBJ *obj;
281*4c8945a0SNathan Whitehorn     FILE *fd;
282*4c8945a0SNathan Whitehorn     int min_width = 12;
283*4c8945a0SNathan Whitehorn 
284*4c8945a0SNathan Whitehorn     /* Open input file for reading */
285*4c8945a0SNathan Whitehorn     if ((fd = fopen(file, "rb")) == NULL)
286*4c8945a0SNathan Whitehorn 	dlg_exiterr("Can't open input file in dialog_tailbox().");
287*4c8945a0SNathan Whitehorn 
288*4c8945a0SNathan Whitehorn #ifdef KEY_RESIZE
289*4c8945a0SNathan Whitehorn   retry:
290*4c8945a0SNathan Whitehorn #endif
291*4c8945a0SNathan Whitehorn     dlg_auto_sizefile(title, file, &height, &width, 2, min_width);
292*4c8945a0SNathan Whitehorn     dlg_print_size(height, width);
293*4c8945a0SNathan Whitehorn     dlg_ctl_size(height, width);
294*4c8945a0SNathan Whitehorn 
295*4c8945a0SNathan Whitehorn     x = dlg_box_x_ordinate(width);
296*4c8945a0SNathan Whitehorn     y = dlg_box_y_ordinate(height);
297*4c8945a0SNathan Whitehorn     thigh = height - ((2 * MARGIN) + (bg_task ? 0 : 2));
298*4c8945a0SNathan Whitehorn 
299*4c8945a0SNathan Whitehorn     dialog = dlg_new_window(height, width, y, x);
300*4c8945a0SNathan Whitehorn 
301*4c8945a0SNathan Whitehorn     dlg_mouse_setbase(x, y);
302*4c8945a0SNathan Whitehorn 
303*4c8945a0SNathan Whitehorn     /* Create window for text region, used for scrolling text */
304*4c8945a0SNathan Whitehorn     text = dlg_sub_window(dialog,
305*4c8945a0SNathan Whitehorn 			  thigh,
306*4c8945a0SNathan Whitehorn 			  width - (2 * MARGIN),
307*4c8945a0SNathan Whitehorn 			  y + MARGIN,
308*4c8945a0SNathan Whitehorn 			  x + MARGIN);
309*4c8945a0SNathan Whitehorn 
310*4c8945a0SNathan Whitehorn     dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
311*4c8945a0SNathan Whitehorn     dlg_draw_bottom_box(dialog);
312*4c8945a0SNathan Whitehorn     dlg_draw_title(dialog, title);
313*4c8945a0SNathan Whitehorn 
314*4c8945a0SNathan Whitehorn     if (!bg_task) {
315*4c8945a0SNathan Whitehorn 	buttons = dlg_exit_label();
316*4c8945a0SNathan Whitehorn 	dlg_button_layout(buttons, &min_width);
317*4c8945a0SNathan Whitehorn 	dlg_draw_buttons(dialog, height - (2 * MARGIN), 0, buttons, FALSE,
318*4c8945a0SNathan Whitehorn 			 FALSE, width);
319*4c8945a0SNathan Whitehorn     }
320*4c8945a0SNathan Whitehorn 
321*4c8945a0SNathan Whitehorn     (void) wmove(dialog, thigh, (MARGIN + 1));
322*4c8945a0SNathan Whitehorn     (void) wnoutrefresh(dialog);
323*4c8945a0SNathan Whitehorn 
324*4c8945a0SNathan Whitehorn     obj = dlg_calloc(MY_OBJ, 1);
325*4c8945a0SNathan Whitehorn     assert_ptr(obj, "dialog_tailbox");
326*4c8945a0SNathan Whitehorn 
327*4c8945a0SNathan Whitehorn     obj->obj.input = fd;
328*4c8945a0SNathan Whitehorn     obj->obj.win = dialog;
329*4c8945a0SNathan Whitehorn     obj->obj.handle_getc = handle_my_getc;
330*4c8945a0SNathan Whitehorn     obj->obj.keep_bg = bg_task && dialog_vars.cant_kill;
331*4c8945a0SNathan Whitehorn     obj->obj.bg_task = bg_task;
332*4c8945a0SNathan Whitehorn     obj->text = text;
333*4c8945a0SNathan Whitehorn     obj->buttons = buttons;
334*4c8945a0SNathan Whitehorn     dlg_add_callback(&(obj->obj));
335*4c8945a0SNathan Whitehorn 
336*4c8945a0SNathan Whitehorn     dlg_register_window(dialog, "tailbox", binding);
337*4c8945a0SNathan Whitehorn     dlg_register_buttons(dialog, "tailbox", buttons);
338*4c8945a0SNathan Whitehorn 
339*4c8945a0SNathan Whitehorn     /* Print last page of text */
340*4c8945a0SNathan Whitehorn     dlg_attr_clear(text, thigh, getmaxx(text), dialog_attr);
341*4c8945a0SNathan Whitehorn     repaint_text(obj);
342*4c8945a0SNathan Whitehorn 
343*4c8945a0SNathan Whitehorn     if (bg_task) {
344*4c8945a0SNathan Whitehorn 	result = DLG_EXIT_OK;
345*4c8945a0SNathan Whitehorn     } else {
346*4c8945a0SNathan Whitehorn 	int ch;
347*4c8945a0SNathan Whitehorn 	do {
348*4c8945a0SNathan Whitehorn 	    ch = dlg_getc(dialog, &fkey);
349*4c8945a0SNathan Whitehorn #ifdef KEY_RESIZE
350*4c8945a0SNathan Whitehorn 	    if (fkey && ch == KEY_RESIZE) {
351*4c8945a0SNathan Whitehorn 		/* reset data */
352*4c8945a0SNathan Whitehorn 		height = old_height;
353*4c8945a0SNathan Whitehorn 		width = old_width;
354*4c8945a0SNathan Whitehorn 		/* repaint */
355*4c8945a0SNathan Whitehorn 		dlg_clear();
356*4c8945a0SNathan Whitehorn 		dlg_del_window(dialog);
357*4c8945a0SNathan Whitehorn 		refresh();
358*4c8945a0SNathan Whitehorn 		dlg_mouse_free_regions();
359*4c8945a0SNathan Whitehorn 		dlg_button_layout(buttons, &min_width);
360*4c8945a0SNathan Whitehorn 		goto retry;
361*4c8945a0SNathan Whitehorn 	    }
362*4c8945a0SNathan Whitehorn #endif
363*4c8945a0SNathan Whitehorn 	}
364*4c8945a0SNathan Whitehorn 	while (handle_my_getc(&(obj->obj), ch, fkey, &result));
365*4c8945a0SNathan Whitehorn     }
366*4c8945a0SNathan Whitehorn     dlg_mouse_free_regions();
367*4c8945a0SNathan Whitehorn     return result;
368*4c8945a0SNathan Whitehorn }
369