From 0a64c2b8a42d766e5a893fcab2d4573b33cca74f Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 8 Mar 2022 18:38:25 +0100 Subject: Make error and info messages visually uniform (#2939) * initial work to add msg formatter * wip * replace AMREX_ALWAYS_ASSERT_WITH_MESSAGE with WarpX equivalent --- Source/Utils/WarnManager.cpp | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) (limited to 'Source/Utils/WarnManager.cpp') diff --git a/Source/Utils/WarnManager.cpp b/Source/Utils/WarnManager.cpp index 4e8332631..973e7ca28 100644 --- a/Source/Utils/WarnManager.cpp +++ b/Source/Utils/WarnManager.cpp @@ -8,6 +8,7 @@ #include "WarnManager.H" #include "MsgLogger/MsgLogger.H" +#include "WarpXUtil.H" #include @@ -201,39 +202,12 @@ WarnManager::msg_formatter( const auto prefix = "*" + std::string(tab_size, ' '); const auto prefix_length = static_cast(prefix.length()); - std::stringstream ss_out; - std::stringstream ss_msg{msg}; - - std::string line; - std::string word; - - while(std::getline(ss_msg, line,'\n')){ - ss_out << prefix; + const auto wrapped_text = WarpXUtilStr::automatic_text_wrap( + msg, line_size-prefix_length); - std::stringstream ss_line{line}; - int counter = prefix_length; - - while (ss_line >> word){ - const auto wlen = static_cast(word.length()); - - if(counter == prefix_length){ - ss_out << word; - counter += wlen; - } - else{ - if (counter + wlen < line_size){ - ss_out << " " << word; - counter += (wlen+1); - } - else{ - ss_out << "\n" << prefix << word; - counter = prefix_length + wlen; - } - } - } - - ss_out << '\n'; - } + std::stringstream ss_out; + for (const auto& line : wrapped_text) + ss_out << prefix << line << "\n"; return ss_out.str(); } -- cgit v1.2.3