From b896046bff4ca15318ec70ee0a481a91c3d96359 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 17 Aug 2017 21:31:57 -0600 Subject: [PATCH] Add 'auto' support for prepAnsi() rows/height --- core/message.js | 2 +- core/multi_line_edit_text_view.js | 2 +- core/string_util.js | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/message.js b/core/message.js index 5e48fa9d..207e748a 100644 --- a/core/message.js +++ b/core/message.js @@ -480,7 +480,7 @@ Message.prototype.getQuoteLines = function(options, cb) { termWidth : options.termWidth, termHeight : options.termHeight, cols : options.cols - quotePrefix.length, - rows : 5000, // :TODO: Need 'auto' + rows : 'auto', startCol : options.startCol, forceLineTerm : true, }, diff --git a/core/multi_line_edit_text_view.js b/core/multi_line_edit_text_view.js index 4b8c8b69..469ac4c9 100644 --- a/core/multi_line_edit_text_view.js +++ b/core/multi_line_edit_text_view.js @@ -569,7 +569,7 @@ function MultiLineEditTextView(options) { termWidth : this.client.termWidth, termHeight : this.client.termHeight, cols : this.dimens.width, - height : 5000, // :TODO: 'auto' needed here! + rows : 'auto', startCol : this.position.col, forceLineTerm : options.forceLineTerm, }, diff --git a/core/string_util.js b/core/string_util.js index 592b44cd..59a6eb74 100644 --- a/core/string_util.js +++ b/core/string_util.js @@ -384,11 +384,11 @@ function prepAnsi(input, options, cb) { options.termHeight = options.termHeight || 25; 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; - 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 state = { @@ -398,6 +398,14 @@ function prepAnsi(input, options, cb) { 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) => { state.row = row - 1; state.col = col - 1; @@ -412,7 +420,9 @@ function prepAnsi(input, options, cb) { literal = literal.replace(/\r?\n|[\r\u2028\u2029]/g, ''); 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; if(state.sgr) {