122std::vector<std::string>
static myformat(
const std::string& prefix,
123 const std::string& headLine,
124 const std::string& message,
125 std::size_t initialPrefixLength = 0) {
127 const size_t prefixLen = prefix.size();
128 const size_t indentCount = prefixLen + 1;
129 const std::string indent(indentCount,
' ');
131 std::vector<std::string> lines;
135 size_t avail = (termWidth >
int(indentCount + 2)) ?
static_cast<std::size_t>(termWidth) - (indentCount + 2) : 20u;
137 auto wrapped =
wrapParagraph(prefix +
" ┬ " + headLine
, avail - (prefix.length() + 2)
);
139 if (wrapped.empty()) {
140 wrapped.push_back(
"");
146 for (
const auto& line : wrapped) {
147 lines.emplace_back((first ?
"" : indent +
"│ ") + line);
153 auto j =
json::parse(message);
155 std::string pretty = j.dump(2);
157 std::istringstream prettyIStringStream(pretty);
159 for (
auto [line, lineNumnber] = std::tuple{std::string(
""), 0}; std::getline(prettyIStringStream, line); lineNumnber++) {
160 if (lineNumnber == 0 && !prettyIStringStream.eof()) {
161 lines.push_back(indent +
"├ " + line);
162 }
else if (prettyIStringStream.eof()) {
163 lines.push_back(indent +
"└ " + line);
165 lines.push_back(indent +
"│ " + line);
168 }
catch (
json::parse_error&) {
172 std::istringstream messageIStringStream(message);
173 std::vector<std::string> allLines;
174 for (std::string line; std::getline(messageIStringStream, line);) {
177 if (wrapped.empty()) {
178 wrapped.push_back(
"");
181 allLines.insert(allLines.end(), wrapped.begin(), wrapped.end());
184 if (!allLines.empty() && allLines.back().empty()) {
189 for (std::size_t lineNumber = 0; lineNumber < allLines.size(); ++lineNumber) {
190 if (lineNumber == 0 && lineNumber + 1 != allLines.size()) {
191 lines.push_back(indent +
"├ " + allLines[lineNumber]);
192 }
else if (lineNumber + 1 == allLines.size()) {
193 lines.push_back(indent +
"└ " + allLines[lineNumber]);
195 lines.push_back(indent +
"│ " + allLines[lineNumber]);
Mqtt(const std::string &connectionName, const std::string &clientId, uint8_t qoSDefault, uint16_t keepAlive, bool cleanSession, const std::string &willTopic, const std::string &willMessage, uint8_t willQoS, bool willRetain, const std::string &username, const std::string &password, const std::list< std::string > &subTopics, const std::string &pubTopic, const std::string &pubMessage, bool pubRetain=false, const std::string &sessionStoreFileName="")
static std::vector< std::string > myformat(const std::string &prefix, const std::string &headLine, const std::string &message, std::size_t initialPrefixLength=0)