mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-04-26 09:44:38 +00:00
fix print Help
This commit is contained in:
parent
5a971a5b21
commit
663c1571c7
35
helpdata.cpp
35
helpdata.cpp
@ -1,39 +1,52 @@
|
||||
#include "helpdata.h"
|
||||
#include <iostream>
|
||||
|
||||
int MAX_LENGTH = 80;
|
||||
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)
|
||||
|
||||
void QuasarAppUtils::Help::print(const QuasarAppUtils::Help::Options &charter) {
|
||||
int maxLength = 0;
|
||||
for (auto line = charter.begin(); line != charter.end(); ++line) {
|
||||
print(line.key(), line.value());
|
||||
if (line.key().size() > maxLength)
|
||||
maxLength = line.key().size();
|
||||
}
|
||||
|
||||
for (auto line = charter.begin(); line != charter.end(); ++line) {
|
||||
print(line.key(), line.value(), maxLength + SectionMargin);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void QuasarAppUtils::Help::print(const QuasarAppUtils::Help::Charters &help) {
|
||||
for (auto line = help.begin(); line != help.end(); ++line) {
|
||||
std::string expander('-', MAX_LENGTH);
|
||||
QString expander(MAX_LENGTH, '-');
|
||||
|
||||
std::cout << line.key().toStdString()<< std::endl;
|
||||
std::cout << expander << std::endl;
|
||||
std::cout << expander.toStdString() << std::endl;
|
||||
print(line.value());
|
||||
std::cout << expander << std::endl;
|
||||
std::cout << std::endl << expander.toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void QuasarAppUtils::Help::print(const QString &key, const QString &value) {
|
||||
void QuasarAppUtils::Help::print(const QString &key, const QString &value, int keyLength) {
|
||||
|
||||
int keyLength = key.size() + 2;
|
||||
std::cout << key.toStdString() << ": ";
|
||||
auto diffExpander = QString(keyLength - key.size(), ' ');
|
||||
std::cout << SECTION_MARGIN << key.toStdString() << diffExpander.toStdString() << ":";
|
||||
|
||||
std::string expander(' ', keyLength);
|
||||
QString expander(keyLength + SectionMargin, ' ');
|
||||
auto words = value.split(" ");
|
||||
|
||||
int currentLength = keyLength;
|
||||
for (const auto& word : words) {
|
||||
if (currentLength < MAX_LENGTH) {
|
||||
if (currentLength + 2 + word.size() < MAX_LENGTH) {
|
||||
std::cout << word.toStdString();
|
||||
currentLength += 2 + word.size();
|
||||
} else {
|
||||
std::cout << std::endl << expander << ": ";
|
||||
std::cout << std::endl << expander.toStdString() << ":";
|
||||
currentLength = keyLength;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ typedef QHash<QString, Options> Charters;
|
||||
* @param key - option name
|
||||
* @param value - description of option
|
||||
*/
|
||||
void print(const QString& key, const QString& value);
|
||||
void print(const QString& key, const QString& value, int keyLength);
|
||||
|
||||
/**
|
||||
* @brief print = help Charter
|
||||
|
Loading…
x
Reference in New Issue
Block a user