From: Miroslav Lichvar Date: Thu, 24 Nov 2022 16:13:11 +0000 (+0100) Subject: fix automatic width with --noitem and --notags options X-Git-Tag: r0-52-23~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6d4088f971869eed3ddd60cbc01a16f460e73ebf;p=thirdparty%2Fnewt.git fix automatic width with --noitem and --notags options --- diff --git a/dialogboxes.c b/dialogboxes.c index 13994e4..f0a53d3 100644 --- a/dialogboxes.c +++ b/dialogboxes.c @@ -485,11 +485,11 @@ int checkList(const char * text, int height, int width, int listHeight, snprintf(buf, MAXBUF, format, cbInfo[i].tag, cbInfo[i].text); if (useRadio) - cbInfo[i].comp = newtRadiobutton(4, top + 1 + i, buf, + cbInfo[i].comp = newtRadiobutton(2, top + 1 + i, buf, cbStates[i] != ' ', i ? cbInfo[i - 1].comp : NULL); else - cbInfo[i].comp = newtCheckbox(4, top + 1 + i, buf, + cbInfo[i].comp = newtCheckbox(2, top + 1 + i, buf, cbStates[i], NULL, cbStates + i); newtCheckboxSetFlags(cbInfo[i].comp, NEWT_FLAG_RETURNEXIT, NEWT_FLAGS_SET); diff --git a/whiptail.c b/whiptail.c index 804bde4..2ee42d0 100644 --- a/whiptail.c +++ b/whiptail.c @@ -200,7 +200,7 @@ static void spaceForButtons(int * height, int * width, int count, int full) { } static int menuSize(int * height, int * width, int * listHeight, - enum mode mode, poptContext options) { + enum mode mode, int * flags, poptContext options) { const char ** argv = poptGetArgs(options); int h = 0; int tagWidth = 0; @@ -217,13 +217,21 @@ static int menuSize(int * height, int * width, int * listHeight, tagWidth = max(tagWidth, _newt_wstrlen(argv[0], -1)); descriptionWidth = max(descriptionWidth, _newt_wstrlen(argv[1], -1)); - if ( mode == MODE_MENU ) + if (mode == MODE_MENU || *flags & FLAG_NOITEM) argv += 2; else argv += 3; h++; } + if (*flags & FLAG_NOTAGS) { + tagWidth = 0; + overhead -= mode == MODE_MENU ? 1 : 2; + } + if (*flags & FLAG_NOITEM) { + descriptionWidth = 0; + } + *width = max(*width, tagWidth + descriptionWidth + overhead); *width = min(*width, SLtt_Screen_Cols); @@ -255,7 +263,7 @@ static void guessSize(int * height, int * width, int * listHeight, case MODE_MENU: spaceForButtons(&h, &w, *flags & FLAG_NOCANCEL ? 1 : 2, fullButtons); - menuSize(&h, &w, listHeight, mode, options); + menuSize(&h, &w, listHeight, mode, flags, options); break; case MODE_YESNO: case MODE_MSGBOX: @@ -518,6 +526,12 @@ int main(int argc, const char ** argv) { break; } + if (noCancel) flags |= FLAG_NOCANCEL; + if (noItem) flags |= FLAG_NOITEM; + if (noTags) flags |= FLAG_NOTAGS; + if (scrollText) flags |= FLAG_SCROLL_TEXT; + if (defaultNo) flags |= FLAG_DEFAULT_NO; + newtInit(); newtCls(); @@ -551,12 +565,6 @@ int main(int argc, const char ** argv) { if (no_button) setButtonText(no_button, BUTTON_NO); - if (noCancel) flags |= FLAG_NOCANCEL; - if (noItem) flags |= FLAG_NOITEM; - if (noTags) flags |= FLAG_NOTAGS; - if (scrollText) flags |= FLAG_SCROLL_TEXT; - if (defaultNo) flags |= FLAG_DEFAULT_NO; - switch (mode) { case MODE_MSGBOX: case MODE_TEXTBOX: