From f1f010fdb2edabf631e4aba6f2b9c23a3393f5fe Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 15 Oct 2023 03:38:32 -0400 Subject: [PATCH] Change program options to use streaming wrap, not string wrap. --- ProgramOptions.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ProgramOptions.cpp b/ProgramOptions.cpp index c075ae1..46b70a7 100644 --- a/ProgramOptions.cpp +++ b/ProgramOptions.cpp @@ -190,11 +190,15 @@ namespace Alepha::Cavorite ::detail:: program_options } } + const std::size_t width= getConsoleWidth(); + std::cout << StartWrap{ width }; std::cout << "Options:" << std::endl << std::endl; + std::cout << EndWrap; // Inspect and print each option. for( const auto &[ name, def ]: programOptions() ) { + std::cout << StartWrap{ width, alignmentWidth }; const auto &[ _, helpText, defaultBuilder, domains ]= def; // How much unused of the max width there will be const std::size_t padding= alignmentWidth - name.size() - 2; @@ -221,16 +225,17 @@ namespace Alepha::Cavorite ::detail:: program_options // Append the incompatibility text, when we see mutually-exclusive options. substitutionTemplate+= buildIncompatibleHelpText( name, domains, exclusivityMembers ); - const std::string helpString= expandVariables( substitutionTemplate, substitutions, '!' ); - printString( helpString, alignmentWidth ); + std::cout << expandVariables( substitutionTemplate, substitutions, '!' ); + std::cout << EndWrap; std::cout << std::endl; } + // Check for required options, and print a summary of those: if( not requiredOptions().empty() ) for( const auto &[ _, group ]: requiredOptions() ) { - const std::size_t width= getConsoleWidth(); - std::ostringstream oss; + std::ostream &oss= std::cout; + oss << StartWrap{ width }; oss << "At least one of the options in this group are required: "; bool first= true; for( const auto &required: group ) @@ -240,7 +245,7 @@ namespace Alepha::Cavorite ::detail:: program_options oss << '`' << required << '`'; } - std::cout << wordWrap( oss.str(), width ) << std::endl; + oss << std::endl; } } }