diff --git a/example/tput.js b/example/tput.js index c35dd0e..344f977 100644 --- a/example/tput.js +++ b/example/tput.js @@ -1,6 +1,9 @@ -var Tput = require('../lib/tput'); +var Tput = require('../').Tput; -var tput = new Tput(process.argv[2] || 'xterm', true); +var tput = Tput({ + term: process.argv[2] || 'xterm', + debug: true +}); //tput.colors(); diff --git a/lib/tput.js b/lib/tput.js index 8c9b738..27e5bf5 100644 --- a/lib/tput.js +++ b/lib/tput.js @@ -22,15 +22,21 @@ var assert = require('assert') * Tput */ -function Tput(term, debug) { +function Tput(options) { if (!(this instanceof Tput)) { - return new Tput(term); + return new Tput(options); } - this.term = term; + if (typeof options === 'string') { + options = { term: options }; + } + + this.options = options; + this.term = options.term; this.data = null; this.info = {}; - this.debug = debug; + this.debug = options.debug; + this.padding = options.padding; this.readTerminfo(); this.compile(); @@ -514,7 +520,18 @@ Tput.prototype._compile = function(val) { // as in printf, flags are [-+#] and space. Use a `:' to allow the // next character to be a `-' flag, avoiding interpreting "%-" as an // operator. - if (read(/^%(:-|[+# ])(?:(\d+)(\.\d+)?)?([doxXs])?/)) { + // NOTE: Possibly remove one of the {0,1}'s. + // Otherwise %+ and other ops could be mistaken for this. + // Guessing it looks like: + // %:-d + // %+d + // %#x + // %+10d + // Probably should be: /^%(:-|[+# ])?(\d+(?:\.\d+)?)?([doxXs])/ + if (read(/^%(:-|[+# ])(\d+(?:\.\d+)?)?([doxXs])?/)) { + // var op = cap[1] + // , width = cap[2] + // , flag = cap[3]; print(''); continue; } @@ -525,8 +542,8 @@ Tput.prototype._compile = function(val) { continue; } - // %d print pop() like %d in printf - // NOT SURE ABOUT %d being print! + // %d print pop() + // "Print (e.g., "%d") is a special case." if (read(/^%d/)) { echo('stack.pop()'); continue;