3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-11-25 15:09:34 +00:00

log_help.cc: Better line splitting

If a word by itself meets the max line length it should only drop to a new line if the current line has content (would previously force an empty line before it).
Include the length of indent when adding a line break (was previously only accounted for on the first line).
This commit is contained in:
Krystine Sherwin 2025-11-17 12:47:50 +13:00
parent e5b9401bf3
commit 5896579066
No known key found for this signature in database

View file

@ -84,6 +84,7 @@ void log_pass_str(const std::string &pass_str, std::string indent_str, bool lead
std::istringstream iss(pass_str); std::istringstream iss(pass_str);
if (leading_newline) if (leading_newline)
log("\n"); log("\n");
bool partial_line = false;
for (std::string line; std::getline(iss, line);) { for (std::string line; std::getline(iss, line);) {
log("%s", indent_str); log("%s", indent_str);
auto curr_len = indent_str.length(); auto curr_len = indent_str.length();
@ -91,13 +92,15 @@ void log_pass_str(const std::string &pass_str, std::string indent_str, bool lead
for (std::string word; std::getline(lss, word, ' ');) { for (std::string word; std::getline(lss, word, ' ');) {
while (word[0] == '`' && word.back() == '`') while (word[0] == '`' && word.back() == '`')
word = word.substr(1, word.length()-2); word = word.substr(1, word.length()-2);
if (curr_len + word.length() >= MAX_LINE_LEN-1) { if (partial_line && curr_len + word.length() >= MAX_LINE_LEN-1) {
curr_len = 0; curr_len = indent_str.length();
log("\n%s", indent_str); log("\n%s", indent_str);
partial_line = false;
} }
if (word.length()) { if (word.length()) {
log("%s ", word); log("%s ", word);
curr_len += word.length() + 1; curr_len += word.length() + 1;
partial_line = true;
} }
} }
log("\n"); log("\n");