From bb034f4c54d02e9297355f88bbc640476e2bf2b1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 16 Mar 2026 16:28:16 +0100 Subject: [PATCH 1/4] :bug: :art: resolv bug & Improve format of the code. --- src/coreComponents/common/format/LogPart.hpp | 31 +++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/coreComponents/common/format/LogPart.hpp b/src/coreComponents/common/format/LogPart.hpp index d4223c008b0..f69729b25bc 100644 --- a/src/coreComponents/common/format/LogPart.hpp +++ b/src/coreComponents/common/format/LogPart.hpp @@ -143,7 +143,7 @@ class LogPart /// minimal length of a log part size_t m_minWidth = 100; /// maximal length of a log part - size_t m_maxWidth = SIZE_MAX; + size_t m_maxWidth = 100; /// margin (left and right) between all descriptions and the log part borders static constexpr size_t m_borderMargin = 2; /// numbers of character used for the border @@ -194,30 +194,33 @@ void LogPart::addDescriptionBySection( Description & description, FormattedDescr string_view name, Args const &... args ) { stdVector< string > values; - size_t & maxValueSize = formattedDescription.m_maxValueWidth; - size_t & maxNameSize = formattedDescription.m_maxNameWidth; + size_t & formattedDescriptionMaxWidth = formattedDescription.m_maxValueWidth; + size_t & formattedDescriptionNameWidth = formattedDescription.m_maxNameWidth; ( [&] { static_assert( has_formatter_v< decltype(args) >, "Argument passed cannot be converted to string" ); string const value = GEOS_FMT( "{}", args ); - stdVector< string_view > splitValues = divideLines< string_view >( maxValueSize, value ); - values.insert( values.end(), splitValues.begin(), splitValues.end() ); + stdVector< string_view > dividedDescriptionValues = + divideLines< string_view >( formattedDescriptionMaxWidth, value ); + values.insert( values.end(), dividedDescriptionValues.begin(), dividedDescriptionValues.end() ); } (), ...); description.m_values.push_back( values ); - size_t lineWidth = 0; - stdVector< string > nameDivided = divideLines< string >( lineWidth, name ); - if( lineWidth == 0 ) - lineWidth = name.size(); - maxNameSize = std::max( maxNameSize, lineWidth ); + size_t nameWidth = 0; + stdVector< string > nameLines = divideLines< string >( nameWidth, name ); + if( nameWidth == 0 ) + nameWidth = name.size(); + formattedDescriptionNameWidth = std::max( formattedDescriptionNameWidth, nameWidth ); - description.m_names.push_back( nameDivided ); + description.m_names.push_back( nameLines ); - size_t const formattingCharSize = m_nbBorderChar * 2 + m_borderMargin * 2; - size_t const currentTotalWidth = maxNameSize + maxValueSize + formattingCharSize; - m_width = std::max( m_width, currentTotalWidth ); + size_t const totalDecorationWidth = m_nbBorderChar * 2 + m_borderMargin * 2; + size_t const logPartTotalWidth = formattedDescriptionNameWidth + + formattedDescriptionMaxWidth + + totalDecorationWidth; + m_width = std::max( m_width, logPartTotalWidth ); m_width = std::max( m_width, formattedDescription.m_title.size()); } From 441aaeeabc44e23df35ede765ede8d96b18e49c7 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 16 Mar 2026 16:28:34 +0100 Subject: [PATCH 2/4] :art: Improve format of the code. --- src/coreComponents/common/format/LogPart.cpp | 38 ++++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/coreComponents/common/format/LogPart.cpp b/src/coreComponents/common/format/LogPart.cpp index a9ce3c69da6..d396d7c4a6d 100644 --- a/src/coreComponents/common/format/LogPart.cpp +++ b/src/coreComponents/common/format/LogPart.cpp @@ -70,34 +70,32 @@ void LogPart::formatDescriptions( LogPart::Description & description, stdVector< string > & formattedLines = formattedDescription.m_lines; size_t const borderSpaceWidth = m_nbBorderChar * 2 + m_borderMargin * 2; - size_t const formattingCharSize = borderSpaceWidth; + size_t const decorationWidth = borderSpaceWidth; size_t & maxNameSize = formattedDescription.m_maxNameWidth; size_t & maxValueSize = formattedDescription.m_maxValueWidth; formattedLines.reserve( description.m_names.size() * 2 ); - /// clamp - m_width = std::min( m_maxWidth, std::max( m_minWidth, m_width )); - + m_width = std::clamp( m_width, m_minWidth, m_maxWidth ); for( size_t idxName = 0; idxName < description.m_names.size(); idxName++ ) { - auto const & nonFormattedNames = description.m_names[idxName]; - auto const & nonFormattedValues = description.m_values[idxName]; + auto const & rawName = description.m_names[idxName]; + auto const & rawValues = description.m_values[idxName]; // Format name with no values associated - if( nonFormattedValues.empty()) + if( rawValues.empty()) { - size_t maxLineLength = m_width - borderSpaceWidth; - auto wrappedNames = stringutilities::wrapTextToMaxLength( nonFormattedNames, maxLineLength ); + size_t availableWidth = m_width - borderSpaceWidth; + auto wrappedNames = stringutilities::wrapTextToMaxLength( rawName, availableWidth ); for( auto & name : wrappedNames ) { auto const currMaxNameSize = std::max( name.size(), maxNameSize ); - if( currMaxNameSize + formattingCharSize < m_width ) + if( currMaxNameSize + decorationWidth < m_width ) { // append space at the end of name if needed name.reserve( m_width - borderSpaceWidth ); - name.append( std::string( m_width - currMaxNameSize - formattingCharSize, ' ' )); + name.append( std::string( m_width - currMaxNameSize - decorationWidth, ' ' )); } formattedLines.push_back( name ); } @@ -105,25 +103,25 @@ void LogPart::formatDescriptions( LogPart::Description & description, } // Format name with values assiociated - size_t maxLineLength = m_width - maxNameSize - formattingCharSize - m_delimiter.size(); - auto wrappedValues = stringutilities::wrapTextToMaxLength( nonFormattedValues, maxLineLength ); + size_t availableWidthForValues = m_width - maxNameSize - decorationWidth - m_delimiter.size(); + auto wrappedValues = stringutilities::wrapTextToMaxLength( rawValues, availableWidthForValues ); // format name - stdVector< string > formatNames {nonFormattedNames}; + stdVector< string > formatNames {rawName}; for( size_t idxSubName = 0; idxSubName < formatNames.size(); idxSubName++ ) { - size_t const spaces = idxSubName < wrappedValues.size() ? - maxNameSize - formatNames[idxSubName].size() : - m_width - formatNames[idxSubName].size() - formattingCharSize; + size_t const paddingNeeded = idxSubName < wrappedValues.size() ? + maxNameSize - formatNames[idxSubName].size() : + m_width - formatNames[idxSubName].size() - decorationWidth; // append space at the end of name if needed - formatNames[idxSubName].reserve( formatNames[idxSubName].size() + spaces ); - formatNames[idxSubName].append( spaces, ' ' ); + formatNames[idxSubName].reserve( formatNames[idxSubName].size() + paddingNeeded ); + formatNames[idxSubName].append( paddingNeeded, ' ' ); } size_t const lineCount = std::max( formatNames.size(), wrappedValues.size()); // format values - size_t const minValueSizeRequired = m_width - maxNameSize - formattingCharSize - m_delimiter.size(); + size_t const minValueSizeRequired = m_width - maxNameSize - decorationWidth - m_delimiter.size(); for( auto & wrappedValue : wrappedValues ) { wrappedValue.reserve( minValueSizeRequired ); From edbb7f4b2ee5c1d3a45e88e3fa70ebecbb9f5882 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 18 Mar 2026 14:50:12 +0100 Subject: [PATCH 3/4] :green_heart: test removing std::clamp --- src/coreComponents/common/format/LogPart.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coreComponents/common/format/LogPart.cpp b/src/coreComponents/common/format/LogPart.cpp index d396d7c4a6d..0907b881aaa 100644 --- a/src/coreComponents/common/format/LogPart.cpp +++ b/src/coreComponents/common/format/LogPart.cpp @@ -76,7 +76,9 @@ void LogPart::formatDescriptions( LogPart::Description & description, formattedLines.reserve( description.m_names.size() * 2 ); - m_width = std::clamp( m_width, m_minWidth, m_maxWidth ); + /// clamp + m_width = std::min( m_maxWidth, std::max( m_minWidth, m_width )); + for( size_t idxName = 0; idxName < description.m_names.size(); idxName++ ) { auto const & rawName = description.m_names[idxName]; From 1586f2e5cea78d4fe77a5cd67b3f73c39b18f5a3 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 19 Mar 2026 14:41:44 +0100 Subject: [PATCH 4/4] :bug: use LvArray method --- src/coreComponents/common/format/LogPart.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/common/format/LogPart.cpp b/src/coreComponents/common/format/LogPart.cpp index 0907b881aaa..1f3dac85297 100644 --- a/src/coreComponents/common/format/LogPart.cpp +++ b/src/coreComponents/common/format/LogPart.cpp @@ -61,7 +61,7 @@ void LogPart::setMaxWidth( size_t const & maxWidth ) double clamp( double v, double min, double max ) { - return std::min( max, std::max( min, v )); + return LvArray::math::min( max, LvArray::math::max( min, v )); } void LogPart::formatDescriptions( LogPart::Description & description, @@ -76,8 +76,7 @@ void LogPart::formatDescriptions( LogPart::Description & description, formattedLines.reserve( description.m_names.size() * 2 ); - /// clamp - m_width = std::min( m_maxWidth, std::max( m_minWidth, m_width )); + m_width = clamp( m_maxWidth, m_minWidth, m_width ); for( size_t idxName = 0; idxName < description.m_names.size(); idxName++ ) {