Skip to content

Commit

Permalink
clean up comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Feb 15, 2013
1 parent 3e8cea6 commit f5fdf2a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 51 deletions.
6 changes: 6 additions & 0 deletions example/tput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var Tput = require('../lib/tput');

var tput = new Tput(process.argv[2] || 'xterm');
tput.colors();

console.log(tput.info);
67 changes: 16 additions & 51 deletions lib/tput.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ var assert = require('assert')
*/

function Tput(term) {
if (!(this instanceof Tput)) {
return new Tput(term);
}

this.term = term;
this.data = null;
this.info = {};
Expand Down Expand Up @@ -66,9 +70,6 @@ Tput.prototype.parseTermInfo = function(data) {

i = h.headerSize;

// short int = 2 8bit bytes, first byte - least significant, second byte - most significant
// little endian

// Names Section
var names = data.toString('ascii', i, i + h.namesSize - 1)
, parts = names.split('|')
Expand All @@ -84,14 +85,6 @@ Tput.prototype.parseTermInfo = function(data) {
assert.equal(data[i], 0);
i++;

// Might need to add another one here, without the extra bool defs there is 1 undefined.
// Example doesn't show this.
//i++;
//if (i % 2) {
// assert.equal(data[i], 0);
// i++;
//}

// Booleans Section
// One byte for each flag
// Same order as <term.h>
Expand All @@ -104,7 +97,6 @@ Tput.prototype.parseTermInfo = function(data) {
}

// Null byte in between to make sure numbers begin on an even byte.
// Maybe subtract one from boolCount above and always do this instead.
if (i % 2) {
assert.equal(data[i], 0);
i++;
Expand All @@ -123,14 +115,6 @@ Tput.prototype.parseTermInfo = function(data) {
}
}

// Null byte in between to make sure numbers begin on an even byte.
// Does it explicitly say to do this? tput does not seem to do this,
// but it seems to work on xterm (?).
//if (i % 2) {
// assert.equal(data[i], 0);
// i++;
//}

// Strings Section
info.strings = {};
l = i + h.strCount * 2;
Expand All @@ -145,12 +129,9 @@ Tput.prototype.parseTermInfo = function(data) {
}

// String Table
// %p, %i, etc - parameters
// $<num> - padding
Object.keys(info.strings).forEach(function(key) {
if (info.strings[key] === -1) {
delete info.strings[key];
//info.strings[key] = null;
return;
}

Expand All @@ -161,27 +142,25 @@ Tput.prototype.parseTermInfo = function(data) {

if (s >= data.length || j > data.length) {
delete info.strings[key];
//info.strings[key] = null;
return;
}

info.strings[key] = data.toString('ascii', s, j);
});

// Extended Header, +1 or -1, not sure.
i += h.strTableSize + 1;
l = data.length;
if (0)
if (i < l) {
info.extended = this.parseExtended(data.slice(i));
Object.keys(info.extended).forEach(function(key) {
info[key].extended = info.extended[key];
});
delete info.extended;
// Extended Header
if (this.extended) {
i += h.strTableSize + 1; // offset?
l = data.length;
if (i < l) {
info.extended = this.parseExtended(data.slice(i));
Object.keys(info.extended).forEach(function(key) {
info[key].extended = info.extended[key];
});
delete info.extended;
}
}

console.log(info);

return info;
};

Expand Down Expand Up @@ -220,7 +199,6 @@ Tput.prototype.parseExtended = function(data) {
}

// Null byte in between to make sure numbers begin on an even byte.
// Maybe subtract one from boolCount above and always do this instead.
if (i % 2) {
assert.equal(data[i], 0);
i++;
Expand All @@ -239,14 +217,6 @@ Tput.prototype.parseExtended = function(data) {
}
}

// Null byte in between to make sure numbers begin on an even byte.
// Does it explicitly say to do this? tput does not seem to do this,
// but it seems to work on xterm (?).
//if (i % 2) {
// assert.equal(data[i], 0);
// i++;
//}

// Strings Section
info.strings = {};
l = i + h.strCount * 2;
Expand All @@ -261,12 +231,9 @@ Tput.prototype.parseExtended = function(data) {
}

// String Table
// %p, %i, etc - parameters
// $<num> - padding
Object.keys(info.strings).forEach(function(key) {
if (info.strings[key] === -1) {
delete info.strings[key];
//info.strings[key] = null;
return;
}

Expand All @@ -277,7 +244,6 @@ Tput.prototype.parseExtended = function(data) {

if (s >= data.length || j > data.length) {
delete info.strings[key];
//info.strings[key] = null;
return;
}

Expand Down Expand Up @@ -1088,5 +1054,4 @@ Object.keys(Tput.prototype).forEach(function(key) {
};
});

var tput = new Tput(process.argv[2] || 'xterm');
tput.colors();
module.exports = Tput;

0 comments on commit f5fdf2a

Please sign in to comment.