From 7fc902c4b46db9cde267ffb1348a159fc8e7d54d Mon Sep 17 00:00:00 2001 From: Joshua Russo Date: Mon, 22 Jun 2015 15:09:51 -0400 Subject: [PATCH] Added the ability to put line feeds and/or carriage returns in descriptions --- src/CommandLine/Text/HelpText.cs | 54 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/CommandLine/Text/HelpText.cs b/src/CommandLine/Text/HelpText.cs index 91e0c771..2575b662 100644 --- a/src/CommandLine/Text/HelpText.cs +++ b/src/CommandLine/Text/HelpText.cs @@ -642,39 +642,43 @@ private HelpText AddOption(string requiredWord, int maxLength, OptionSpecificati { do { - var wordBuffer = 0; - var words = optionHelpText.Split(new[] { ' ' }); - for (var i = 0; i < words.Length; i++) + var paragraphs = optionHelpText.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var paragraph in paragraphs) { - if (words[i].Length < (widthOfHelpText - wordBuffer)) + var wordBuffer = 0; + var words = paragraph.Split(new[] { ' ' }); + for (var i = 0; i < words.Length; i++) { - this.optionsHelp.Append(words[i]); - wordBuffer += words[i].Length; - if ((widthOfHelpText - wordBuffer) > 1 && i != words.Length - 1) + if (words[i].Length < (widthOfHelpText - wordBuffer)) { - this.optionsHelp.Append(" "); - wordBuffer++; + this.optionsHelp.Append(words[i]); + wordBuffer += words[i].Length; + if ((widthOfHelpText - wordBuffer) > 1 && i != words.Length - 1) + { + this.optionsHelp.Append(" "); + wordBuffer++; + } + } + else if (words[i].Length >= widthOfHelpText && wordBuffer == 0) + { + this.optionsHelp.Append(words[i].Substring(0, widthOfHelpText)); + wordBuffer = widthOfHelpText; + break; + } + else + { + break; } } - else if (words[i].Length >= widthOfHelpText && wordBuffer == 0) - { - this.optionsHelp.Append(words[i].Substring(0, widthOfHelpText)); - wordBuffer = widthOfHelpText; - break; - } - else + + optionHelpText = optionHelpText.Substring( + Math.Min(wordBuffer, optionHelpText.Length)).Trim(); + if (optionHelpText.Length > 0) { - break; + this.optionsHelp.Append(Environment.NewLine); + this.optionsHelp.Append(new string(' ', maxLength + 6)); } } - - optionHelpText = optionHelpText.Substring( - Math.Min(wordBuffer, optionHelpText.Length)).Trim(); - if (optionHelpText.Length > 0) - { - this.optionsHelp.Append(Environment.NewLine); - this.optionsHelp.Append(new string(' ', maxLength + 6)); - } } while (optionHelpText.Length > widthOfHelpText); }