diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index 9cfb74c8d3..dcebbde184 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -36,15 +36,17 @@ module Formatter # Wraps text to fit within a given number of columns using regular expressions that: # # 1. convert hard-wrapped paragraphs to a single line - # 2. find any option descriptions longer than a pre-set length and wrap between words + # 2. add line break and indent to subcommand descriptions + # 3. find any option descriptions longer than a pre-set length and wrap between words # with a hanging indent, without breaking any words that overflow - # 3. wrap any remaining description lines that need wrapping with the same indent - # 4. wrap all lines to the given width. + # 4. wrap any remaining description lines that need wrapping with the same indent + # 5. wrap all lines to the given width. # @see https://macromates.com/blog/2006/wrapping-text-with-regular-expressions/ def wrap(s, width = 172) desc = OPTION_DESC_WIDTH indent = width - desc s.gsub(/(?<=\S) *\n(?=\S)/, " ") + .gsub(/([`>)\]]:) /, "\\1\n ") .gsub(/^( +-.+ +(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n" + " " * indent) .gsub(/^( {#{indent}}(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n" + " " * indent) .gsub(/(.{1,#{width}})( +|$)\n?/, "\\1\n")