🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

consolemark

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consolemark - npm Package Compare versions

Comparing version

to
0.0.2

lib/utils.js

3

Changelog.md
###v0.0.1, 2011-04-14###
1, support basic color tags.
###v0.0.2, 2011-04-14###
1, support all ansi style tag.

92

lib/render.js

@@ -1,62 +0,52 @@

var fs = require('fs'),
path = require('path'),
colors = require('colors');
var fs = require('fs'),
path = require('path'),
colors = require('colors');
var styles = require('../include/meta.js').styles;
var openTags = require('../include/meta.js').openTags;
var closeTags = require('../include/meta.js').closeTags;
var sortMap = require('./utils.js').sortMap,
fillSpaces = require('./utils.js').fillSpaces;
function _hasTag(data) {
openTags.forEach(function(t) {
if (data.match(t)) {
return true;
}
});
var styles = require('../include/meta.js').styles;
var openTags = require('../include/meta.js').openTags;
var closeTags = require('../include/meta.js').closeTags;
return false;
}
function _split(data) {
var content = [], start = 0, end,
color, string, ct;
function _map(data) {
var map = [], start = 0, end, ot, ct, style, i;
openTags.forEach(function(ot) {
if (data.match(ot)) {
start = (data.match(ot)).index;
content.push(data.substring(0, start));
ct = closeTags[openTags.indexOf(ot)];
end = (data.match(ct)).index + ct.length;
color = ot.substring(1, ot.length - 1);
string = data.substring(start + ot.length, end - ct.length);
content.push({string:string, color:color});
data = data.substring(end, data.length);
}
});
if (_hasTag(data)) {
_split(data);
} else {
content.push(data);
for (i = 0; i < openTags.length; ++i) {
ot = openTags[i];
ct = closeTags[i];
style = styles[i];
while(data.match(ct) && data.match(ot)) {
start = (data.match(ot)).index;
end = (data.match(ct)).index + ct.length;
map.push({start:start, end:end, style:style});
data = data.replace(ot, fillSpaces(ot.length)).replace(ct, fillSpaces(ct.length));
}
}
return content;
return sortMap(map);
}
function _parse(content) {
var colorful = [];
function _parse(data) {
var colorful = [], map = _map(data),
string, i, tail = 0, start, end;
content.forEach(function(c) {
if (c.string && c.color) {
styles.forEach(function(s) {
if (s === c.color) {
colorful.push(c.string[s]);
}
});
} else {
if (c) {
colorful.push(c);
}
for (i = 0; i < map.length; i++) {
if (i === 0 && map[i] > 0) {
colorful.push(data.slice(0, m[i].start - 1));
} else if (i === map.length - 1 && map[i].end < data.length - 1) {
colorful.push(data.slice(map[i].end + 1, data.length));
}
else {
if (map[i].start > tail + 1) {
colorful.push(data.slice(tail, map[i].start));
}
});
string = data.slice(map[i].start + map[i].style.length + 2, map[i].end - (map[i].style.length + 3));
colorful.push(string[map[i].style]);
}
tail = map[i].end;
}
return colorful;

@@ -74,3 +64,3 @@ }

if (err) {callback(err, null);}
callback(error, _parse(_split(data)));
callback(error, _parse(data));
});

@@ -85,3 +75,3 @@ }

data = fs.readFileSync(filePath, 'utf8');
return _parse(_split(data));
return _parse(data);
} else {

@@ -88,0 +78,0 @@ throw new Error('File not exists.');

{
"name":"consolemark",
"description":"try parse to something console con display.",
"version":"0.0.1",
"version":"0.0.2",
"author":"Guan 'kuno' Qing <neokuno AT gmail DOT com>",

@@ -6,0 +6,0 @@ "contributors":[],

@@ -13,6 +13,8 @@ Use ansi color to render the output on console screen;

Similar to html tag, __<TAG>text</TAG>__ __<ANOTHERTAG>text</ANOTHERTAG>__
Similar to html tag:
See details at example/exmaple.cmk file
;
<yellow>text</yellow>
See details at example/exmaple.cmk
####Current support tags

@@ -19,0 +21,0 @@

Sorry, the diff of this file is not supported yet