Skip to content

Commit

Permalink
Rename all the other instances of the old names
Browse files Browse the repository at this point in the history
  • Loading branch information
Dru Nelson committed Oct 10, 2012
1 parent 4bcede7 commit 9875df4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 46 deletions.
11 changes: 10 additions & 1 deletion Readme.md
Expand Up @@ -28,7 +28,16 @@ Into this:

</script>

There are examples in the repo that demonstrate this as well as a require.js and jQuery example.
## Node Example

var ansi_up = require('ansi_up');

var txt = "\n\n\033[1;33;40m 33;40 \033[1;33;41m 33;41 \033[1;33;42m 33;42 \033[1;33;43m 33;43 \033[1;33;44m 33;44 \033[1;33;45m 33;45 \033[1;33;46m 33;46 \033[1m\033[0\n\n\033[1;33;42m >> Tests OK\n\n"

var html = ansi_up.ansi_to_html(txt);


There are examples in the repo that demonstrate an AMD/require.js/ jQuery example as well as a simple browser example.

## Installation

Expand Down
34 changes: 17 additions & 17 deletions ansi_up.js
@@ -1,12 +1,12 @@
// ansi2html.js
// ansi_up.js
// version : 1.0.0
// author : Dru Nelson
// license : MIT
// http://github.com/drudru/ansi2html
// http://github.com/drudru/ansi_up

(function (Date, undefined) {

var ansi2html,
var ansi_up,
VERSION = "1.0.0",

// check for nodeJS
Expand All @@ -18,26 +18,26 @@
["85,85,85", "255, 85, 85", "0, 255, 0", "255, 255, 85", "85, 85, 255", "255, 85, 255", "85, 255, 255", "255,255,255" ]
];

function Ansi2HTML() {
function Ansi_Up() {
this.fg = this.bg = null;
this.bright = 0;
}

Ansi2HTML.prototype.escape_for_html = function (txt) {
Ansi_Up.prototype.escape_for_html = function (txt) {
return txt.replace(/[&<>]/gm, function(str) {
if (str == "&") return "&amp;";
if (str == "<") return "&lt;";
if (str == ">") return "&gt;";
});
};

Ansi2HTML.prototype.linkify = function (txt) {
Ansi_Up.prototype.linkify = function (txt) {
return txt.replace(/(https?:\/\/[^\s]+)/gm, function(str) {
return "<a href=\"" + str + "\">" + str + "</a>";
});
};

Ansi2HTML.prototype.ansi_to_html = function (txt) {
Ansi_Up.prototype.ansi_to_html = function (txt) {

var data4 = txt.split(/\033\[/);

Expand All @@ -63,7 +63,7 @@
return escaped_data;
};

Ansi2HTML.prototype.process_chunk = function (text) {
Ansi_Up.prototype.process_chunk = function (text) {

// Do proper handling of sequences (aka - injest vi split(';') into state machine
//match,codes,txt = text.match(/([\d;]+)m(.*)/m);
Expand Down Expand Up @@ -104,40 +104,40 @@
};

// Module exports
ansi2html = {
ansi_up = {

escape_for_html: function (txt) {
var a2h = new Ansi2HTML();
var a2h = new Ansi_Up();
return a2h.escape_for_html(txt);
},

linkify: function (txt) {
var a2h = new Ansi2HTML();
var a2h = new Ansi_Up();
return a2h.linkify(txt);
},

ansi_to_html: function (txt) {
var a2h = new Ansi2HTML();
var a2h = new Ansi_Up();
return a2h.ansi_to_html(txt);
},

ansi_to_html_obj: function () {
return new Ansi2HTML();
return new Ansi_Up();
}
};

// CommonJS module is defined
if (hasModule) {
module.exports = ansi2html;
module.exports = ansi_up;
}
/*global ender:false */
if (typeof window !== 'undefined' && typeof ender === 'undefined') {
window.ansi2html = ansi2html;
window.ansi_up = ansi_up;
}
/*global define:false */
if (typeof define === "function" && define.amd) {
define("ansi2html", [], function () {
return ansi2html;
define("ansi_up", [], function () {
return ansi_up;
});
}
})(Date);
1 change: 0 additions & 1 deletion examples/ansi2html.js

This file was deleted.

1 change: 1 addition & 0 deletions examples/ansi_up.js
4 changes: 2 additions & 2 deletions examples/browser.html
Expand Up @@ -12,12 +12,12 @@
<body>
<pre id="console"></pre>
</body>
<script src="../ansi2html.js" type="text/javascript"></script>
<script src="../ansi_up.js" type="text/javascript"></script>
<script type="text/javascript">

var txt = "\n\n\033[1;33;40m 33;40 \033[1;33;41m 33;41 \033[1;33;42m 33;42 \033[1;33;43m 33;43 \033[1;33;44m 33;44 \033[1;33;45m 33;45 \033[1;33;46m 33;46 \033[1m\033[0\n\n\033[1;33;42m >> Tests OK\n\n"

var html = ansi2html.ansi_to_html(txt);
var html = ansi_up.ansi_to_html(txt);

var cdiv = document.getElementById("console");

Expand Down
2 changes: 1 addition & 1 deletion examples/main.js
@@ -1,4 +1,4 @@
require(['ansi2html',"/examples/jquery-1.7.2.min.js"], function(a2h) {
require(['ansi_up',"/examples/jquery-1.7.2.min.js"], function(a2h) {

var txt = "\n\n\033[1;33;40m 33;40 \033[1;33;41m 33;41 \033[1;33;42m 33;42 \033[1;33;43m 33;43 \033[1;33;44m 33;44 \033[1;33;45m 33;45 \033[1;33;46m 33;46 \033[1m\033[0\n\n\033[1;33;42m >> Tests OK\n\n"

Expand Down
10 changes: 5 additions & 5 deletions package.json
@@ -1,18 +1,18 @@
{
"name": "ansi2html",
"name": "ansi_up",
"version": "1.0.0",
"description": "Convert ansi sequences in strings to HTML spans",
"description": "Convert ansi sequences in strings to colorful HTML",
"keywords": ["ansi", "html"],
"author": "drudru <drudru@gmail.com>",
"main": "./ansi2html.js",
"main": "./ansi_up.js",
"repository" :
{
"type" : "git",
"url" : "git://github.com/drudru/ansi2html.git"
"url" : "git://github.com/drudru/ansi_up.git"
},
"bugs" :
{
"url" : "http://github.com/drudru/ansi2html/issues"
"url" : "http://github.com/drudru/ansi_up/issues"
},
"engines":
{
Expand Down
38 changes: 19 additions & 19 deletions test/ansi_up-test.js
@@ -1,8 +1,8 @@
var ansi2html = require('../ansi2html');
var ansi_up = require('../ansi_up');

var should = require('should');

describe('ansi2html', function() {
describe('ansi_up', function() {

describe('escape_for_html', function() {

Expand All @@ -13,7 +13,7 @@ describe('ansi2html', function() {
var start = "&";
var expected = "&amp;";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -22,7 +22,7 @@ describe('ansi2html', function() {
var start = "abcd&efgh";
var expected = "abcd&amp;efgh";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -31,7 +31,7 @@ describe('ansi2html', function() {
var start = " & & ";
var expected = " &amp; &amp; ";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -40,7 +40,7 @@ describe('ansi2html', function() {
var start = " &amp; ";
var expected = " &amp;amp; ";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -53,7 +53,7 @@ describe('ansi2html', function() {
var start = "<";
var expected = "&lt;";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -62,7 +62,7 @@ describe('ansi2html', function() {
var start = "abcd<efgh";
var expected = "abcd&lt;efgh";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -71,7 +71,7 @@ describe('ansi2html', function() {
var start = " < < ";
var expected = " &lt; &lt; ";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -84,7 +84,7 @@ describe('ansi2html', function() {
var start = ">";
var expected = "&gt;";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -93,7 +93,7 @@ describe('ansi2html', function() {
var start = "abcd>efgh";
var expected = "abcd&gt;efgh";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -102,7 +102,7 @@ describe('ansi2html', function() {
var start = " > > ";
var expected = " &gt; &gt; ";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -115,7 +115,7 @@ describe('ansi2html', function() {
var start = "<&>/\\'\"";
var expected = "&lt;&amp;&gt;/\\'\"";

var l = ansi2html.escape_for_html(start);
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});

Expand All @@ -130,7 +130,7 @@ describe('ansi2html', function() {
var start = "http://link.to/me";
var expected = "<a href=\"http://link.to/me\">http://link.to/me</a>";

var l = ansi2html.linkify(start);
var l = ansi_up.linkify(start);
l.should.eql(expected);
});

Expand All @@ -146,7 +146,7 @@ describe('ansi2html', function() {

var expected = "<span style=\"color:rgb(0, 187, 0)\"> " + fg + " </span>";

var l = ansi2html.ansi_to_html(start);
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});

Expand All @@ -159,7 +159,7 @@ describe('ansi2html', function() {

var expected = "<span style=\"color:rgb(0, 187, 0)\"> " + fg + " </span>";

var l = ansi2html.ansi_to_html(start);
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});

Expand All @@ -171,7 +171,7 @@ describe('ansi2html', function() {

var expected = "<span style=\"color:rgb(0, 255, 0)\"> " + attr + ";" + fg + " </span>";

var l = ansi2html.ansi_to_html(start);
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});

Expand All @@ -184,7 +184,7 @@ describe('ansi2html', function() {

var expected = "<span style=\"color:rgb(255, 255, 85);background-color:rgb(0, 187, 0)\"> " + attr + ";" + bg + ";" + fg + " </span>";

var l = ansi2html.ansi_to_html(start);
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});

Expand All @@ -197,7 +197,7 @@ describe('ansi2html', function() {

var expected = "\n <span style=\"color:rgb(0, 187, 0)\"> " + fg + " </span> \n <span style=\"background-color:rgb(0, 187, 0)\"> " + bg + " </span> \n zimpper ";

var l = ansi2html.ansi_to_html(start);
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});

Expand Down

0 comments on commit 9875df4

Please sign in to comment.