make text wrapping optional.

This commit is contained in:
Christopher Jeffrey 2013-07-23 14:43:14 -05:00
parent f56d7386c6
commit 76cc6d37e7

View File

@ -1618,6 +1618,7 @@ function Element(options) {
this.fixed = options.fixed || false;
this.align = options.align || 'left';
this.valign = options.valign || 'top';
this.wrap = options.wrap !== false;
this.shrink = options.shrink;
if (typeof options.padding === 'number' || !options.padding) {
@ -1942,9 +1943,10 @@ Element.prototype._align = function(line, width, align) {
};
Element.prototype._wrapContent = function(content, width) {
var el = this
var self = this
, tags = this.parseTags
, state = this.align
, wrap = this.wrap
, margin = 0
, rtof = []
, ftor = []
@ -1962,8 +1964,8 @@ Element.prototype._wrapContent = function(content, width) {
return out;
}
if (el.scrollbar) margin++;
if (el.type === 'textarea') margin++;
if (this.scrollbar) margin++;
if (this.type === 'textarea') margin++;
if (width > margin) width -= margin;
lines.forEach(function(line, no) {
@ -2003,6 +2005,10 @@ Element.prototype._wrapContent = function(content, width) {
, part
, esc;
if (!wrap && line.length > width) {
line = line.slice(0, width);
}
while (line.length > width) {
for (i = 0, total = 0; i < line.length; i++) {
while (line[i] === '\x1b') {
@ -2032,12 +2038,12 @@ Element.prototype._wrapContent = function(content, width) {
if (esc) {
part = part.slice(0, -esc[0].length);
line = line.substring(i - 1 - esc[0].length);
out.push(el._align(part, width, align));
out.push(self._align(part, width, align));
ftor[no].push(out.length - 1);
rtof.push(no);
} else {
line = line.substring(i - 1);
out.push(el._align(part, width, align));
out.push(self._align(part, width, align));
ftor[no].push(out.length - 1);
rtof.push(no);
}
@ -2053,7 +2059,7 @@ Element.prototype._wrapContent = function(content, width) {
return;
}
out.push(el._align(line, width, align));
out.push(self._align(line, width, align));
ftor[no].push(out.length - 1);
rtof.push(no);
});