From 0acfb4b819e8d535dfe8aafd1ed4e66d5f4fdd53 Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Sat, 18 Apr 2020 12:07:28 -0400 Subject: [PATCH] Add line break and indent to subcommand descriptions --- Library/Homebrew/utils/formatter.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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")