2020-02-18 22:28:17 +03:00
|
|
|
#include "helpdata.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
2020-02-19 13:32:22 +03:00
|
|
|
static int MAX_LENGTH = 80;
|
|
|
|
static int SectionMargin = 3;
|
|
|
|
|
|
|
|
#define EXPANDER(COUNT, ITEM) QString(COUNT, ITEM).toStdString()
|
|
|
|
#define SPACES(X) EXPANDER(X, ' ')
|
|
|
|
#define SECTION_MARGIN SPACES(SectionMargin)
|
|
|
|
|
2020-02-18 22:28:17 +03:00
|
|
|
void QuasarAppUtils::Help::print(const QuasarAppUtils::Help::Options &charter) {
|
2020-02-19 13:32:22 +03:00
|
|
|
int maxLength = 0;
|
|
|
|
for (auto line = charter.begin(); line != charter.end(); ++line) {
|
|
|
|
if (line.key().size() > maxLength)
|
|
|
|
maxLength = line.key().size();
|
|
|
|
}
|
|
|
|
|
2020-02-18 22:28:17 +03:00
|
|
|
for (auto line = charter.begin(); line != charter.end(); ++line) {
|
2020-02-19 13:32:22 +03:00
|
|
|
print(line.key(), line.value(), maxLength + SectionMargin);
|
|
|
|
std::cout << std::endl;
|
2020-02-18 22:28:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QuasarAppUtils::Help::print(const QuasarAppUtils::Help::Charters &help) {
|
|
|
|
for (auto line = help.begin(); line != help.end(); ++line) {
|
2020-02-19 13:32:22 +03:00
|
|
|
QString expander(MAX_LENGTH, '-');
|
2020-02-18 22:28:17 +03:00
|
|
|
|
|
|
|
std::cout << line.key().toStdString()<< std::endl;
|
2020-02-19 13:32:22 +03:00
|
|
|
std::cout << expander.toStdString() << std::endl;
|
2020-02-18 22:28:17 +03:00
|
|
|
print(line.value());
|
2020-02-19 13:32:22 +03:00
|
|
|
std::cout << std::endl << expander.toStdString() << std::endl;
|
2020-02-18 22:28:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 13:32:22 +03:00
|
|
|
void QuasarAppUtils::Help::print(const QString &key, const QString &value, int keyLength) {
|
2020-02-18 22:28:17 +03:00
|
|
|
|
2020-02-19 13:32:22 +03:00
|
|
|
auto diffExpander = QString(keyLength - key.size(), ' ');
|
|
|
|
std::cout << SECTION_MARGIN << key.toStdString() << diffExpander.toStdString() << ":";
|
2020-02-18 22:28:17 +03:00
|
|
|
|
2020-02-19 13:32:22 +03:00
|
|
|
QString expander(keyLength + SectionMargin, ' ');
|
2020-02-18 22:28:17 +03:00
|
|
|
auto words = value.split(" ");
|
|
|
|
|
|
|
|
int currentLength = keyLength;
|
|
|
|
for (const auto& word : words) {
|
2020-02-19 13:32:22 +03:00
|
|
|
if (currentLength + 2 + word.size() < MAX_LENGTH) {
|
2020-02-19 19:25:22 +03:00
|
|
|
std::cout << " " << word.toStdString();
|
2020-02-18 22:28:17 +03:00
|
|
|
currentLength += 2 + word.size();
|
|
|
|
} else {
|
2020-02-19 13:32:22 +03:00
|
|
|
std::cout << std::endl << expander.toStdString() << ":";
|
2020-02-18 22:28:17 +03:00
|
|
|
currentLength = keyLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QuasarAppUtils::Help::setLineLength(int newLength) {
|
|
|
|
MAX_LENGTH = newLength;
|
|
|
|
}
|