Sha256: 11073f0104b18fd28111851303b0ad20825afc106da0c001c81236def5f29e03

Contents?: true

Size: 1.01 KB

Versions: 64

Compression:

Stored size: 1.01 KB

Contents

require_relative "column_printer"
require_relative "terminal"

class Bundler::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

64 entries across 64 versions & 4 rubygems

Version Path
rubygems-update-3.6.6 bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
bundler-2.6.6 lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
rubygems-update-3.6.5 bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
bundler-2.6.5 lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
rubygems-update-3.6.4 bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
bundler-2.6.4 lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/bundler-2.5.21/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
rubygems-update-3.6.3 bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
bundler-2.6.3 lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
rubygems-update-3.6.2 bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
bundler-2.6.2 lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
rubygems-update-3.6.1 bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
bundler-2.6.1 lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
rubygems-update-3.6.0 bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
bundler-2.6.0 lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
rubygems-update-3.5.23 bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
bundler-2.5.23 lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
rubygems-update-3.5.22 bundler/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb
bundler-2.5.22 lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb