From 857a83a3fbc68dac1cce1763dfe939cd91aa729a Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 23 Feb 2013 20:38:24 -0600 Subject: [PATCH] add parsePadding --- lib/tput.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++--- test/terminfo | 2 +- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/lib/tput.js b/lib/tput.js index 5c13aad..a450791 100644 --- a/lib/tput.js +++ b/lib/tput.js @@ -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) { diff --git a/test/terminfo b/test/terminfo index 55f112e..869f89e 100644 --- a/test/terminfo +++ b/test/terminfo @@ -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"