do not violate 80 col limit.

This commit is contained in:
Christopher Jeffrey 2013-07-18 14:52:56 -05:00
parent 4333952081
commit 48c2bae2a0
3 changed files with 138 additions and 72 deletions

View File

@ -10,7 +10,8 @@
var EventEmitter = require('events').EventEmitter
, Tput = require('./tput')
, colors = require('./colors');
, colors = require('./colors')
, slice = Array.prototype.slice;
/**
* Program
@ -109,7 +110,7 @@ Program.prototype.setupTput = function() {
});
this.put = function() {
var args = Array.prototype.slice.call(arguments)
var args = slice.call(arguments)
, cap = args.shift();
if (tput[cap]) {
@ -831,6 +832,8 @@ Program.prototype._bindResponse = function(s) {
x: +parts[2],
y: +parts[3]
};
out.x = out.position.x;
out.y = out.position.y;
// LEGACY
out.windowPosition = out.position;
@ -847,6 +850,8 @@ Program.prototype._bindResponse = function(s) {
height: +parts[2],
width: +parts[3]
};
out.height = out.size.height;
out.width = out.size.width;
// LEGACY
out.windowSizePixels = out.size;
@ -863,6 +868,8 @@ Program.prototype._bindResponse = function(s) {
height: +parts[2],
width: +parts[3]
};
out.height = out.size.height;
out.width = out.size.width;
// LEGACY
out.textAreaSizeCharacters = out.size;
@ -879,6 +886,8 @@ Program.prototype._bindResponse = function(s) {
height: +parts[2],
width: +parts[3]
};
out.height = out.size.height;
out.width = out.size.width;
// LEGACY
out.screenSizeCharacters = out.size;
@ -2047,9 +2056,11 @@ Program.prototype.setBackground = function(color, val) {
Program.prototype.dsr =
Program.prototype.deviceStatus = function(param, callback, dec) {
if (dec) {
return this.response('device-status', '\x1b[?' + (param || '0') + 'n', callback);
return this.response('device-status',
'\x1b[?' + (param || '0') + 'n', callback);
}
return this.response('device-status', '\x1b[' + (param || '0') + 'n', callback);
return this.response('device-status',
'\x1b[' + (param || '0') + 'n', callback);
};
Program.prototype.getCursor = function(callback) {
@ -2147,7 +2158,7 @@ Program.prototype.charPosAbsolute = function(param) {
if (this.tput) {
return this.put.hpa.apply(this.put, arguments);
}
var param = Array.prototype.slice.call(arguments).join(';');
var param = slice.call(arguments).join(';');
return this.write('\x1b[' + (param || '') + '`');
};
@ -2201,7 +2212,8 @@ Program.prototype.HPositionRelative = function(param) {
// vim responds with ^[[?0c or ^[[?1c after the terminal's response (?)
Program.prototype.da =
Program.prototype.sendDeviceAttributes = function(param, callback) {
return this.response('device-attributes', '\x1b[' + (param || '') + 'c', callback);
return this.response('device-attributes',
'\x1b[' + (param || '') + 'c', callback);
};
// CSI Pm d
@ -2214,7 +2226,7 @@ Program.prototype.linePosAbsolute = function(param) {
if (this.tput) {
return this.put.vpa.apply(this.put, arguments);
}
var param = Array.prototype.slice.call(arguments).join(';');
var param = slice.call(arguments).join(';');
return this.write('\x1b[' + (param || '') + 'd');
};
@ -2337,12 +2349,12 @@ Program.prototype.HVPosition = function(row, col) {
// http://vt100.net/docs/vt220-rm/chapter4.html
Program.prototype.sm =
Program.prototype.setMode = function() {
var param = Array.prototype.slice.call(arguments).join(';');
var param = slice.call(arguments).join(';');
return this.write('\x1b[' + (param || '') + 'h');
};
Program.prototype.decset = function() {
var param = Array.prototype.slice.call(arguments).join(';');
var param = slice.call(arguments).join(';');
return this.setMode('?' + param);
};
@ -2452,12 +2464,12 @@ Program.prototype.alternateBuffer = function() {
// Ps = 2 0 0 4 -> Reset bracketed paste mode.
Program.prototype.rm =
Program.prototype.resetMode = function() {
var param = Array.prototype.slice.call(arguments).join(';');
var param = slice.call(arguments).join(';');
return this.write('\x1b[' + (param || '') + 'l');
};
Program.prototype.decrst = function() {
var param = Array.prototype.slice.call(arguments).join(';');
var param = slice.call(arguments).join(';');
return this.resetMode('?' + param);
};
@ -2681,7 +2693,7 @@ Program.prototype.scrollDown = function(param) {
// [func;startx;starty;firstrow;lastrow]. See the section Mouse
// Tracking.
Program.prototype.initMouseTracking = function() {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + 'T');
return this.write('\x1b[' + slice.call(arguments).join(';') + 'T');
};
// CSI > Ps; Ps T
@ -2696,7 +2708,7 @@ Program.prototype.initMouseTracking = function() {
// Ps = 3 -> Do not query window/icon labels using UTF-8.
// (See discussion of "Title Modes").
Program.prototype.resetTitleModes = function() {
return this.write('\x1b[>' + Array.prototype.slice.call(arguments).join(';') + 'T');
return this.write('\x1b[>' + slice.call(arguments).join(';') + 'T');
};
// CSI Ps Z Cursor Backward Tabulation Ps tab stops (default = 1) (CBT).
@ -2742,7 +2754,7 @@ Program.prototype.tabClear = function(param) {
// Ps = 1 1 -> Print all pages.
Program.prototype.mc =
Program.prototype.mediaCopy = function() {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + 'i');
return this.write('\x1b[' + slice.call(arguments).join(';') + 'i');
};
Program.prototype.print_screen =
@ -2786,7 +2798,7 @@ Program.prototype.mc5p = function() {
// If no parameters are given, all resources are reset to their
// initial values.
Program.prototype.setResources = function() {
return this.write('\x1b[>' + Array.prototype.slice.call(arguments).join(';') + 'm');
return this.write('\x1b[>' + slice.call(arguments).join(';') + 'm');
};
// CSI > Ps n
@ -2868,7 +2880,7 @@ Program.prototype.requestPrivateMode = function(param) {
// Ps = 2 -> 8-bit controls.
Program.prototype.decscl =
Program.prototype.setConformanceLevel = function() {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '"p');
return this.write('\x1b[' + slice.call(arguments).join(';') + '"p');
};
// CSI Ps q Load LEDs (DECLL).
@ -2939,7 +2951,7 @@ Program.prototype.setCharProtectionAttr = function(param) {
// Restore DEC Private Mode Values. The value of Ps previously
// saved is restored. Ps values are the same as for DECSET.
Program.prototype.restorePrivateValues = function() {
return this.write('\x1b[?' + Array.prototype.slice.call(arguments).join(';') + 'r');
return this.write('\x1b[?' + slice.call(arguments).join(';') + 'r');
};
// CSI Pt; Pl; Pb; Pr; Ps$ r
@ -2949,14 +2961,14 @@ Program.prototype.restorePrivateValues = function() {
// NOTE: xterm doesn't enable this code by default.
Program.prototype.deccara =
Program.prototype.setAttrInRectangle = function() {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$r');
return this.write('\x1b[' + slice.call(arguments).join(';') + '$r');
};
// CSI ? Pm s
// Save DEC Private Mode Values. Ps values are the same as for
// DECSET.
Program.prototype.savePrivateValues = function(params) {
return this.write('\x1b[?' + Array.prototype.slice.call(arguments).join(';') + 's');
return this.write('\x1b[?' + slice.call(arguments).join(';') + 's');
};
// CSI Ps ; Ps ; Ps t
@ -3006,13 +3018,14 @@ Program.prototype.savePrivateValues = function(params) {
// Ps = 2 3 ; 2 -> Restore xterm window title from stack.
// Ps >= 2 4 -> Resize to Ps lines (DECSLPP).
Program.prototype.manipulateWindow = function() {
var args = Array.prototype.slice.call(arguments);
var args = slice.call(arguments);
var callback = typeof args[args.length-1] === 'function'
? args.pop()
: function() {};
return this.response('window-manipulation', '\x1b[' + args.join(';') + 't', callback);
return this.response('window-manipulation',
'\x1b[' + args.join(';') + 't', callback);
};
Program.prototype.getWindowSize = function(callback) {
@ -3027,7 +3040,7 @@ Program.prototype.getWindowSize = function(callback) {
// NOTE: xterm doesn't enable this code by default.
Program.prototype.decrara =
Program.prototype.reverseAttrInRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$t');
return this.write('\x1b[' + slice.call(arguments).join(';') + '$t');
};
// CSI > Ps; Ps t
@ -3039,7 +3052,7 @@ Program.prototype.reverseAttrInRectangle = function(params) {
// Ps = 3 -> Query window/icon labels using UTF-8. (See dis-
// cussion of "Title Modes")
Program.prototype.setTitleModeFeature = function(params) {
return this.write('\x1b[>' + Array.prototype.slice.call(arguments).join(';') + 't');
return this.write('\x1b[>' + slice.call(arguments).join(';') + 't');
};
// CSI Ps SP t
@ -3071,7 +3084,7 @@ Program.prototype.setMarginBellVolume = function(params) {
// NOTE: xterm doesn't enable this code by default.
Program.prototype.deccra =
Program.prototype.copyRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$v');
return this.write('\x1b[' + slice.call(arguments).join(';') + '$v');
};
// CSI Pt ; Pl ; Pb ; Pr ' w
@ -3087,7 +3100,7 @@ Program.prototype.copyRectangle = function(params) {
// cels any prevous rectangle definition.
Program.prototype.decefr =
Program.prototype.enableFilterRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '\'w');
return this.write('\x1b[' + slice.call(arguments).join(';') + '\'w');
};
// CSI Ps x Request Terminal Parameters (DECREQTPARM).
@ -3122,7 +3135,7 @@ Program.prototype.selectChangeExtent = function(params) {
// NOTE: xterm doesn't enable this code by default.
Program.prototype.decfra =
Program.prototype.fillRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$x');
return this.write('\x1b[' + slice.call(arguments).join(';') + '$x');
};
// CSI Ps ; Pu ' z
@ -3139,7 +3152,7 @@ Program.prototype.fillRectangle = function(params) {
// Pu = 2 <- character cells.
Program.prototype.decelr =
Program.prototype.enableLocatorReporting = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '\'z');
return this.write('\x1b[' + slice.call(arguments).join(';') + '\'z');
};
// CSI Pt; Pl; Pb; Pr$ z
@ -3148,7 +3161,7 @@ Program.prototype.enableLocatorReporting = function(params) {
// NOTE: xterm doesn't enable this code by default.
Program.prototype.decera =
Program.prototype.eraseRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '$z');
return this.write('\x1b[' + slice.call(arguments).join(';') + '$z');
};
// CSI Pm ' {
@ -3164,7 +3177,7 @@ Program.prototype.eraseRectangle = function(params) {
// Ps = 4 -> do not report button up transitions.
Program.prototype.decsle =
Program.prototype.setLocatorEvents = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '\'{');
return this.write('\x1b[' + slice.call(arguments).join(';') + '\'{');
};
// CSI Pt; Pl; Pb; Pr$ {
@ -3172,7 +3185,7 @@ Program.prototype.setLocatorEvents = function(params) {
// Pt; Pl; Pb; Pr denotes the rectangle.
Program.prototype.decsera =
Program.prototype.selectiveEraseRectangle = function(params) {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + '${');
return this.write('\x1b[' + slice.call(arguments).join(';') + '${');
};
// CSI Ps ' |
@ -3227,7 +3240,8 @@ Program.prototype.requestLocatorPosition = function(params, callback) {
var code = this.tput.req_mouse_pos.apply(this.tput, params);
return this.response('locator-position', code, callback);
}
return this.response('locator-position', '\x1b[' + (param || '') + '\'|', callback);
return this.response('locator-position',
'\x1b[' + (param || '') + '\'|', callback);
};
// CSI P m SP }
@ -3235,7 +3249,7 @@ Program.prototype.requestLocatorPosition = function(params, callback) {
// NOTE: xterm doesn't enable this code by default.
Program.prototype.decic =
Program.prototype.insertColumns = function() {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + ' }');
return this.write('\x1b[' + slice.call(arguments).join(';') + ' }');
};
// CSI P m SP ~
@ -3243,7 +3257,7 @@ Program.prototype.insertColumns = function() {
// NOTE: xterm doesn't enable this code by default.
Program.prototype.decdc =
Program.prototype.deleteColumns = function() {
return this.write('\x1b[' + Array.prototype.slice.call(arguments).join(';') + ' ~');
return this.write('\x1b[' + slice.call(arguments).join(';') + ' ~');
};
/**
@ -3255,7 +3269,7 @@ Program.prototype._owrite = function(data) {
};
Program.prototype.out = function(name) {
var args = Array.prototype.slice.call(arguments, 1);
var args = slice.call(arguments, 1);
var write = this.write;
this.write = this._owrite;
var receive = this.receive;

View File

@ -320,7 +320,8 @@ Tput.prototype.parseTerminfo = function(data) {
// sym: '612 - 928' } // length: 316
//
// How lastStrTableOffset works:
// data.length - h.lastStrTableOffset === 248 (sym-offset end, string-table start)
// data.length - h.lastStrTableOffset === 248
// (sym-offset end, string-table start)
// 364 + 316 === 680 (lastStrTableOffset)
// How strTableSize works:
// h.strCount + [symOffsetCount] === h.strTableSize
@ -774,7 +775,8 @@ Tput.prototype._compile = function(val, key) {
if (this.printf) {
echo('sprintf("%c", stack.pop())');
} else {
echo('(v = stack.pop() || "", isFinite(v) ? String.fromCharCode(v) : v[0])');
echo('(v = stack.pop() || "",'
+ ' isFinite(v) ? String.fromCharCode(v) : v[0])');
}
continue;
}
@ -1141,8 +1143,10 @@ Tput.prototype.readTermcap = function(data) {
/**
* Termcap Parser
* http://en.wikipedia.org/wiki/Termcap
* http://www.gnu.org/software/termutils/manual/termcap-1.3/html_mono/termcap.html
* http://www.gnu.org/software/termutils/manual/termcap-1.3/html_mono/termcap.html#SEC17
* http://www.gnu.org/software
* /termutils/manual/termcap-1.3/html_mono/termcap.html
* http://www.gnu.org/software
* /termutils/manual/termcap-1.3/html_mono/termcap.html#SEC17
* http://tldp.org/HOWTO/Text-Terminal-HOWTO.html#toc16
* man termcap
*/
@ -1641,16 +1645,16 @@ Tput.prototype.has = function(name) {
*/
Tput.termcap = ''
+ 'vt102|dec vt102:\\\n'
+ ' :do=^J:co#80:li#24:cl=50\\E[;H\\E[2J:\\\n'
+ ' :le=^H:bs:cm=5\\E[%i%d;%dH:nd=2\\E[C:up=2\\E[A:\\\n'
+ ' :ce=3\\E[K:cd=50\\E[J:so=2\\E[7m:se=2\\E[m:us=2\\E[4m:ue=2\\E[m:\\\n'
+ ' :md=2\\E[1m:mr=2\\E[7m:mb=2\\E[5m:me=2\\E[m:is=\\E[1;24r\\E[24;1H:\\\n'
+ ' :rs=\\E>\\E[?3l\\E[?4l\\E[?5l\\E[?7h\\E[?8h:ks=\\E[?1h\\E=:ke=\\E[?1l\\E>:\\\n'
+ ' :ku=\\EOA:kd=\\EOB:kr=\\EOC:kl=\\EOD:kb=^H:\\\n'
+ ' :ho=\\E[H:k1=\\EOP:k2=\\EOQ:k3=\\EOR:k4=\\EOS:pt:sr=5\\EM:vt#3:\\\n'
+ ' :sc=\\E7:rc=\\E8:cs=\\E[%i%d;%dr:vs=\\E[?7l:ve=\\E[?7h:\\\n'
+ ' :mi:al=\\E[L:dc=\\E[P:dl=\\E[M:ei=\\E[4l:im=\\E[4h:';
+ 'vt102|dec vt102:'
+ ':do=^J:co#80:li#24:cl=50\\E[;H\\E[2J:'
+ ':le=^H:bs:cm=5\\E[%i%d;%dH:nd=2\\E[C:up=2\\E[A:'
+ ':ce=3\\E[K:cd=50\\E[J:so=2\\E[7m:se=2\\E[m:us=2\\E[4m:ue=2\\E[m:'
+ ':md=2\\E[1m:mr=2\\E[7m:mb=2\\E[5m:me=2\\E[m:is=\\E[1;24r\\E[24;1H:'
+ ':rs=\\E>\\E[?3l\\E[?4l\\E[?5l\\E[?7h\\E[?8h:ks=\\E[?1h\\E=:ke=\\E[?1l\\E>:'
+ ':ku=\\EOA:kd=\\EOB:kr=\\EOC:kl=\\EOD:kb=^H:\\\n'
+ ':ho=\\E[H:k1=\\EOP:k2=\\EOQ:k3=\\EOR:k4=\\EOS:pt:sr=5\\EM:vt#3:'
+ ':sc=\\E7:rc=\\E8:cs=\\E[%i%d;%dr:vs=\\E[?7l:ve=\\E[?7h:'
+ ':mi:al=\\E[L:dc=\\E[P:dl=\\E[M:ei=\\E[4l:im=\\E[4h:';
/**
* Terminfo Data

View File

@ -1995,7 +1995,8 @@ Element.prototype.__defineSetter__('right', function(val) {
this.emit('move');
this.clearPos();
//if (this.options.right == null) {
// return this.options.left = this.position.left = this.screen.width - 1 - val;
// return this.options.left = this.position.left =
// this.screen.width - 1 - val;
//}
return this.options.right = this.position.right = val;
});
@ -2024,7 +2025,8 @@ Element.prototype.__defineSetter__('bottom', function(val) {
this.emit('move');
this.clearPos();
//if (this.options.bottom == null) {
// return this.options.top = this.position.top = this.screen.height - 1 - val;
// return this.options.top = this.position.top =
// this.screen.height - 1 - val;
//}
return this.options.bottom = this.position.bottom = val;
});
@ -2055,7 +2057,8 @@ Element.prototype.__defineSetter__('rright', function(val) {
this.emit('move');
this.clearPos();
//if (this.options.right == null) {
// return this.options.left = this.position.left = this.parent.width - 1 - val;
// return this.options.left = this.position.left =
// this.parent.width - 1 - val;
//}
return this.options.right = this.position.right = val;
});
@ -2072,11 +2075,36 @@ Element.prototype.__defineSetter__('rbottom', function(val) {
this.emit('move');
this.clearPos();
//if (this.options.bottom == null) {
// return this.options.top = this.position.top = this.parent.height - 1 - val;
// return this.options.top = this.position.top =
// this.parent.height - 1 - val;
//}
return this.options.bottom = this.position.bottom = val;
});
Element.prototype.__defineGetter__('ileft', function() {
return this.left + (this.border ? 1 : 0) + this.padding;
});
Element.prototype.__defineGetter__('itop', function() {
return this.top + (this.border ? 1 : 0) + this.padding;
});
Element.prototype.__defineGetter__('iright', function() {
return this.right - (this.border ? 1 : 0) - this.padding;
});
Element.prototype.__defineGetter__('ibottom', function() {
return this.bottom - (this.border ? 1 : 0) - this.padding;
});
Element.prototype.__defineGetter__('iwidth', function() {
return this.width - (this.border ? 2 : 0) - this.padding * 2;
});
Element.prototype.__defineGetter__('iheight', function() {
return this.height - (this.border ? 2 : 0) - this.padding * 2;
});
/**
* Box
*/
@ -2772,7 +2800,8 @@ ScrollableBox.prototype.scroll = function(offset) {
b = p.yl - (this.border ? 1 : 0) - this.padding - 1;
d = this.childBase - base;
// var attr = this.screen.olines[t][p.xi + (this.border ? 1 : 0) + this.padding][0];
// var i = p.xi + (this.border ? 1 : 0) + this.padding;
// var attr = this.screen.olines[t][i][0];
// this.screen.program.write(this.screen.codeAttr(attr, this.screen));
if (d > 0 && d < visible) {
@ -2892,7 +2921,8 @@ function List(options) {
self.screen.render();
return;
}
if (key.name === 'enter' || (options.vi && key.name === 'l' && !key.shift)) {
if (key.name === 'enter'
|| (options.vi && key.name === 'l' && !key.shift)) {
self.emit('action', self.items[self.selected], self.selected);
self.emit('select', self.items[self.selected], self.selected);
return;
@ -2928,17 +2958,19 @@ function List(options) {
return;
}
if (options.vi && key.name === 'm' && key.shift) {
// TODO: Maybe use Math.min(this.items.length, ... for calculating visible items elsewhere.
self.move(self.childBase
+ (Math.min(self.height - (self.border ? 2 : 0), this.items.length) / 2 | 0)
- self.selected);
// TODO: Maybe use Math.min(this.items.length,
// ... for calculating visible items elsewhere.
var visible = Math.min(
self.height - (self.border ? 2 : 0),
self.items.length) / 2 | 0;
self.move(self.childBase + visible - self.selected);
self.screen.render();
return;
}
if (options.vi && key.name === 'l' && key.shift) {
// XXX This goes one too far on lists with an odd number of items.
self.down(self.childBase
+ Math.min(self.height - (self.border ? 2 : 0), this.items.length)
+ Math.min(self.height - (self.border ? 2 : 0), self.items.length)
- self.selected);
self.screen.render();
return;
@ -3029,6 +3061,7 @@ List.prototype.remove = function(child) {
this._remove(child);
};
List.prototype.addItem = List.prototype.add;
List.prototype.appendItem = List.prototype.add;
List.prototype.removeItem = List.prototype.remove;
@ -3193,7 +3226,8 @@ ScrollableText.prototype.scroll = function(offset) {
if (this.content != null) {
this.parseContent();
max = this._clines.length - (this.height - (this.border ? 2 : 0) - this.padding * 2);
max = this._clines.length
- (this.height - (this.border ? 2 : 0) - this.padding * 2);
if (max < 0) max = 0;
if (cb > max) {
@ -3202,9 +3236,13 @@ ScrollableText.prototype.scroll = function(offset) {
}
if (diff > 0) {
for (i = base; i < cb; i++) this.contentIndex += this._clines[i].length + 1;
for (i = base; i < cb; i++) {
this.contentIndex += this._clines[i].length + 1;
}
} else {
for (i = base - 1; i >= cb; i--) this.contentIndex -= this._clines[i].length + 1;
for (i = base - 1; i >= cb; i--) {
this.contentIndex -= this._clines[i].length + 1;
}
}
}
@ -3214,7 +3252,8 @@ ScrollableText.prototype.scroll = function(offset) {
ScrollableText.prototype._recalculateIndex = function() {
if (this.detached) return;
var max = this._clines.length - (this.height - (this.border ? 2 : 0) - this.padding * 2);
var max = this._clines.length
- (this.height - (this.border ? 2 : 0) - this.padding * 2);
if (max < 0) max = 0;
if (this.childBase > max) {
@ -3254,12 +3293,16 @@ function Form(options) {
return;
}
if ((key.name === 'tab' && !key.shift) || key.name === 'down' || (options.vi && key.name === 'j')) {
if ((key.name === 'tab' && !key.shift)
|| key.name === 'down'
|| (options.vi && key.name === 'j')) {
self.focusNext();
return;
}
if ((key.name === 'tab' && key.shift) || key.name === 'up' || (options.vi && key.name === 'k')) {
if ((key.name === 'tab' && key.shift)
|| key.name === 'up'
|| (options.vi && key.name === 'k')) {
self.focusPrevious();
return;
}
@ -3527,7 +3570,8 @@ Textbox.prototype.setInput = function(callback) {
Textbox.prototype._listener = function(ch, key) {
var callback = this._callback
, value = this.value;
, value = this.value
, width = this.width - (this.border ? 2 : 0) - this.padding * 2;
if (key.name === 'escape' || key.name === 'enter') {
delete this._callback;
@ -3538,7 +3582,7 @@ Textbox.prototype._listener = function(ch, key) {
if (this.value.length) {
this.value = this.value.slice(0, -1);
if (this.secret) return;
if (this.value.length < this.width - (this.border ? 2 : 0) - this.padding * 2 - 1) {
if (this.value.length < width - 1) {
this.screen.program.cub();
}
}
@ -3548,7 +3592,7 @@ Textbox.prototype._listener = function(ch, key) {
if (ch === '\t') ch = ' ';
this.value += ch;
if (this.secret) return;
if (this.value.length < this.width - (this.border ? 2 : 0) - this.padding * 2) {
if (this.value.length < width) {
this.screen.program.cuf();
}
}
@ -3557,7 +3601,8 @@ Textbox.prototype._listener = function(ch, key) {
// Maybe just use this instead of render hook:
// Problem - user can't set .value willy nilly.
// if (this.value !== value) {
// this.setContent(this.value.slice(-(this.width - (this.border ? 2 : 0) - this.padding * 2 - 1)));
// var i = -(this.width - (this.border ? 2 : 0) - this.padding * 2 - 1);
// this.setContent(this.value.slice(i));
// }
this.screen.render();
@ -3589,7 +3634,8 @@ Textbox.prototype.render = function() {
this.setContent(Array(this.value.length + 1).join('*'));
return this._render();
}
this.setContent(this.value.slice(-(this.width - (this.border ? 2 : 0) - this.padding * 2 - 1)));
var visible = -(this.width - (this.border ? 2 : 0) - this.padding * 2 - 1);
this.setContent(this.value.slice(visible));
return this._render();
};
@ -3760,7 +3806,8 @@ Textarea.prototype._listener = function(ch, key) {
Textarea.prototype._typeScroll = function() {
// XXX Workaround
if (this._clines.length - this.childBase > this.height - (this.border ? 2 : 0) - this.padding * 2) {
var width = this.height - (this.border ? 2 : 0) - this.padding * 2;
if (this._clines.length - this.childBase > width) {
//this.setContent(this.value + '\n');
this.scroll(this._clines.length);
}
@ -3905,7 +3952,8 @@ ProgressBar.prototype.type = 'progress-bar';
ProgressBar.prototype._render = ProgressBar.prototype.render;
ProgressBar.prototype.render = function() {
// NOTE: Maybe move this `hidden` check down below `stop` check and return `ret`.
// NOTE: Maybe move this `hidden` check
// down below `stop` check and return `ret`.
if (this.hidden) return;
var ret = this._render();