Sha256: e2f836ba8ace32090a38309d7e94619a0fdf598224809dbedd17d03c0f35435b

Contents?: true

Size: 1003 Bytes

Versions: 7

Compression:

Stored size: 1003 Bytes

Contents

require 'whirled_peas/utils/formatted_string'
require 'whirled_peas/utils/title_font'

require_relative 'content_dimensions'
require_relative 'content_painter'

module WhirledPeas
  module Graphics
    class TextPainter < ContentPainter
      def paint(canvas, left, top, &block)
        return unless canvas.writable?
        formatting = [*settings.color, *settings.bg_color]
        formatting << Utils::Ansi::BOLD if settings.bold?
        if settings.underline? && settings.title_font.nil?
          formatting << Utils::Ansi::UNDERLINE
        end
        content_lines.each.with_index do |line, index|
          canvas.stroke(left, top + index, line, formatting, &block)
        end
      end

      private

      def content_lines
        @content_lines = if settings.title_font
          Utils::TitleFont.to_s(
            content, settings.title_font
          ).split("\n")
        else
          content.split("\n")
        end
      end
    end
    private_constant :TextPainter
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
whirled_peas-0.13.0 lib/whirled_peas/graphics/text_painter.rb
whirled_peas-0.12.0 lib/whirled_peas/graphics/text_painter.rb
whirled_peas-0.11.1 lib/whirled_peas/graphics/text_painter.rb
whirled_peas-0.11.0 lib/whirled_peas/graphics/text_painter.rb
whirled_peas-0.10.0 lib/whirled_peas/graphics/text_painter.rb
whirled_peas-0.9.1 lib/whirled_peas/graphics/text_painter.rb
whirled_peas-0.9.0 lib/whirled_peas/graphics/text_painter.rb