add parsePadding

This commit is contained in:
Christopher Jeffrey 2013-02-23 20:38:24 -06:00
parent f83e3304d1
commit 857a83a3fb
2 changed files with 56 additions and 4 deletions

View File

@ -424,7 +424,7 @@ Tput.prototype._compile = function(val) {
if (ch.length < 2) ch = '0' + ch;
ch = '\\x' + ch;
} else {
ch = '^' + cap[1];
ch = cap[0];
}
break;
}
@ -493,8 +493,8 @@ Tput.prototype._compile = function(val) {
// $<5> -> padding
// e.g. flash_screen: '\u001b[?5h$<100/>\u001b[?5l',
if (read(/^\$<(\d+)>(\*|\/)/)) {
print('');
if (read(/^\$<(\d+)([*\/]{0,2})>/)) {
if (this.padding) print(cap[0]);
continue;
}
@ -730,6 +730,58 @@ Tput.prototype._compile = function(val) {
}
};
Tput.prototype._parsePadding = function(code, print, done) {
if (!this.padding) {
print(code);
return done();
}
var parts = code.split(/(?=\$<\d+[*\/]{0,2}>)/)
, i = 0;
// if (!parts[0]) parts.shift();
(function next() {
if (i === parts.length) {
return done();
}
var part = parts[i++]
, padding = /^\$<(\d+)([*\/]{0,2})>/.exec(part);
if (!padding) {
print(part);
return next();
}
part = part.substring(padding[0].cap);
// From terminfo man page:
// A `*' indicates that the padding required is proportional to the number
// of lines affected by the operation, and the amount given is the
// per-affected-unit padding required. (In the case of insert character,
// the factor is still the number of lines affected.) Normally, padding is
// advisory if the device has the xon capability; it is used for cost
// computation but does not trigger delays.
if (~padding[2].indexOf('*')) {
;
}
// From terminfo man page:
// A `/' suffix indicates that the padding is mandatory and forces a
// delay of the given number of milliseconds even on devices for which xon
// is present to indicate flow control.
if (~padding[2].indexOf('/')) {
;
}
return setTimeout(function() {
print(part);
return next();
}, +padding[1]);
})();
};
Tput.prototype.setupAliases = function(info) {
var self = this;
Object.keys(info).forEach(function(name) {

View File

@ -362,7 +362,7 @@ return "\x1b[27m";
Compiling exit_underline_mode: "\u001b[24m"
return "\x1b[24m";
Compiling flash_screen: "\u001b[?5h$<100/>\u001b[?5l"
return "\x1b[?5h$<100/>\x1b[?5l";
var v, dyn = {}, stat = {}, stack = [], out = [];out.push("\x1b[?5h"),out.push("\x1b[?5l");return out.join("");
Compiling init_2string: "\u001b[!p\u001b[?3;4l\u001b[4l\u001b>"
return "\x1b[!p\x1b[?3;4l\x1b[4l\x1b>";
Compiling insert_line: "\u001b[L"