Permalink
Browse files

adding code, tests, demo script, package

  • Loading branch information...
1 parent b5c9b93 commit 93f13fc7cb1dbedc4c98eb44c004d4216af4a205 @khrome committed Dec 11, 2012
Showing with 1,043 additions and 0 deletions.
  1. +833 −0 Fonts/Doom.flf
  2. +144 −0 ascii-art.js
  3. +5 −0 demo.js
  4. +31 −0 package.json
  5. +30 −0 test.js
View
833 Fonts/Doom.flf
@@ -0,0 +1,833 @@
+flf2a$ 8 6 14 15 16
+DOOM by Frans P. de Vries <fpv@xymph.iaf.nl> 18 Jun 1996
+based on Big by Glenn Chappell 4/93 -- based on Standard
+figlet release 2.1 -- 12 Aug 1994
+Permission is hereby given to modify this font, as long as the
+modifier's name is placed on a comment line.
+
+Explanation of first line:
+flf2 - "magic number" for file identification
+a - should always be `a', for now
+$ - the "hardblank" -- prints as a blank, but can't be smushed
+8 - height of a character
+6 - height of a character, not including descenders
+14 - max line length (excluding comment lines) + a fudge factor
+15 - default smushmode for this font
+16 - number of comment lines
+
+$@
+$@
+$@
+$@
+$@
+$@
+$@
+$@@
+ _ @
+| |@
+| |@
+| |@
+|_|@
+(_)@
+ @
+ @@
+ _ _ @
+( | )@
+ V V @
+ $ @
+ $ @
+ $ @
+ @
+ @@
+ _ _ @
+ _| || |_ @
+|_ __ _|@
+ _| || |_ @
+|_ __ _|@
+ |_||_| @
+ @
+ @@
+ _ @
+ | | @
+/ __)@
+\__ \@
+( /@
+ |_| @
+ @
+ @@
+ _ __@
+(_) / /@
+ / / @
+ / / @
+ / / _ @
+/_/ (_)@
+ @
+ @@
+ @
+ ___ @
+ ( _ ) @
+ / _ \/\@
+| (_> <@
+ \___/\/@
+ @
+ @@
+ _ @
+( )@
+|/ @
+ $ @
+ $ @
+ $ @
+ @
+ @@
+ __@
+ / /@
+| | @
+| | @
+| | @
+| | @
+ \_\@
+ @@
+__ @
+\ \ @
+ | |@
+ | |@
+ | |@
+ | |@
+/_/ @
+ @@
+ _ @
+ /\| |/\ @
+ \ ` ' / @
+|_ _|@
+ / , . \ @
+ \/|_|\/ @
+ @
+ @@
+ @
+ _ @
+ _| |_ @
+|_ _|@
+ |_| @
+ $ @
+ @
+ @@
+ @
+ @
+ @
+ @
+ _ @
+( )@
+|/ @
+ @@
+ @
+ @
+ ______ @
+|______|@
+ $ @
+ $ @
+ @
+ @@
+ @
+ @
+ @
+ @
+ _ @
+(_)@
+ @
+ @@
+ __@
+ / /@
+ / / @
+ / / @
+ / / @
+/_/ @
+ @
+ @@
+ _____ @
+| _ |@
+| |/' |@
+| /| |@
+\ |_/ /@
+ \___/ @
+ @
+ @@
+ __ @
+/ | @
+`| | @
+ | | @
+_| |_@
+\___/@
+ @
+ @@
+ _____ @
+/ __ \@
+`' / /'@
+ / / @
+./ /___@
+\_____/@
+ @
+ @@
+ _____ @
+|____ |@
+ / /@
+ $ \ \@
+.___/ /@
+\____/ @
+ @
+ @@
+ ___ @
+ / |@
+ / /| |@
+/ /_| |@
+\___ |@
+ |_/@
+ @
+ @@
+ _____ @
+| ___|@
+|___ \ @
+ \ \@
+/\__/ /@
+\____/ @
+ @
+ @@
+ ____ @
+ / ___|@
+/ /___ @
+| ___ \@
+| \_/ |@
+\_____/@
+ @
+ @@
+ ______@
+|___ /@
+ $/ / @
+ / / @
+./ / @
+\_/ @
+ @
+ @@
+ _____ @
+| _ |@
+ \ V / @
+ / _ \ @
+| |_| |@
+\_____/@
+ @
+ @@
+ _____ @
+| _ |@
+| |_| |@
+\____ |@
+.___/ /@
+\____/ @
+ @
+ @@
+ @
+ _ @
+(_)@
+ $ @
+ _ @
+(_)@
+ @
+ @@
+ @
+ _ @
+(_)@
+ $ @
+ _ @
+( )@
+|/ @
+ @@
+ __@
+ / /@
+ / / @
+< < @
+ \ \ @
+ \_\@
+ @
+ @@
+ @
+ ______ @
+|______|@
+ ______ @
+|______|@
+ @
+ @
+ @@
+__ @
+\ \ @
+ \ \ @
+ > >@
+ / / @
+/_/ @
+ @
+ @@
+ ___ @
+|__ \ @
+ ) |@
+ / / @
+ |_| @
+ (_) @
+ @
+ @@
+ @
+ ____ @
+ / __ \ @
+ / / _` |@
+| | (_| |@
+ \ \__,_|@
+ \____/ @
+ @@
+ ___ @
+ / _ \ @
+/ /_\ \@
+| _ |@
+| | | |@
+\_| |_/@
+ @
+ @@
+______ @
+| ___ \@
+| |_/ /@
+| ___ \@
+| |_/ /@
+\____/ @
+ @
+ @@
+ _____ @
+/ __ \@
+| / \/@
+| | @
+| \__/\@
+ \____/@
+ @
+ @@
+______ @
+| _ \@
+| | | |@
+| | | |@
+| |/ / @
+|___/ @
+ @
+ @@
+ _____ @
+| ___|@
+| |__ @
+| __| @
+| |___ @
+\____/ @
+ @
+ @@
+______ @
+| ___|@
+| |_ @
+| _| @
+| | @
+\_| @
+ @
+ @@
+ _____ @
+| __ \@
+| | \/@
+| | __ @
+| |_\ \@
+ \____/@
+ @
+ @@
+ _ _ @
+| | | |@
+| |_| |@
+| _ |@
+| | | |@
+\_| |_/@
+ @
+ @@
+ _____ @
+|_ _|@
+ | | @
+ | | @
+ _| |_ @
+ \___/ @
+ @
+ @@
+ ___ @
+ |_ |@
+ $ | |@
+ | |@
+/\__/ /@
+\____/ @
+ @
+ @@
+ _ __@
+| | / /@
+| |/ / @
+| \ @
+| |\ \@
+\_| \_/@
+ @
+ @@
+ _ @
+| | $ @
+| | $ @
+| | @
+| |____@
+\_____/@
+ @
+ @@
+___ ___@
+| \/ |@
+| . . |@
+| |\/| |@
+| | | |@
+\_| |_/@
+ @
+ @@
+ _ _ @
+| \ | |@
+| \| |@
+| . ` |@
+| |\ |@
+\_| \_/@
+ @
+ @@
+ _____ @
+| _ |@
+| | | |@
+| | | |@
+\ \_/ /@
+ \___/ @
+ @
+ @@
+______ @
+| ___ \@
+| |_/ /@
+| __/ @
+| | @
+\_| @
+ @
+ @@
+ _____ @
+| _ |@
+| | | |@
+| | | |@
+\ \/' /@
+ \_/\_\@
+ @
+ @@
+______ @
+| ___ \@
+| |_/ /@
+| / @
+| |\ \ @
+\_| \_|@
+ @
+ @@
+ _____ @
+/ ___|@
+\ `--. @
+ `--. \@
+/\__/ /@
+\____/ @
+ @
+ @@
+ _____ @
+|_ _|@
+ | | @
+ | | @
+ | | @
+ \_/ @
+ @
+ @@
+ _ _ @
+| | | |@
+| | | |@
+| | | |@
+| |_| |@
+ \___/ @
+ @
+ @@
+ _ _ @
+| | | |@
+| | | |@
+| | | |@
+\ \_/ /@
+ \___/ @
+ @
+ @@
+ _ _ @
+| | | |@
+| | | |@
+| |/\| |@
+\ /\ /@
+ \/ \/ @
+ @
+ @@
+__ __@
+\ \ / /@
+ \ V / @
+ / \ @
+/ /^\ \@
+\/ \/@
+ @
+ @@
+__ __@
+\ \ / /@
+ \ V / @
+ \ / @
+ | | @
+ \_/ @
+ @
+ @@
+ ______@
+|___ /@
+ $/ / @
+ / / @
+./ /___@
+\_____/@
+ @
+ @@
+ ___ @
+| _|@
+| | @
+| | @
+| | @
+| |_ @
+|___|@
+ @@
+__ @
+\ \ @
+ \ \ @
+ \ \ @
+ \ \ @
+ \_\@
+ @
+ @@
+ ___ @
+|_ |@
+ | |@
+ | |@
+ | |@
+ _| |@
+|___|@
+ @@
+ /\ @
+|/\|@
+ $ @
+ $ @
+ $ @
+ $ @
+ @
+ @@
+ @
+ @
+ @
+ @
+ @
+ $ @
+ ______ @
+|______|@@
+ _ @
+( )@
+ \|@
+ $ @
+ $ @
+ $ @
+ @
+ @@
+ @
+ @
+ __ _ @
+ / _` |@
+| (_| |@
+ \__,_|@
+ @
+ @@
+ _ @
+| | @
+| |__ @
+| '_ \ @
+| |_) |@
+|_.__/ @
+ @
+ @@
+ @
+ @
+ ___ @
+ / __|@
+| (__ @
+ \___|@
+ @
+ @@
+ _ @
+ | |@
+ __| |@
+ / _` |@
+| (_| |@
+ \__,_|@
+ @
+ @@
+ @
+ @
+ ___ @
+ / _ \@
+| __/@
+ \___|@
+ @
+ @@
+ __ @
+ / _|@
+| |_ @
+| _|@
+| | @
+|_| @
+ @
+ @@
+ @
+ @
+ __ _ @
+ / _` |@
+| (_| |@
+ \__, |@
+ __/ |@
+ |___/ @@
+ _ @
+| | @
+| |__ @
+| '_ \ @
+| | | |@
+|_| |_|@
+ @
+ @@
+ _ @
+(_)@
+ _ @
+| |@
+| |@
+|_|@
+ @
+ @@
+ _ @
+ (_)@
+ _ @
+ | |@
+ | |@
+ | |@
+ _/ |@
+|__/ @@
+ _ @
+| | @
+| | __@
+| |/ /@
+| < @
+|_|\_\@
+ @
+ @@
+ _ @
+| |@
+| |@
+| |@
+| |@
+|_|@
+ @
+ @@
+ @
+ @
+ _ __ ___ @
+| '_ ` _ \ @
+| | | | | |@
+|_| |_| |_|@
+ @
+ @@
+ @
+ @
+ _ __ @
+| '_ \ @
+| | | |@
+|_| |_|@
+ @
+ @@
+ @
+ @
+ ___ @
+ / _ \ @
+| (_) |@
+ \___/ @
+ @
+ @@
+ @
+ @
+ _ __ @
+| '_ \ @
+| |_) |@
+| .__/ @
+| | @
+|_| @@
+ @
+ @
+ __ _ @
+ / _` |@
+| (_| |@
+ \__, |@
+ | |@
+ |_|@@
+ @
+ @
+ _ __ @
+| '__|@
+| | @
+|_| @
+ @
+ @@
+ @
+ @
+ ___ @
+/ __|@
+\__ \@
+|___/@
+ @
+ @@
+ _ @
+| | @
+| |_ @
+| __|@
+| |_ @
+ \__|@
+ @
+ @@
+ @
+ @
+ _ _ @
+| | | |@
+| |_| |@
+ \__,_|@
+ @
+ @@
+ @
+ @
+__ __@
+\ \ / /@
+ \ V / @
+ \_/ @
+ @
+ @@
+ @
+ @
+__ __@
+\ \ /\ / /@
+ \ V V / @
+ \_/\_/ @
+ @
+ @@
+ @
+ @
+__ __@
+\ \/ /@
+ > < @
+/_/\_\@
+ @
+ @@
+ @
+ @
+ _ _ @
+| | | |@
+| |_| |@
+ \__, |@
+ __/ |@
+ |___/ @@
+ @
+ @
+ ____@
+|_ /@
+ / / @
+/___|@
+ @
+ @@
+ __@
+ / /@
+ | | @
+/ / @
+\ \ @
+ | | @
+ \_\@
+ @@
+ _ @
+| |@
+| |@
+| |@
+| |@
+| |@
+| |@
+|_|@@
+__ @
+\ \ @
+ | | @
+ \ \@
+ / /@
+ | | @
+/_/ @
+ @@
+ /\/|@
+|/\/ @
+ $ @
+ $ @
+ $ @
+ $ @
+ @
+ @@
+ _ _ @
+(_)_(_)@
+ / _ \ @
+/ /_\ \@
+| _ |@
+\_| |_/@
+ @
+ @@
+ _ _ @
+(_)_(_)@
+| _ |@
+| | | |@
+\ \_/ /@
+ \___/ @
+ @
+ @@
+ _ _ @
+(_) (_)@
+| | | |@
+| | | |@
+| |_| |@
+ \___/ @
+ @
+ @@
+ _ _ @
+(_) (_)@
+ __ _ @
+ / _` |@
+| (_| |@
+ \__,_|@
+ @
+ @@
+ _ _ @
+(_) (_)@
+ ___ @
+ / _ \ @
+| (_) |@
+ \___/ @
+ @
+ @@
+ _ _ @
+(_) (_)@
+ _ _ @
+| | | |@
+| |_| |@
+ \__,_|@
+ @
+ @@
+ ___ @
+ / _ \ @
+| | ) |@
+| |< < @
+| | ) |@
+| ||_/ @
+\_| @
+ @@
View
144 ascii-art.js
@@ -0,0 +1,144 @@
+var AsciiArt = {
+ value : 'variant1',
+ valueScales : {
+ variant1 : ' .,:;i1tfLCG08@'.split(''),
+ variant2 : '@%#*+=-:. '.split('').reverse(),
+ variant3 : '#´´¨¨¯¯$$¿0oo¡++=-,. '.split('').reverse(),
+ variant4 : '#WMBRXVYIti+=;:,. '.split('').reverse(),
+ 'ultra-wide' : ('MMMMMMM@@@@@@@WWWWWWWWWBBBBBBBB000000008888888ZZZZZZZZZaZaaaaaa2222222SSS'
+ +'SSSSXXXXXXXXXXX7777777rrrrrrr;;;;;;;;iiiiiiiii:::::::,:,,,,,,......... ').split('').reverse(),
+ wide : '@@@@@@@######MMMBBHHHAAAA&&GGhh9933XXX222255SSSiiiissssrrrrrrr;;;;;;;;:::::::,,,,,,,........ '.split('').reverse(),
+ hatching : '##XXxxx+++===---;;,,... '.split('').reverse(),
+ bits : '# '.split('').reverse(),
+ binary : '01 '.split('').reverse(),
+ greyscale : '"???? '.split('').reverse()
+ },
+ color : ' CGO08@'.split(''),
+ font : 'courier new',
+ fontPath : 'fonts/',
+ invert : false,
+ alpha : false,
+ errorMode : 'console',
+};
+AsciiArt.ansiCodes = function(str, color) {
+ if(!color) return str;
+ if(!this.codes){
+ this.codes = {
+ "off" : '\033[0m',
+ "bold" : '\033[1m',
+ "italic" : '\033[3m',
+ "underline" : '\033[4m',
+ "framed" : '\033[51m',
+ "encircled" : '\033[52m',
+ "overline" : '\033[53m',
+ "blink" : '\033[5m',
+ "inverse" : '\033[7m',
+ "hidden" : '\033[8m',
+ "black" : '\033[30m',
+ "red" : '\033[31m',
+ "green" : '\033[32m',
+ "yellow" : '\033[33m',
+ "blue" : '\033[34m',
+ "magenta" : '\033[35m',
+ "cyan" : '\033[36m',
+ "white" : '\033[37m',
+ "bright_black": '\033[90m',
+ "bright_red" : '\033[91m',
+ "bright_green": '\033[92m',
+ "bright_yellow": '\033[93m',
+ "bright_blue" : '\033[94m',
+ "bright_magenta": '\033[95m',
+ "bright_cyan" : '\033[96m',
+ "bright_white": '\033[97m',
+ "black_bg" : '\033[40m',
+ "red_bg" : '\033[41m',
+ "green_bg" : '\033[42m',
+ "yellow_bg" : '\033[43m',
+ "blue_bg" : '\033[44m',
+ "magenta_bg": '\033[45m',
+ "cyan_bg" : '\033[46m',
+ "white_bg" : '\033[47m'
+ };
+ }
+ var color_attrs = color.split("+");
+ var ansi_str = "";
+ for(var i=0, attr; attr = color_attrs[i]; i++) {
+ ansi_str += this.codes[attr];
+ }
+ ansi_str += str + this.codes["off"];
+ return ansi_str;
+};
+// this code originates with http://github.com/scottgonzalez/figlet-js
+// if that ever makes it to NPM, it will become a dependency
+AsciiArt.Figlet = {
+ fonts: {},
+ fontPath : __dirname+'/Fonts/',
+ parseFont: function(name, fn) {
+ if (AsciiArt.Figlet.fonts[name]) fn(AsciiArt.Figlet.fonts[name]);
+ else AsciiArt.Figlet.loadFont(name, function(defn){
+ AsciiArt.Figlet._parseFont(name, defn, function(font){
+ AsciiArt.Figlet.fonts[name] = font;
+ fn(font);
+ });
+ });
+ },
+ _parseFont: function(name, defn, fn) {
+ var lines = defn.split("\n");
+ var header = lines[0].split(" ");
+ var hardblank = header[0].charAt(header[0].length - 1);
+ var height = +header[1];
+ var comments = +header[5];
+ var font = {
+ defn: lines.slice(comments + 1),
+ hardblank: hardblank,
+ height: height,
+ char: {}
+ };
+ fn(font);
+ },
+ parseChar: function(char, font) {
+ if(char > 122) return;
+ if (char in font.char) return font.char[char];
+ var height = font.height,
+ start = (char - 32) * height,
+ charDefn = [],
+ i;
+ for (i = 0; i < height; i++) {
+ if(!font.defn[start + i]) return;
+ charDefn[i] = font.defn[start + i].replace(/@/g, "")
+ .replace(RegExp("\\" + font.hardblank, "g"), " ");
+ }
+ return font.char[char] = charDefn;
+ },
+ loadFont: function(name, fn) {
+ var fs = require('fs');
+ var fileName = this.fontPath + name+ '.flf';
+ fs.readFile(fileName, 'utf8', function(error, data) {
+ if(error) throw(error);
+ if(data) fn(data);
+ });
+ },
+ preloadDirectory : function(path, callback){
+ //todo
+ },
+ write : function(str, fontName, callback) {
+ AsciiArt.Figlet.parseFont(fontName, function(font) {
+ var chars = {},
+ result = "";
+ for (var i = 0, len = str.length; i < len; i++) {
+ chars[i] = AsciiArt.Figlet.parseChar(str.charCodeAt(i), font);
+ }
+ for (var i = 0, height = chars[0].length; i < height; i++) {
+ for (var j = 0; j < len; j++) {
+ if(chars[j]) result += chars[j][i];
+ }
+ result += "\n";
+ }
+ callback(result, font);
+ });
+ }
+};
+AsciiArt.font = AsciiArt.Figlet.write;
+AsciiArt.style = AsciiArt.ansiCodes;
+//todo: AsciiArt.image
+module.exports = AsciiArt;
View
5 demo.js
@@ -0,0 +1,5 @@
+var art = require('./ascii-art');
+
+art.font('Demo!', 'Doom', function(rendered){
+ console.log(art.style(rendered, 'blue_bg+red+blink+inverse'));
+});
View
31 package.json
@@ -0,0 +1,31 @@
+{
+ "name": "ascii-art",
+ "homepage": "https://github.com/khrome/ascii-art",
+ "version": "0.0.1-alpha",
+ "main": "ascii-art.js",
+ "description": "A package for ansi codes, figlet fonts, and ascii art",
+ "keywords": [
+ "ascii",
+ "figlet",
+ "ansi"
+ ],
+ "author": "Abbey Hawk Sparrow <@khrome> (http://patternweaver.com)",
+ "contributors": [],
+ "bugs": {
+ "url": "https://github.com/khrome/ascii-art/issues"
+ },
+ "license": "MIT",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/khrome/ascii-art.git"
+ },
+ "dependencies": {},
+ "devDependencies": {
+ "mocha": "*",
+ "should": "*"
+ },
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ }
+}
View
30 test.js
@@ -0,0 +1,30 @@
+var should = require("should");
+var art = require('./ascii-art');
+
+describe('AsciiArt', function(){
+ describe('can render', function(){
+
+ var text = 'blargh';
+
+ it('ANSI codes', function(){
+ var rendered = art.ansiCodes(text, 'red+blink+inverse');
+ rendered.should.not.equal(text); //make sure string has been altered
+ });
+
+ it('Figlet font', function(done){
+ art.font(text, 'Doom', function(rendered){
+ var sample =
+ " _ _ _ "+"\n"+
+ "| | | | | | "+"\n"+
+ "| |__ | | __ _ _ __ __ _ | |__ "+"\n"+
+ "| '_ \\ | | / _` || '__| / _` || '_ \\ "+"\n"+
+ "| |_) || || (_| || | | (_| || | | |"+"\n"+
+ "|_.__/ |_| \\__,_||_| \\__, ||_| |_|"+"\n"+
+ " __/ | "+"\n"+
+ " |___/ "+"\n";
+ rendered.should.equal(sample);
+ done();
+ });
+ });
+ });
+});

0 comments on commit 93f13fc

Please sign in to comment.