Add 'auto' support for prepAnsi() rows/height

This commit is contained in:
Bryan Ashby 2017-08-17 21:31:57 -06:00
parent 8a619b5138
commit b896046bff
3 changed files with 15 additions and 5 deletions

View File

@ -480,7 +480,7 @@ Message.prototype.getQuoteLines = function(options, cb) {
termWidth : options.termWidth, termWidth : options.termWidth,
termHeight : options.termHeight, termHeight : options.termHeight,
cols : options.cols - quotePrefix.length, cols : options.cols - quotePrefix.length,
rows : 5000, // :TODO: Need 'auto' rows : 'auto',
startCol : options.startCol, startCol : options.startCol,
forceLineTerm : true, forceLineTerm : true,
}, },

View File

@ -569,7 +569,7 @@ function MultiLineEditTextView(options) {
termWidth : this.client.termWidth, termWidth : this.client.termWidth,
termHeight : this.client.termHeight, termHeight : this.client.termHeight,
cols : this.dimens.width, cols : this.dimens.width,
height : 5000, // :TODO: 'auto' needed here! rows : 'auto',
startCol : this.position.col, startCol : this.position.col,
forceLineTerm : options.forceLineTerm, forceLineTerm : options.forceLineTerm,
}, },

View File

@ -384,11 +384,11 @@ function prepAnsi(input, options, cb) {
options.termHeight = options.termHeight || 25; options.termHeight = options.termHeight || 25;
options.cols = options.cols || options.termWidth || 80; options.cols = options.cols || options.termWidth || 80;
options.rows = options.rows || options.termHeight || 25; options.rows = options.rows || options.termHeight || 'auto';
options.startCol = options.startCol || 1; options.startCol = options.startCol || 1;
const canvas = Array.from( { length : options.rows }, () => Array.from( { length : options.cols}, () => new Object() ) ); const canvas = Array.from( { length : 'auto' === options.rows ? 25 : options.rows }, () => Array.from( { length : options.cols}, () => new Object() ) );
const parser = new ANSIEscapeParser( { termHeight : options.termHeight, termWidth : options.termWidth } ); const parser = new ANSIEscapeParser( { termHeight : options.termHeight, termWidth : options.termWidth } );
const state = { const state = {
@ -398,6 +398,14 @@ function prepAnsi(input, options, cb) {
let lastRow = 0; let lastRow = 0;
function ensureRow(row) {
if(Array.isArray(canvas[row])) {
return;
}
canvas[row] = Array.from( { length : options.cols}, () => new Object() );
}
parser.on('position update', (row, col) => { parser.on('position update', (row, col) => {
state.row = row - 1; state.row = row - 1;
state.col = col - 1; state.col = col - 1;
@ -412,7 +420,9 @@ function prepAnsi(input, options, cb) {
literal = literal.replace(/\r?\n|[\r\u2028\u2029]/g, ''); literal = literal.replace(/\r?\n|[\r\u2028\u2029]/g, '');
for(let c of literal) { for(let c of literal) {
if(state.col < options.cols && state.row < options.rows) { if(state.col < options.cols && ('auto' === options.rows || state.row < options.rows)) {
ensureRow(state.row);
canvas[state.row][state.col].char = c; canvas[state.row][state.col].char = c;
if(state.sgr) { if(state.sgr) {