From f5fdf2a9c078719afeab015fdbcc0a41972d50e9 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 15 Feb 2013 11:42:52 -0600 Subject: [PATCH] clean up comments --- example/tput.js | 6 +++++ lib/tput.js | 67 ++++++++++++------------------------------------- 2 files changed, 22 insertions(+), 51 deletions(-) create mode 100644 example/tput.js diff --git a/example/tput.js b/example/tput.js new file mode 100644 index 00000000..3d0d9749 --- /dev/null +++ b/example/tput.js @@ -0,0 +1,6 @@ +var Tput = require('../lib/tput'); + +var tput = new Tput(process.argv[2] || 'xterm'); +tput.colors(); + +console.log(tput.info); diff --git a/lib/tput.js b/lib/tput.js index b35079e1..937dc5d8 100644 --- a/lib/tput.js +++ b/lib/tput.js @@ -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 = {}; @@ -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('|') @@ -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 @@ -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++; @@ -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; @@ -145,12 +129,9 @@ Tput.prototype.parseTermInfo = function(data) { } // String Table - // %p, %i, etc - parameters - // $ - padding Object.keys(info.strings).forEach(function(key) { if (info.strings[key] === -1) { delete info.strings[key]; - //info.strings[key] = null; return; } @@ -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; }; @@ -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++; @@ -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; @@ -261,12 +231,9 @@ Tput.prototype.parseExtended = function(data) { } // String Table - // %p, %i, etc - parameters - // $ - padding Object.keys(info.strings).forEach(function(key) { if (info.strings[key] === -1) { delete info.strings[key]; - //info.strings[key] = null; return; } @@ -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; } @@ -1088,5 +1054,4 @@ Object.keys(Tput.prototype).forEach(function(key) { }; }); -var tput = new Tput(process.argv[2] || 'xterm'); -tput.colors(); +module.exports = Tput;