class RETerm::Components::AsciiText

Renders specified text via ascii graphics.

This Component depends on the 'artii' gem.

Public Class Methods

new(args={}) click to toggle source

Initialize the AsciiText component

@param [Hash] args ascii text params @option args [String] :text actual text to render,

default empty string

@option args [String] :font font to use

Calls superclass method RETerm::Component::new
# File lib/reterm/components/ascii_text.rb, line 14
def initialize(args={})
  super
  @text = args[:text] || ""
  @font = args[:font]
end

Public Instance Methods

draw!() click to toggle source
# File lib/reterm/components/ascii_text.rb, line 28
def draw!
  refresh_win
end
requested_cols() click to toggle source
# File lib/reterm/components/ascii_text.rb, line 24
def requested_cols
  lines.max { |l1, l2| l1.size <=> l2.size }.size + 1
end
requested_rows() click to toggle source
# File lib/reterm/components/ascii_text.rb, line 20
def requested_rows
  lines.size + 1
end

Private Instance Methods

atext() click to toggle source
# File lib/reterm/components/ascii_text.rb, line 34
def atext
  @atext ||= begin
    require 'artii'
    art = @font.nil? ? Artii::Base.new :
                       Artii::Base.new(:font => @font)
    art.asciify @text
  end
end
lines() click to toggle source
# File lib/reterm/components/ascii_text.rb, line 43
def lines
  @lines ||= atext.split("\n")
end
refresh_win() click to toggle source
# File lib/reterm/components/ascii_text.rb, line 47
def refresh_win
  y = 1
  lines.each { |t|
    window.mvaddstr(y, 1, t)
    y += 1
  }

  window.refresh
  update_reterm
end