Sha256: ee8a4450bc334c81c29a3e0d6d1da06ce6159aadc76580e43ceee89975652818

Contents?: true

Size: 1 KB

Versions: 83

Compression:

Stored size: 1 KB

Contents

require_relative "column_printer"
require_relative "terminal"

class Thor
  module Shell
    class WrappedPrinter < ColumnPrinter
      def print(message)
        width = Terminal.terminal_width - @indent
        paras = message.split("\n\n")

        paras.map! do |unwrapped|
          words = unwrapped.split(" ")
          counter = words.first.length
          words.inject do |memo, word|
            word = word.gsub(/\n\005/, "\n").gsub(/\005/, "\n")
            counter = 0 if word.include? "\n"
            if (counter + word.length + 1) < width
              memo = "#{memo} #{word}"
              counter += (word.length + 1)
            else
              memo = "#{memo}\n#{word}"
              counter = word.length
            end
            memo
          end
        end.compact!

        paras.each do |para|
          para.split("\n").each do |line|
            stdout.puts line.insert(0, " " * @indent)
          end
          stdout.puts unless para == paras.last
        end
      end
    end
  end
end

Version data entries

83 entries across 83 versions & 7 rubygems

Version Path
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.94 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.93 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.91 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.90 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.89 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.88 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.87 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.86 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.85 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.84 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.83 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.82 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.81 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.80 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.79 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb
harbr-0.1.78 vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/shell/wrapped_printer.rb