From 7fc902c4b46db9cde267ffb1348a159fc8e7d54d Mon Sep 17 00:00:00 2001 From: Joshua Russo Date: Mon, 22 Jun 2015 15:09:51 -0400 Subject: [PATCH 1/6] 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); } From a3d27b5502f4fa9c17a67ca7f3ee76d65cea5f57 Mon Sep 17 00:00:00 2001 From: Joshua Russo Date: Mon, 22 Jun 2015 15:39:34 -0400 Subject: [PATCH 2/6] Fixed the line feeds in HelpText --- src/CommandLine/Text/HelpText.cs | 72 +++++++++++++++++++------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/src/CommandLine/Text/HelpText.cs b/src/CommandLine/Text/HelpText.cs index 2575b662..63f5b084 100644 --- a/src/CommandLine/Text/HelpText.cs +++ b/src/CommandLine/Text/HelpText.cs @@ -640,50 +640,64 @@ private HelpText AddOption(string requiredWord, int maxLength, OptionSpecificati if (!string.IsNullOrEmpty(optionHelpText)) { - do + var paragraphs = optionHelpText.Split(new[] { '\n', '\r' }); + for (var p = 0; p < paragraphs.Length; p++) { - var paragraphs = optionHelpText.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); - foreach (var paragraph in paragraphs) + var paragraph = paragraphs[p].Trim(); + + if (paragraph.Length > 0) { - var wordBuffer = 0; - var words = paragraph.Split(new[] { ' ' }); - for (var i = 0; i < words.Length; i++) + do { - 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 + + paragraph = paragraph.Substring( + Math.Min(wordBuffer, paragraph.Length)).Trim(); + if (paragraph.Length > 0) { - break; + this.optionsHelp.Append(Environment.NewLine); + this.optionsHelp.Append(new string(' ', maxLength + 6)); } + } + while (paragraph.Length > widthOfHelpText); - 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)); - } + this.optionsHelp.Append(paragraph); + + } + + if (p < paragraphs.Length - 1) + { + this.optionsHelp.Append(Environment.NewLine); + this.optionsHelp.Append(new string(' ', maxLength + 6)); } } - while (optionHelpText.Length > widthOfHelpText); } - this.optionsHelp.Append(optionHelpText); this.optionsHelp.Append(Environment.NewLine); if (this.additionalNewLineAfterOption) { From 90291d4adac54c66585a63cea0a9354f3c194e7a Mon Sep 17 00:00:00 2001 From: Joshua Russo Date: Tue, 23 Jun 2015 15:14:40 -0400 Subject: [PATCH 3/6] added test with line feeds --- CommandLine.sln.DotSettings.user | 49 +++++++++++++++++++ .../CommandLine.Tests.csproj | 2 + src/CommandLine.Tests/Fakes/HelpFakes.cs | 9 ++++ .../Unit/Text/HelpTextTests.cs | 32 ++++++++++++ src/CommandLine.Tests/packages.config | 1 + src/CommandLine/Text/HelpText.cs | 2 +- 6 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 CommandLine.sln.DotSettings.user diff --git a/CommandLine.sln.DotSettings.user b/CommandLine.sln.DotSettings.user new file mode 100644 index 00000000..1df67b37 --- /dev/null +++ b/CommandLine.sln.DotSettings.user @@ -0,0 +1,49 @@ + + False + False + False + True + 1 + 1 + True + FirstAttributeOnSingleLine + OnDifferentLines + $object$_On$event$ + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + $object$_On$event$ + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + True + True \ No newline at end of file diff --git a/src/CommandLine.Tests/CommandLine.Tests.csproj b/src/CommandLine.Tests/CommandLine.Tests.csproj index 78783fd0..290fe047 100644 --- a/src/CommandLine.Tests/CommandLine.Tests.csproj +++ b/src/CommandLine.Tests/CommandLine.Tests.csproj @@ -1,5 +1,6 @@  + @@ -132,6 +133,7 @@ This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. +