Ejemplo n.º 1
0
void getLine(const std::string& prompt,
             std::string& out) {
    std::string promptCopy = prompt;
    appendSpace(promptCopy);
    std::cout << promptCopy;
    getline(std::cin, out);
}
Ejemplo n.º 2
0
bool getYesOrNo(const std::string& prompt,
                const std::string& reprompt,
                const std::string& defaultValue) {
    std::string promptCopy = prompt;
    appendSpace(promptCopy);
    bool value;
    while (true) {
        std::cout << promptCopy;
        std::string line;
        getline(std::cin, line);
        if (line.empty()) {
            line = defaultValue;
        }
        if ((int) line.length() > 0) {
            char first = tolower(line[0]);
            if (first == 'y') {
                value = true;
                break;
            } else if (first == 'n') {
                value = false;
                break;
            }
        }
        std::cout << (reprompt.empty() ? GETYESORNO_DEFAULT_REPROMPT : reprompt) << std::endl;
        if (promptCopy.empty()) {
            promptCopy = GETYESORNO_DEFAULT_PROMPT;
        }
    }
    return value;
}
unsigned int appendMotionEndDetectionStatusRegisterTableData(OutputStream* outputStream, 
                                                             MotionEndDetectionStatusRegister motionEndDetectionStatusRegister,
                                                             unsigned int columnSize) {
    appendTableSeparator(outputStream);
    appendSpace(outputStream);
    unsigned int length = appendMotionEndDetectionStatusRegister(outputStream, motionEndDetectionStatusRegister);
    return length + appendSpaces(outputStream, columnSize - length) + 2;
}
Ejemplo n.º 4
0
double getReal(const std::string& prompt,
               const std::string& reprompt) {
    std::string promptCopy = prompt;
    appendSpace(promptCopy);
    double value;
    while (true) {
        std::cout << promptCopy;
        std::string line;
        getline(std::cin, line);
        std::istringstream stream(line);
        stream >> value >> std::ws;
        if (!stream.fail() && stream.eof()) {
            break;
        }
        std::cout << (reprompt.empty() ? GETREAL_DEFAULT_REPROMPT : reprompt) << std::endl;
        if (promptCopy.empty()) {
            promptCopy = GETREAL_DEFAULT_PROMPT;
        }
    }
    return value;
}
std::string promptUserForFile(std::ofstream& stream,
                              const std::string& prompt,
                              const std::string& reprompt) {
    std::string promptCopy = prompt;
    std::string repromptCopy = reprompt;
    if (reprompt == "") {
        repromptCopy = "Unable to open that file.  Try again.";
    }
    appendSpace(promptCopy);
    while (true) {
        std::cout << promptCopy;
        std::string filename;
        getline(std::cin, filename);
        if (!filename.empty()) {
            openFile(stream, filename);
            if (!stream.fail()) return filename;
            stream.clear();
        }
        std::cout << repromptCopy << std::endl;
        if (promptCopy == "") promptCopy = "Output file: ";
    }
}
Ejemplo n.º 6
0
int getInteger(const std::string& prompt,
               const std::string& reprompt) {
    std::string promptCopy = prompt;
    appendSpace(promptCopy);
    int value;
    while (true) {
        std::cout << promptCopy;
        std::string line;
        getline(std::cin, line);
        trimInPlace(line);
        std::istringstream stream(line);
        stream >> value;
        if (!stream.fail() && stream.eof()) {
            break;
        }
        std::cout << (reprompt.empty() ? GETINTEGER_DEFAULT_REPROMPT : reprompt) << std::endl;
        if (promptCopy.empty()) {
            promptCopy = GETINTEGER_DEFAULT_PROMPT;
        }
    }
    return value;
}