Sha256: 1c77ee52321ec2919365854298cad3d53248f6e6d7700aac49af651e8987f21d

Contents?: true

Size: 947 Bytes

Versions: 1

Compression:

Stored size: 947 Bytes

Contents

require 'v8'


module Asciimo
  VERSION = "0.1.0"
  HOME = File.join(File.dirname(__FILE__), "..", "ext", "asciimo")
  LIB = File.join(HOME, "lib")
  FONTS = File.join(HOME, "fonts")
  
  def text(font_name, text, color = nil)
    cxt = V8::Context.new
    asciimo = cxt.scope
    cxt.load("#{LIB}/asciimo.js")
    cxt.load("#{LIB}/colors.js")
    font = File.read("#{FONTS}/#{font_name}")
    asciimo.loadFont(font)
    art = asciimo.createLargeText(text)
    return color ? asciimo.stylize(art, color) : art
  end

  def fonts
    cxt = V8::Context.new
    cxt.load("#{LIB}/fonts.js")
    cxt.scope.asciimoFonts.to_a
  end

  def colors
    #TODO figure out a way to load this from the JS source.
    [
      'bold',
      'italic',
      'underline',
      'yellow',
      'cyan',
      'white',
      'green',
      'red',
      'grey',
      'blue',
      'magenta',
      'inverse'
    ]
  end

  module_function :text, :colors, :fonts
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
asciimo-0.1.0 lib/asciimo.rb