Ignore:
Timestamp:
May 6, 2015, 1:10:17 PM (5 years ago)
Author:
Bruno Cornec
Message:
  • Rename mr_parted2fdisk to mr-parted2fdisk for consistency with all other new mr-* commands
  • Adds functions mr_center_string and mr_popup_and_get_string with dynamic allocation to solve a memory allocation issue reported on the ML
  • Fix mr_boot_type to detect correctly a UEFI based system
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/common/newt-specific.c

    r3292 r3377  
    717717        }
    718718    }
     719
     720/**
     721 * Ask the user to enter a value.
     722 * @param title The title of the dialog box.
     723 * @param b The blurb (e.g. what you want the user to enter).
     724 * @param input The string to initialize the user's answer with.
     725 * @return value needs to be freed up by caller
     726 */
     727char *mr_popup_and_get_string(char *title, char *b, char *input) {
     728
     729    /*@ newt ************************************************************ */
     730    newtComponent myForm;
     731    newtComponent b_1;
     732    newtComponent b_2;
     733    newtComponent b_res;
     734    newtComponent text;
     735    newtComponent type_here;
     736
     737    char *entry_value = NULL;
     738    char *blurb = NULL;
     739    char *out = NULL;
     740
     741    assert_string_is_neither_NULL_nor_zerolength(title);
     742    assert(b != NULL);
     743
     744    if (g_text_mode) {
     745        printf("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n-->  ", title, b);
     746        mr_getline(out, stdin);
     747        if (out[strlen(out) - 1] == '\n')
     748            out[strlen(out) - 1] = '\0';
     749        return(out);
     750    }
     751
     752    assert(input != NULL);
     753    text = newtTextboxReflowed(2, 1, b, 48, 5, 5, 0);
     754    type_here = newtEntry(2, newtTextboxGetNumLines(text) + 2, input, 50, (void *) &entry_value, NEWT_FLAG_RETURNEXIT);
     755    b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, "  OK  ");
     756    b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel");
     757    newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
     758    myForm = newtForm(NULL, NULL, 0);
     759    newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL);
     760    blurb = mr_center_string(b, 80);
     761    newtPushHelpLine(blurb);
     762    b_res = newtRunForm(myForm);
     763
     764    newtPopHelpLine();
     765    newtFormDestroy(myForm);
     766    newtPopWindow();
     767    mr_free(blurb);
     768
     769    if (b_res != b_2) {
     770        out = entry_value;
     771    }
     772    return(out);
     773}
    719774
    720775/**
Note: See TracChangeset for help on using the changeset viewer.