class Branding::Canvas

Attributes

cols[R]
height[R]
rows[R]
width[R]

Public Class Methods

new(width: 0, height: 0) click to toggle source
# File lib/branding/canvas.rb, line 15
def initialize(width: 0, height: 0)
  @width = width
  @height = height
  @rows, @cols = self.class.terminal_size
  @pixel_buffer = []
end
terminal_size() click to toggle source
# File lib/branding/canvas.rb, line 7
def self.terminal_size
  # TODO: make sure we can get this on linux

  `stty size`.split.map(&:to_i)
rescue
  [40, 100]
end

Public Instance Methods

load(pixels, algo: :normal) click to toggle source
# File lib/branding/canvas.rb, line 22
def load(pixels, algo: :normal)
  case algo
  when :normal
    klass = Pixel
  when :hires
    klass = Pixel2x
  when :hicolor
    raise 'Hi-Color coming soon!'
  else
    raise "Unknown pixel algo `#{algo}`"
  end

  klass.load_strategy(pixels, width: width, height: height) do |pixel|
    @pixel_buffer << pixel
  end
end
max_width() click to toggle source
# File lib/branding/canvas.rb, line 49
def max_width
  @max_width ||= [@width, @cols].min
end
print() click to toggle source