1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2002-2006 Ben Kibbey <bjk@arbornet.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 int dump_message(const char *title
, const char *prompt
, int center
,
33 const char *extra_help
, void(*custom_func
)(void*), void *arg
, int ckey
,
34 const char *format
, ...)
38 char *line
, **lines
= NULL
;
39 int width
= 0, height
;
42 char buf
[LINE_MAX
], *p
;
49 vasprintf(&line
, format
, ap
);
51 line
= Malloc(LINE_MAX
);
52 vsnprintf(line
, LINE_MAX
, format
, ap
);
57 /* Get the longest line to dynamically adjust the message box width. */
58 for (i
= n
= pos
= 0; line
[i
]; i
++, n
++) {
59 if (line
[i
] == '\n') {
67 pos
= (n
> pos
) ? n
: pos
;
76 for (i
= n
= pos
= 0; line
[i
]; i
++, n
++, pos
++) {
84 while (line
[--i
] != ' ')
99 while ((tmp
= strsep(&p
, "\n")) != NULL
) {
105 lines
= Realloc(lines
, (total
+ 2) * sizeof(char *));
106 lines
[total
++] = strdup(tmp
);
111 if (prompt
&& width
< strlen(prompt
))
112 width
= strlen(prompt
);
114 if (extra_help
&& width
< strlen(extra_help
))
115 width
= strlen(extra_help
);
117 if (title
&& width
< strlen(title
))
118 width
= strlen(title
);
126 win
= newwin((title
) ? height
+ 5 : height
+ 4, width
,
127 CALCPOSY(((title
) ? height
+ 5 : height
+ 4)), CALCPOSX(width
));
128 panel
= new_panel(win
);
129 wbkgd(win
, CP_MESSAGE_WINDOW
);
130 draw_window_title(win
, title
, width
, CP_MESSAGE_TITLE
, CP_MESSAGE_BORDER
);
132 for (i
= 0; lines
[i
]; i
++)
133 mvwprintw(win
, (title
) ? 2 + i
: 1 + i
,
134 (center
) ? CENTERX(width
, lines
[i
]) : 1, "%s", lines
[i
]);
137 draw_prompt(win
, (title
) ? height
+ 2 : height
+ 1, width
, extra_help
,
140 draw_prompt(win
, (title
) ? height
+ 3 : height
+ 2, width
, prompt
,
149 if (!custom_func
|| n
!= ckey
)
158 for (i
= 0; i
< total
; i
++)