refactor, options, comments. flags.
This commit is contained in:
parent
587443f9e3
commit
6c6b4f8f66
|
@ -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();
|
||||
|
||||
|
|
31
lib/tput.js
31
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;
|
||||
|
|
Loading…
Reference in New Issue