1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2002-2006 Ben Kibbey <bjk@luxsci.net>
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
51 int dump_message(const char *title
, const char *prompt
, int center
,
52 const char *extra_help
, void(*custom_func
)(void*), void *arg
, int ckey
,
53 const char *format
, ...)
57 char *line
, **lines
= NULL
;
58 int width
= 0, height
;
61 char buf
[LINE_MAX
], *p
;
68 vasprintf(&line
, format
, ap
);
70 line
= Malloc(LINE_MAX
);
71 vsnprintf(line
, LINE_MAX
, format
, ap
);
76 /* Get the longest line to dynamically adjust the message box width. */
77 for (i
= n
= pos
= 0; line
[i
]; i
++, n
++) {
78 if (line
[i
] == '\n') {
86 pos
= (n
> pos
) ? n
: pos
;
95 for (i
= n
= pos
= 0; line
[i
]; i
++, n
++, pos
++) {
103 while (line
[--i
] != ' ')
118 while ((tmp
= strsep(&p
, "\n")) != NULL
) {
124 lines
= Realloc(lines
, (total
+ 2) * sizeof(char *));
125 lines
[total
++] = strdup(tmp
);
130 if (prompt
&& width
< strlen(prompt
))
131 width
= strlen(prompt
);
133 if (extra_help
&& width
< strlen(extra_help
))
134 width
= strlen(extra_help
);
136 if (title
&& width
< strlen(title
))
137 width
= strlen(title
);
145 win
= newwin((title
) ? height
+ 5 : height
+ 4, width
,
146 CALCPOSY(((title
) ? height
+ 5 : height
+ 4)), CALCPOSX(width
));
148 panel
= new_panel(win
);
149 wbkgd(win
, CP_MESSAGE_WINDOW
);
150 draw_window_title(win
, title
, width
, CP_MESSAGE_TITLE
, CP_MESSAGE_BORDER
);
152 for (i
= 0; lines
[i
]; i
++)
153 mvwprintw(win
, (title
) ? 2 + i
: 1 + i
,
154 (center
) ? CENTERX(width
, lines
[i
]) : 1, "%s", lines
[i
]);
157 draw_prompt(win
, (title
) ? height
+ 2 : height
+ 1, width
, extra_help
,
160 draw_prompt(win
, (title
) ? height
+ 3 : height
+ 2, width
, prompt
,
169 if (!custom_func
|| n
!= ckey
)
178 for (i
= 0; i
< total
; i
++)