kconfig/lxdialog: handle newline characters in print_autowrap()
When exiting menuconfig with unsaved changes, a dialog like the following is shown: Do you wish to save your new configuration ? <ESC><ESC> to continue. The author of the dialog text specified a newline after the '?', and probably expected it to be processed, so let print_autowrap() handle newlines propperly. Also, reword that dialog's second phrase with a real sentence. Signed-off-by: Dirk Gouders <dirk@gouders.net> Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr> [yann.morin.1998@free.fr: very slightly tweak the commit message] Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
This commit is contained in:
parent
ff7b0c2c24
commit
1376391621
2 changed files with 19 additions and 16 deletions
|
@ -371,27 +371,19 @@ void print_title(WINDOW *dialog, const char *title, int width)
|
||||||
/*
|
/*
|
||||||
* Print a string of text in a window, automatically wrap around to the
|
* Print a string of text in a window, automatically wrap around to the
|
||||||
* next line if the string is too long to fit on one line. Newline
|
* next line if the string is too long to fit on one line. Newline
|
||||||
* characters '\n' are replaced by spaces. We start on a new line
|
* characters '\n' are propperly processed. We start on a new line
|
||||||
* if there is no room for at least 4 nonblanks following a double-space.
|
* if there is no room for at least 4 nonblanks following a double-space.
|
||||||
*/
|
*/
|
||||||
void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
|
void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
|
||||||
{
|
{
|
||||||
int newl, cur_x, cur_y;
|
int newl, cur_x, cur_y;
|
||||||
int i, prompt_len, room, wlen;
|
int prompt_len, room, wlen;
|
||||||
char tempstr[MAX_LEN + 1], *word, *sp, *sp2;
|
char tempstr[MAX_LEN + 1], *word, *sp, *sp2, *newline_separator = 0;
|
||||||
|
|
||||||
strcpy(tempstr, prompt);
|
strcpy(tempstr, prompt);
|
||||||
|
|
||||||
prompt_len = strlen(tempstr);
|
prompt_len = strlen(tempstr);
|
||||||
|
|
||||||
/*
|
|
||||||
* Remove newlines
|
|
||||||
*/
|
|
||||||
for (i = 0; i < prompt_len; i++) {
|
|
||||||
if (tempstr[i] == '\n')
|
|
||||||
tempstr[i] = ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prompt_len <= width - x * 2) { /* If prompt is short */
|
if (prompt_len <= width - x * 2) { /* If prompt is short */
|
||||||
wmove(win, y, (width - prompt_len) / 2);
|
wmove(win, y, (width - prompt_len) / 2);
|
||||||
waddstr(win, tempstr);
|
waddstr(win, tempstr);
|
||||||
|
@ -401,7 +393,10 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
|
||||||
newl = 1;
|
newl = 1;
|
||||||
word = tempstr;
|
word = tempstr;
|
||||||
while (word && *word) {
|
while (word && *word) {
|
||||||
sp = strchr(word, ' ');
|
sp = strpbrk(word, "\n ");
|
||||||
|
if (sp && *sp == '\n')
|
||||||
|
newline_separator = sp;
|
||||||
|
|
||||||
if (sp)
|
if (sp)
|
||||||
*sp++ = 0;
|
*sp++ = 0;
|
||||||
|
|
||||||
|
@ -413,7 +408,7 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
|
||||||
if (wlen > room ||
|
if (wlen > room ||
|
||||||
(newl && wlen < 4 && sp
|
(newl && wlen < 4 && sp
|
||||||
&& wlen + 1 + strlen(sp) > room
|
&& wlen + 1 + strlen(sp) > room
|
||||||
&& (!(sp2 = strchr(sp, ' '))
|
&& (!(sp2 = strpbrk(sp, "\n "))
|
||||||
|| wlen + 1 + (sp2 - sp) > room))) {
|
|| wlen + 1 + (sp2 - sp) > room))) {
|
||||||
cur_y++;
|
cur_y++;
|
||||||
cur_x = x;
|
cur_x = x;
|
||||||
|
@ -421,7 +416,15 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
|
||||||
wmove(win, cur_y, cur_x);
|
wmove(win, cur_y, cur_x);
|
||||||
waddstr(win, word);
|
waddstr(win, word);
|
||||||
getyx(win, cur_y, cur_x);
|
getyx(win, cur_y, cur_x);
|
||||||
cur_x++;
|
|
||||||
|
/* Move to the next line if the word separator was a newline */
|
||||||
|
if (newline_separator) {
|
||||||
|
cur_y++;
|
||||||
|
cur_x = x;
|
||||||
|
newline_separator = 0;
|
||||||
|
} else
|
||||||
|
cur_x++;
|
||||||
|
|
||||||
if (sp && *sp == ' ') {
|
if (sp && *sp == ' ') {
|
||||||
cur_x++; /* double space */
|
cur_x++; /* double space */
|
||||||
while (*++sp == ' ') ;
|
while (*++sp == ' ') ;
|
||||||
|
|
|
@ -958,8 +958,8 @@ static int handle_exit(void)
|
||||||
dialog_clear();
|
dialog_clear();
|
||||||
if (conf_get_changed())
|
if (conf_get_changed())
|
||||||
res = dialog_yesno(NULL,
|
res = dialog_yesno(NULL,
|
||||||
_("Do you wish to save your new configuration ?\n"
|
_("Do you wish to save your new configuration?\n"
|
||||||
"<ESC><ESC> to continue."),
|
"(Press <ESC><ESC> to continue kernel configuration.)"),
|
||||||
6, 60);
|
6, 60);
|
||||||
else
|
else
|
||||||
res = -1;
|
res = -1;
|
||||||
|
|
Loading…
Reference in a new issue