#!/usr/bin/env ruby # vim: set filetype=ruby: $: << File.expand_path("../../lib/", __FILE__) require 'yaml' require 'readline' require 'bindot2braillegraph' FONT_TABLE = YAML.load( open(File.expand_path('../../fontdata/misaki.yml', __FILE__)).read + open(File.expand_path('../../fontdata/kanji.yml', __FILE__)).read) def convert_text(input) input.split(//).reject { |c| FONT_TABLE[c].nil? } .map { |c| bindot = FONT_TABLE[c].split("\n") { width: bindot[0].size, height: bindot.size, bindot: bindot.join } } .map { |data| BinDot2BrailleGraph.convert(data[:width], data[:height], data[:bindot]) } .each { |c| print c[0].join } .tap { puts } .each { |c| print c[1].join } .tap { puts } end def interactive begin while input = Readline.readline('YAPPY> ') case input when 'quit', 'exit' break else convert_text(input) end end rescue Interrupt puts "^C" retry end end if File.pipe?(STDIN) || File.select([STDIN], [], [], 0) != nil then STDIN.each_line do |line| convert_text(line) end else interactive end