std::string InputBox(const std::string &msg, const std::string &init, int max, chtype out)
{
    CDialog *dialog = CreateBaseDialog(TColorPair(COLOR_GREEN, COLOR_BLUE),
                                       TColorPair(COLOR_WHITE, COLOR_BLUE), 50);
    
    CLabel *label = new CLabel(msg, false);
    label->SetMaxReqWidth(MaxW());
    dialog->AddWidget(label);
    
    CInputField *input = new CInputField(init, CInputField::STRING, max, out);
    dialog->StartPack(input, true, true, 1, 0);
    
    CButton *okbutton = new CButton(GetTranslation("OK")), *cancelbutton = new CButton(GetTranslation("Cancel"));
    dialog->AddButton(okbutton, false, false);
    dialog->AddButton(cancelbutton, false, false);

    TUI.AddGroup(dialog, true);
    
    while (dialog->Run())
        ;
    
    std::string ret;
    if (dialog->ActivatedWidget() != cancelbutton)
        ret = input->Value();
    
    delete dialog;
    
    return ret;
}
CDialog *CreateBaseDialog(TColorPair fc, TColorPair dfc, int minw, int minh, const std::string &text)
{
    CDialog *dialog = new CDialog;
    dialog->SetFColors(fc);
    dialog->SetDFColors(dfc);

    if (minw)
        dialog->SetMinWidth(minw);

    if (minh)
        dialog->SetMinHeight(minh);

    if (!text.empty())
    {
        CLabel *label = new CLabel(text);
        label->SetMaxReqWidth(MaxW());
        dialog->StartPack(label, true, true, 1, 1);
    }
    
    return dialog;
}