From 643fca7c13ac4a3ad581ca0a5b98a3e8b72e74a0 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Wed, 3 Jul 2024 11:04:48 +0000 Subject: [PATCH 01/13] feat: add bracketed-paste mode Signed-off-by: Snehil Shah --- lib/node_modules/@stdlib/repl/README.md | 1 + lib/node_modules/@stdlib/repl/lib/defaults.js | 3 ++ lib/node_modules/@stdlib/repl/lib/main.js | 18 +++++++- .../@stdlib/repl/lib/multiline_handler.js | 42 +++++++++++++++++-- lib/node_modules/@stdlib/repl/lib/settings.js | 4 ++ 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/README.md b/lib/node_modules/@stdlib/repl/README.md index 206a2b19097f..314718aaeba5 100644 --- a/lib/node_modules/@stdlib/repl/README.md +++ b/lib/node_modules/@stdlib/repl/README.md @@ -83,6 +83,7 @@ The function supports specifying the following settings: - **autoClosePairs**: boolean indicating whether to automatically insert matching brackets, parentheses, and quotes. Default: `true`. - **autoDeletePairs**: boolean indicating whether to automatically delete adjacent matching brackets, parentheses, and quotes. Default: `true`. - **autoPage**: boolean indicating whether to automatically page return values having a display size exceeding the visible screen. When streams are TTY, the default is `true`; otherwise, the default is `false`. +- **bracketedPaste**: boolean indicating whether to enable bracketed paste mode. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **completionPreviews**: boolean indicating whether to display completion previews for auto-completion. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **syntaxHighlighting**: boolean indicating whether to enable syntax highlighting of entered input expressions. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **theme**: initial color theme for syntax highlighting. Default: `stdlib-ansi-basic`. diff --git a/lib/node_modules/@stdlib/repl/lib/defaults.js b/lib/node_modules/@stdlib/repl/lib/defaults.js index 8f07cbe2b011..956c3c00b204 100644 --- a/lib/node_modules/@stdlib/repl/lib/defaults.js +++ b/lib/node_modules/@stdlib/repl/lib/defaults.js @@ -89,6 +89,9 @@ function defaults() { // Flag indicating whether to enable automatically page return values requiring a display size exceeding the visible screen (note: default depends on whether TTY): 'autoPage': void 0, + // Flag indicating whether to enable bracketed paste mode: + 'bracketedPaste': void 0, + // Flag indicating whether to enable the display of completion previews for auto-completion (note: default depends on whether TTY): 'completionPreviews': void 0, diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index b63a95e23f01..b5dfab99bc42 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable no-restricted-syntax, no-invalid-this, no-underscore-dangle, max-lines */ +/* eslint-disable no-restricted-syntax, no-invalid-this, no-underscore-dangle, max-lines, max-lines-per-function */ 'use strict'; @@ -102,6 +102,7 @@ var debug = logger( 'repl' ); * @param {boolean} [options.settings.autoClosePairs=true] - boolean indicating whether to automatically insert matching brackets, parentheses, and quotes * @param {boolean} [options.settings.autoDeletePairs=true] - boolean indicating whether to automatically delete adjacent matching brackets, parentheses, and quotes * @param {boolean} [options.settings.autoPage] - boolean indicating whether to automatically page return values requiring a display size exceeding the visible screen +* @param {boolean} [options.settings.bracketedPaste] - boolean indicating whether to enable bracketed paste mode * @param {boolean} [options.settings.completionPreviews] - boolean indicating whether to enable completion previews for auto-completion * @param {boolean} [options.settings.syntaxHighlighting] - boolean indicating whether to enable syntax highlighting * @param {string} [options.settings.theme] - initial color theme for syntax highlighting @@ -151,6 +152,7 @@ function REPL( options ) { } opts.isTTY = ( opts.isTTY === void 0 ) ? opts.output.isTTY : opts.isTTY; opts.settings.autoPage = ( opts.settings.autoPage === void 0 ) ? opts.isTTY : opts.settings.autoPage; // eslint-disable-line max-len + opts.settings.bracketedPaste = ( opts.settings.bracketedPaste === void 0 ) ? opts.isTTY : opts.settings.bracketedPaste; // eslint-disable-line max-len opts.settings.completionPreviews = ( opts.settings.completionPreviews === void 0 ) ? opts.isTTY : opts.settings.completionPreviews; // eslint-disable-line max-len opts.settings.syntaxHighlighting = ( opts.settings.syntaxHighlighting === void 0 ) ? opts.isTTY : opts.settings.syntaxHighlighting; // eslint-disable-line max-len @@ -321,6 +323,10 @@ function REPL( options ) { // Set the syntax highlighting theme... this.settings( 'theme', opts.settings.theme ); + // Initialize specified bracketed-paste setting in TTY environments: + if ( this._isTTY ) { + this.settings( 'bracketedPaste', opts.settings.bracketedPaste ); + } // Check whether to load and execute a JavaScript file (e.g., prior REPL history) upon startup... if ( opts.load ) { this.load( opts.load ); @@ -404,6 +410,10 @@ function REPL( options ) { * @private */ function onClose() { + // Disable bracketed-paste mode in TTY environments: + if ( self._isTTY ) { + self._multilineHandler.disableBracketedPaste(); + } ostream.end(); ostream.unpipe(); @@ -1481,6 +1491,12 @@ setNonEnumerableReadOnly( REPL.prototype, 'settings', function settings() { } } else if ( name === 'theme' ) { this._syntaxHighlighter.setTheme( value ); + } else if ( name === 'bracketedPaste' ) { + if ( value ) { + this._multilineHandler.enableBracketedPaste(); + } else { + this._multilineHandler.disableBracketedPaste(); + } } return this; diff --git a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js index 817704db71fd..8ece32b00a85 100644 --- a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js +++ b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable no-underscore-dangle, no-restricted-syntax, no-invalid-this */ +/* eslint-disable no-underscore-dangle, no-restricted-syntax, no-invalid-this, max-lines */ 'use strict'; @@ -87,6 +87,7 @@ function MultilineHandler( repl, ttyWrite ) { this._multiline = {}; this._multiline.active = false; this._multiline.trigger = false; + this._multiline.pasteMode = false; // Initialize a buffer for caching input lines: this._lines = []; @@ -399,6 +400,32 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'resetInput', function res this._lines.length = 0; }); +/** +* Enables bracketed paste mode in the terminal. +* +* @private +* @name enableBracketedPaste +* @memberof MultilineHandler.prototype +* @type {Function} +* @returns {void} +*/ +setNonEnumerableReadOnly( MultilineHandler.prototype, 'enableBracketedPaste', function enableBracketedPaste() { + this._ostream.write( '\u001b[?2004h' ); +}); + +/** +* Disables bracketed paste mode in the terminal. +* +* @private +* @name disableBracketedPaste +* @memberof MultilineHandler.prototype +* @type {Function} +* @returns {void} +*/ +setNonEnumerableReadOnly( MultilineHandler.prototype, 'disableBracketedPaste', function disableBracketedPaste() { + this._ostream.write( '\u001b[?2004l' ); +}); + /** * Processes input line data. * @@ -541,13 +568,22 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'beforeKeypress', function this._ttyWrite.call( this._rli, data, key ); return; } + // Check for paste sequences... + if ( key.name === 'paste-start' ) { + this._multiline.pasteMode = true; + return; + } + if ( key.name === 'paste-end' ) { + this._multiline.pasteMode = false; + return; + } // Check whether to trigger multi-line mode or execute the command when `return` key is encountered... if ( key.name === 'return' ) { cmd = copy( this._cmd ); cmd[ this._lineIndex ] = this._rli.line; - // If command is incomplete, trigger multi-line mode... - if ( !this._isMultilineInput( cmd.join( '\n' ) ) ) { + // If we are in paste mode or the command is incomplete, trigger multi-line mode... + if ( !this._multiline.pasteMode && !this._isMultilineInput( cmd.join( '\n' ) ) ) { this._ttyWrite.call( this._rli, data, key ); return; } diff --git a/lib/node_modules/@stdlib/repl/lib/settings.js b/lib/node_modules/@stdlib/repl/lib/settings.js index abfb131a0d26..e998a5f00c1f 100644 --- a/lib/node_modules/@stdlib/repl/lib/settings.js +++ b/lib/node_modules/@stdlib/repl/lib/settings.js @@ -40,6 +40,10 @@ var SETTINGS = { 'desc': 'Automatically page return values whose display size exceeds the visible screen.', 'type': 'boolean' }, + 'bracketedPaste': { + 'desc': 'Enable bracketed-paste mode.', + 'type': 'boolean' + }, 'completionPreviews': { 'desc': 'Enable the display of completion previews for auto-completion.', 'type': 'boolean' From 5a39fd86a2fb78158f6f975408332827adb380aa Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Wed, 3 Jul 2024 12:17:26 +0000 Subject: [PATCH 02/13] refactor: move paste sequence detection to `onKeypress` handler Signed-off-by: Snehil Shah --- .../@stdlib/repl/lib/multiline_handler.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js index 8ece32b00a85..7667861f763b 100644 --- a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js +++ b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js @@ -538,6 +538,15 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'onKeypress', function onK if ( !key ) { return; } + // Check for paste sequences... + if ( key.name === 'paste-start' ) { + this._multiline.pasteMode = true; + return; + } + if ( key.name === 'paste-end' ) { + this._multiline.pasteMode = false; + return; + } // Trigger multi-line input when encountering `CTRL+O` keybinding... if ( key.name === 'o' && key.ctrl ) { this._triggerMultiline(); @@ -568,15 +577,6 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'beforeKeypress', function this._ttyWrite.call( this._rli, data, key ); return; } - // Check for paste sequences... - if ( key.name === 'paste-start' ) { - this._multiline.pasteMode = true; - return; - } - if ( key.name === 'paste-end' ) { - this._multiline.pasteMode = false; - return; - } // Check whether to trigger multi-line mode or execute the command when `return` key is encountered... if ( key.name === 'return' ) { cmd = copy( this._cmd ); From 06b836cb85822c575eccdc783a73497fd807cd28 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Thu, 4 Jul 2024 17:38:47 +0000 Subject: [PATCH 03/13] feat: add setting to control auto disabling of bracketed-paste on exit Signed-off-by: Snehil Shah --- lib/node_modules/@stdlib/repl/README.md | 3 ++- lib/node_modules/@stdlib/repl/lib/defaults.js | 5 ++++- lib/node_modules/@stdlib/repl/lib/main.js | 6 ++++-- lib/node_modules/@stdlib/repl/lib/settings.js | 4 ++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/README.md b/lib/node_modules/@stdlib/repl/README.md index 314718aaeba5..24930256d282 100644 --- a/lib/node_modules/@stdlib/repl/README.md +++ b/lib/node_modules/@stdlib/repl/README.md @@ -83,8 +83,9 @@ The function supports specifying the following settings: - **autoClosePairs**: boolean indicating whether to automatically insert matching brackets, parentheses, and quotes. Default: `true`. - **autoDeletePairs**: boolean indicating whether to automatically delete adjacent matching brackets, parentheses, and quotes. Default: `true`. - **autoPage**: boolean indicating whether to automatically page return values having a display size exceeding the visible screen. When streams are TTY, the default is `true`; otherwise, the default is `false`. -- **bracketedPaste**: boolean indicating whether to enable bracketed paste mode. When streams are TTY, the default is `true`; otherwise, the default is `false`. +- **bracketedPaste**: boolean indicating whether to enable bracketed-paste mode. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **completionPreviews**: boolean indicating whether to display completion previews for auto-completion. When streams are TTY, the default is `true`; otherwise, the default is `false`. +- **autoDisableBracketedPasteOnExit**: boolean indicating whether to automatically disable bracketed-paste upon exiting the REPL. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **syntaxHighlighting**: boolean indicating whether to enable syntax highlighting of entered input expressions. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **theme**: initial color theme for syntax highlighting. Default: `stdlib-ansi-basic`. diff --git a/lib/node_modules/@stdlib/repl/lib/defaults.js b/lib/node_modules/@stdlib/repl/lib/defaults.js index 956c3c00b204..6bc31efa71e0 100644 --- a/lib/node_modules/@stdlib/repl/lib/defaults.js +++ b/lib/node_modules/@stdlib/repl/lib/defaults.js @@ -89,12 +89,15 @@ function defaults() { // Flag indicating whether to enable automatically page return values requiring a display size exceeding the visible screen (note: default depends on whether TTY): 'autoPage': void 0, - // Flag indicating whether to enable bracketed paste mode: + // Flag indicating whether to enable bracketed-paste mode (note: default depends on whether TTY): 'bracketedPaste': void 0, // Flag indicating whether to enable the display of completion previews for auto-completion (note: default depends on whether TTY): 'completionPreviews': void 0, + // Flag indicating whether to automatically disable bracketed-paste upon exiting the REPL (note: default depends on whether TTY): + 'autoDisableBracketedPasteOnExit': void 0, + // Flag indicating whether to enable syntax highlighting (note: default depends on whether TTY): 'syntaxHighlighting': void 0, diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index b5dfab99bc42..5181a0adc4e4 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -102,8 +102,9 @@ var debug = logger( 'repl' ); * @param {boolean} [options.settings.autoClosePairs=true] - boolean indicating whether to automatically insert matching brackets, parentheses, and quotes * @param {boolean} [options.settings.autoDeletePairs=true] - boolean indicating whether to automatically delete adjacent matching brackets, parentheses, and quotes * @param {boolean} [options.settings.autoPage] - boolean indicating whether to automatically page return values requiring a display size exceeding the visible screen -* @param {boolean} [options.settings.bracketedPaste] - boolean indicating whether to enable bracketed paste mode +* @param {boolean} [options.settings.bracketedPaste] - boolean indicating whether to enable bracketed-paste mode * @param {boolean} [options.settings.completionPreviews] - boolean indicating whether to enable completion previews for auto-completion +* @param {boolean} [options.settings.autoDisableBracketedPasteOnExit] - boolean indicating whether to automatically disable bracketed-paste upon exiting the REPL * @param {boolean} [options.settings.syntaxHighlighting] - boolean indicating whether to enable syntax highlighting * @param {string} [options.settings.theme] - initial color theme for syntax highlighting * @throws {Error} must provide valid options @@ -154,6 +155,7 @@ function REPL( options ) { opts.settings.autoPage = ( opts.settings.autoPage === void 0 ) ? opts.isTTY : opts.settings.autoPage; // eslint-disable-line max-len opts.settings.bracketedPaste = ( opts.settings.bracketedPaste === void 0 ) ? opts.isTTY : opts.settings.bracketedPaste; // eslint-disable-line max-len opts.settings.completionPreviews = ( opts.settings.completionPreviews === void 0 ) ? opts.isTTY : opts.settings.completionPreviews; // eslint-disable-line max-len + opts.settings.autoDisableBracketedPasteOnExit = ( opts.settings.autoDisableBracketedPasteOnExit === void 0 ) ? opts.isTTY : opts.settings.autoDisableBracketedPasteOnExit; // eslint-disable-line max-len opts.settings.syntaxHighlighting = ( opts.settings.syntaxHighlighting === void 0 ) ? opts.isTTY : opts.settings.syntaxHighlighting; // eslint-disable-line max-len debug( 'Options: %s', JSON.stringify({ @@ -411,7 +413,7 @@ function REPL( options ) { */ function onClose() { // Disable bracketed-paste mode in TTY environments: - if ( self._isTTY ) { + if ( self._settings.autoDisableBracketedPasteOnExit ) { self._multilineHandler.disableBracketedPaste(); } ostream.end(); diff --git a/lib/node_modules/@stdlib/repl/lib/settings.js b/lib/node_modules/@stdlib/repl/lib/settings.js index e998a5f00c1f..53a38eaffc00 100644 --- a/lib/node_modules/@stdlib/repl/lib/settings.js +++ b/lib/node_modules/@stdlib/repl/lib/settings.js @@ -48,6 +48,10 @@ var SETTINGS = { 'desc': 'Enable the display of completion previews for auto-completion.', 'type': 'boolean' }, + 'autoDisableBracketedPasteOnExit': { + 'desc': 'Automatically disable bracketed-paste upon exiting the REPL.', + 'type': 'boolean' + }, 'syntaxHighlighting': { 'desc': 'Enable syntax highlighting.', 'type': 'boolean' From 88d8b404a9b2ed43e7c096bd4aebcfee74709191 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Thu, 4 Jul 2024 17:41:20 +0000 Subject: [PATCH 04/13] fix: preserve indentation of pasted content by disabling TAB completions Signed-off-by: Snehil Shah --- .../@stdlib/repl/lib/completer_engine.js | 11 +++++++++++ .../@stdlib/repl/lib/multiline_handler.js | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/node_modules/@stdlib/repl/lib/completer_engine.js b/lib/node_modules/@stdlib/repl/lib/completer_engine.js index 5de916695d2e..3d845ed4bdaa 100644 --- a/lib/node_modules/@stdlib/repl/lib/completer_engine.js +++ b/lib/node_modules/@stdlib/repl/lib/completer_engine.js @@ -638,6 +638,12 @@ setNonEnumerableReadOnly( CompleterEngine.prototype, 'beforeKeypress', function this.closeCompleter(); break; + // If paste sequences detected, close the completer: + case 'paste-start': + this.closeCompleter(); + this._ttyWrite.call( this._rli, data, key ); + break; + // If arrow keys detected, allow navigating the completions... case 'down': debug( 'Received a DOWN keypress event...' ); @@ -660,6 +666,11 @@ setNonEnumerableReadOnly( CompleterEngine.prototype, 'beforeKeypress', function } return; } + // If we are in the middle of receiving pasted input, use TAB for indentation and don't trigger completions... + if ( this._multiline.isPasting() ) { + this._ttyWrite.call( this._rli, data, key ); + return; + } // Trigger TAB completions: cursor = this._rli.cursor; line = this._rli.line; diff --git a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js index 7667861f763b..152ce825d310 100644 --- a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js +++ b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js @@ -426,6 +426,19 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'disableBracketedPaste', f this._ostream.write( '\u001b[?2004l' ); }); +/** +* Checks whether the REPL is in the middle of receiving pasted input. +* +* @private +* @name isPasting +* @memberof MultilineHandler.prototype +* @type {Function} +* @returns {boolean} boolean indicating whether the REPL is currently receiving pasted input +*/ +setNonEnumerableReadOnly( MultilineHandler.prototype, 'isPasting', function isPasting() { + return this._multiline.pasteMode; +}); + /** * Processes input line data. * From 12bc919c9f3cb1745b3ca27db8f70262a0d0c2ee Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Thu, 4 Jul 2024 17:42:49 +0000 Subject: [PATCH 05/13] style: remove extra line Signed-off-by: Snehil Shah --- lib/node_modules/@stdlib/repl/lib/completer_engine.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/completer_engine.js b/lib/node_modules/@stdlib/repl/lib/completer_engine.js index 3d845ed4bdaa..e3058e4f8f35 100644 --- a/lib/node_modules/@stdlib/repl/lib/completer_engine.js +++ b/lib/node_modules/@stdlib/repl/lib/completer_engine.js @@ -628,7 +628,6 @@ setNonEnumerableReadOnly( CompleterEngine.prototype, 'beforeKeypress', function this._ttyWrite.call( this._rli, data, key ); return; } - // If user is already viewing completions, allow navigating it... if ( this._isNavigating ) { switch ( key.name ) { From ba8cf2cd7fd9c5fc0cd1ae019f234c9e62bb7974 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 5 Jul 2024 01:11:55 -0700 Subject: [PATCH 06/13] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 5181a0adc4e4..f02c743f9f55 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -412,7 +412,6 @@ function REPL( options ) { * @private */ function onClose() { - // Disable bracketed-paste mode in TTY environments: if ( self._settings.autoDisableBracketedPasteOnExit ) { self._multilineHandler.disableBracketedPaste(); } From 9c0c5dfe11cd6cdb4ec5c1b8a28eeea5151ef3ab Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 5 Jul 2024 01:14:29 -0700 Subject: [PATCH 07/13] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/multiline_handler.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js index 152ce825d310..5a592ad6c7a2 100644 --- a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js +++ b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js @@ -401,7 +401,7 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'resetInput', function res }); /** -* Enables bracketed paste mode in the terminal. +* Enables bracketed paste mode. * * @private * @name enableBracketedPaste @@ -414,7 +414,7 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'enableBracketedPaste', fu }); /** -* Disables bracketed paste mode in the terminal. +* Disables bracketed paste mode. * * @private * @name disableBracketedPaste @@ -427,7 +427,7 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'disableBracketedPaste', f }); /** -* Checks whether the REPL is in the middle of receiving pasted input. +* Checks whether the REPL is currently receiving pasted input. * * @private * @name isPasting From 93c751cc1a87e8a029156cfa74035ca5f17c9d82 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Fri, 5 Jul 2024 09:03:51 +0000 Subject: [PATCH 08/13] refactor: apply suggestions from code review Signed-off-by: Snehil Shah --- lib/node_modules/@stdlib/repl/lib/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index f02c743f9f55..16c439dcb3c1 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -153,7 +153,7 @@ function REPL( options ) { } opts.isTTY = ( opts.isTTY === void 0 ) ? opts.output.isTTY : opts.isTTY; opts.settings.autoPage = ( opts.settings.autoPage === void 0 ) ? opts.isTTY : opts.settings.autoPage; // eslint-disable-line max-len - opts.settings.bracketedPaste = ( opts.settings.bracketedPaste === void 0 ) ? opts.isTTY : opts.settings.bracketedPaste; // eslint-disable-line max-len + opts.settings.bracketedPaste = ( opts.settings.bracketedPaste === void 0 && opts.isTTY ) ? true : opts.settings.bracketedPaste; // eslint-disable-line max-len opts.settings.completionPreviews = ( opts.settings.completionPreviews === void 0 ) ? opts.isTTY : opts.settings.completionPreviews; // eslint-disable-line max-len opts.settings.autoDisableBracketedPasteOnExit = ( opts.settings.autoDisableBracketedPasteOnExit === void 0 ) ? opts.isTTY : opts.settings.autoDisableBracketedPasteOnExit; // eslint-disable-line max-len opts.settings.syntaxHighlighting = ( opts.settings.syntaxHighlighting === void 0 ) ? opts.isTTY : opts.settings.syntaxHighlighting; // eslint-disable-line max-len @@ -326,7 +326,7 @@ function REPL( options ) { this.settings( 'theme', opts.settings.theme ); // Initialize specified bracketed-paste setting in TTY environments: - if ( this._isTTY ) { + if ( opts.settings.bracketedPaste !== void 0 ) { this.settings( 'bracketedPaste', opts.settings.bracketedPaste ); } // Check whether to load and execute a JavaScript file (e.g., prior REPL history) upon startup... @@ -412,7 +412,7 @@ function REPL( options ) { * @private */ function onClose() { - if ( self._settings.autoDisableBracketedPasteOnExit ) { + if ( self._settings.bracketedPaste && self._settings.autoDisableBracketedPasteOnExit ) { // eslint-disable-line max-len self._multilineHandler.disableBracketedPaste(); } ostream.end(); From 6a72b73c9c2865a7303e3d230d942fd00580df8c Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Fri, 5 Jul 2024 09:27:10 +0000 Subject: [PATCH 09/13] fix: ignore `autoCloser` when pasting Signed-off-by: Snehil Shah --- .../@stdlib/repl/lib/auto_close_pairs.js | 12 ++++++++++-- lib/node_modules/@stdlib/repl/lib/main.js | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/auto_close_pairs.js b/lib/node_modules/@stdlib/repl/lib/auto_close_pairs.js index 2d8e5cf5dbde..7cb547108bf8 100644 --- a/lib/node_modules/@stdlib/repl/lib/auto_close_pairs.js +++ b/lib/node_modules/@stdlib/repl/lib/auto_close_pairs.js @@ -65,17 +65,19 @@ function isQuote( ch ) { * @param {Object} rli - readline instance * @param {boolean} autoClose - boolean indicating whether auto-closing should be initially enabled * @param {boolean} autoDelete - boolean indicating whether auto-deleting should be initially enabled +* @param {MultilineHandler} multiline - multiline handler instance * @returns {AutoCloser} auto-closer instance */ -function AutoCloser( rli, autoClose, autoDelete ) { +function AutoCloser( rli, autoClose, autoDelete, multiline ) { if ( !(this instanceof AutoCloser) ) { - return new AutoCloser( rli, autoClose, autoDelete ); + return new AutoCloser( rli, autoClose, autoDelete, multiline ); } debug( 'Creating an auto-closer...' ); this._rli = rli; this._ignoreBackspace = false; this._autoClose = autoClose; this._autoDelete = autoDelete; + this._multiline = multiline; return this; } @@ -316,6 +318,9 @@ setNonEnumerableReadOnly( AutoCloser.prototype, 'beforeKeypress', function befor if ( !this._autoDelete ) { return false; } + if ( this._multiline.isPasting() ) { + return false; + } if ( !key || key.name !== 'backspace' ) { return false; } @@ -360,6 +365,9 @@ setNonEnumerableReadOnly( AutoCloser.prototype, 'onKeypress', function onKeypres if ( !this._autoClose ) { return false; } + if ( this._multiline.isPasting() ) { + return false; + } cursor = this._rli.cursor; line = this._rli.line; diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 16c439dcb3c1..51af7dc355af 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -279,7 +279,7 @@ function REPL( options ) { setNonEnumerableReadOnly( this, '_completerEngine', new CompleterEngine( this, this._completer, this._wstream, this._rli._ttyWrite ) ); // Create a new auto-closer: - setNonEnumerableReadOnly( this, '_autoCloser', new AutoCloser( this._rli, this._settings.autoClosePairs, this._settings.autoDeletePairs ) ); + setNonEnumerableReadOnly( this, '_autoCloser', new AutoCloser( this._rli, this._settings.autoClosePairs, this._settings.autoDeletePairs, this._multilineHandler ) ); // Initialize a preview completer: setNonEnumerableReadOnly( this, '_previewCompleter', new PreviewCompleter( this._rli, this._completer, this._ostream, this._settings.completionPreviews ) ); From 55e365f326850f441fbb173b7a8809ce9cbd34cc Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Fri, 5 Jul 2024 10:10:53 +0000 Subject: [PATCH 10/13] style: keep it consistent Signed-off-by: Snehil Shah --- lib/node_modules/@stdlib/repl/lib/multiline_handler.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js index 5a592ad6c7a2..d3fa1a59c7c3 100644 --- a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js +++ b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js @@ -401,9 +401,8 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'resetInput', function res }); /** -* Enables bracketed paste mode. +* Enables bracketed-paste mode. * -* @private * @name enableBracketedPaste * @memberof MultilineHandler.prototype * @type {Function} @@ -414,9 +413,8 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'enableBracketedPaste', fu }); /** -* Disables bracketed paste mode. +* Disables bracketed-paste mode. * -* @private * @name disableBracketedPaste * @memberof MultilineHandler.prototype * @type {Function} @@ -429,7 +427,6 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'disableBracketedPaste', f /** * Checks whether the REPL is currently receiving pasted input. * -* @private * @name isPasting * @memberof MultilineHandler.prototype * @type {Function} From acad9bf4e38906e7f31154a4a9a5f850dcce3e48 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 5 Jul 2024 11:37:42 -0700 Subject: [PATCH 11/13] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 51af7dc355af..4c872c37bf2f 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -325,7 +325,7 @@ function REPL( options ) { // Set the syntax highlighting theme... this.settings( 'theme', opts.settings.theme ); - // Initialize specified bracketed-paste setting in TTY environments: + // Initialize bracketed-paste: if ( opts.settings.bracketedPaste !== void 0 ) { this.settings( 'bracketedPaste', opts.settings.bracketedPaste ); } From 295da0b6997666a971a22bd636a226b4a559f937 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 5 Jul 2024 11:39:07 -0700 Subject: [PATCH 12/13] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/README.md b/lib/node_modules/@stdlib/repl/README.md index 24930256d282..210e84822a06 100644 --- a/lib/node_modules/@stdlib/repl/README.md +++ b/lib/node_modules/@stdlib/repl/README.md @@ -84,8 +84,8 @@ The function supports specifying the following settings: - **autoDeletePairs**: boolean indicating whether to automatically delete adjacent matching brackets, parentheses, and quotes. Default: `true`. - **autoPage**: boolean indicating whether to automatically page return values having a display size exceeding the visible screen. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **bracketedPaste**: boolean indicating whether to enable bracketed-paste mode. When streams are TTY, the default is `true`; otherwise, the default is `false`. -- **completionPreviews**: boolean indicating whether to display completion previews for auto-completion. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **autoDisableBracketedPasteOnExit**: boolean indicating whether to automatically disable bracketed-paste upon exiting the REPL. When streams are TTY, the default is `true`; otherwise, the default is `false`. +- **completionPreviews**: boolean indicating whether to display completion previews for auto-completion. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **syntaxHighlighting**: boolean indicating whether to enable syntax highlighting of entered input expressions. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **theme**: initial color theme for syntax highlighting. Default: `stdlib-ansi-basic`. From 8f8e1a4fb13cc04969ab226b65ae701ac932261a Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 5 Jul 2024 11:40:00 -0700 Subject: [PATCH 13/13] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/README.md b/lib/node_modules/@stdlib/repl/README.md index 210e84822a06..884cc6926fd8 100644 --- a/lib/node_modules/@stdlib/repl/README.md +++ b/lib/node_modules/@stdlib/repl/README.md @@ -84,7 +84,7 @@ The function supports specifying the following settings: - **autoDeletePairs**: boolean indicating whether to automatically delete adjacent matching brackets, parentheses, and quotes. Default: `true`. - **autoPage**: boolean indicating whether to automatically page return values having a display size exceeding the visible screen. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **bracketedPaste**: boolean indicating whether to enable bracketed-paste mode. When streams are TTY, the default is `true`; otherwise, the default is `false`. -- **autoDisableBracketedPasteOnExit**: boolean indicating whether to automatically disable bracketed-paste upon exiting the REPL. When streams are TTY, the default is `true`; otherwise, the default is `false`. +- **autoDisableBracketedPasteOnExit**: boolean indicating whether to automatically disable bracketed-paste upon exiting the REPL. When streams are TTY and bracketed paste is enabled, the default is `true`; otherwise, the default is `false`. - **completionPreviews**: boolean indicating whether to display completion previews for auto-completion. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **syntaxHighlighting**: boolean indicating whether to enable syntax highlighting of entered input expressions. When streams are TTY, the default is `true`; otherwise, the default is `false`. - **theme**: initial color theme for syntax highlighting. Default: `stdlib-ansi-basic`.