Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add support for auto-closing brackets/quotations in the REPL #1680

Merged
merged 95 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
3431b3c
feat: add auto-closing brackets & quotations in REPL
Snehil-Shah Mar 3, 2024
81d3b7d
feat: add option to toggle auto-closing behavior
Snehil-Shah Mar 3, 2024
3fbdd4e
refactor: prevent use of private readline methods
Snehil-Shah Mar 5, 2024
3f5f685
feat: add generic `settings` command to manage all settings
Snehil-Shah Mar 5, 2024
a6bc4e2
fix: remove autoClose from defaults
Snehil-Shah Mar 5, 2024
d8716d7
fix: remove `autoClose` from REPL opts
Snehil-Shah Mar 5, 2024
3ed9eff
fix: error messages
Snehil-Shah Mar 5, 2024
7b7009b
feat: manual multiline mode from cursor position
Snehil-Shah Mar 8, 2024
d0c66c6
remove unused flag
Snehil-Shah Mar 9, 2024
8278728
feat: handle instinctive closing symbols for improved ergonomics
Snehil-Shah Mar 13, 2024
e4884e5
refactor: suggestions
Snehil-Shah Mar 19, 2024
1202732
feat: add auto indentation
Snehil-Shah Mar 19, 2024
db50041
feat: handle special cases to improve ergonomics
Snehil-Shah Mar 20, 2024
15821a5
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into sn…
kgryte Mar 27, 2024
db29963
fix: consolidate keypress listeners
kgryte Mar 27, 2024
19ef85b
refactor: always attach a keypress listener
kgryte Mar 27, 2024
6b865c9
refactor: document `settings` command signatures
kgryte Mar 27, 2024
35ec9b7
refactor: document defaults and add settings object
kgryte Mar 27, 2024
357431a
refactor: add module exposing settings validators
kgryte Mar 27, 2024
6e75e67
refactor: add module to validate a settings object
kgryte Mar 27, 2024
85687d3
fix: update error messages
kgryte Mar 27, 2024
89f9802
fix: add missing settings file
kgryte Mar 27, 2024
e70d3db
docs: update comment
kgryte Mar 27, 2024
8c5f3cd
refactor: add support for validating a settings object
kgryte Mar 27, 2024
6021d0f
refactor: remove duplicate option setting and document settings
kgryte Mar 27, 2024
4ea8a03
refactor: make the default dependent on whether TTY
kgryte Mar 27, 2024
5786c14
style: disable lint rules
kgryte Mar 27, 2024
3747888
docs: document settings
kgryte Mar 27, 2024
1595697
refactor: add module exporting a list of settings names
kgryte Mar 27, 2024
5e54ec5
refactor: use module to get list of settings names
kgryte Mar 27, 2024
3de8ec5
refactor: update help text generation
kgryte Mar 27, 2024
fd3b2a9
refactor: only pass down settings object
kgryte Mar 27, 2024
02fad69
fix: use setting name when constructing error message
kgryte Mar 27, 2024
9dfa13c
refactor: add module to test if a value is a setting name
kgryte Mar 28, 2024
0d8d3a9
refactor: update error messages
kgryte Mar 28, 2024
22aba0c
feat: add `settings` method for getting and setting REPL settings
kgryte Mar 28, 2024
2dff629
refactor: delegate to `settings` method to validate arguments
kgryte Mar 28, 2024
9f35dff
docs: document `settings` method
kgryte Mar 28, 2024
d8da17a
refactor: handle returning setting value as would normal command
kgryte Mar 28, 2024
336d7a0
refactor: update confirmation message
kgryte Mar 28, 2024
d00958e
docs: update description
kgryte Mar 28, 2024
7e8f592
refactor: remove support for manually entering multi-line editing
kgryte Mar 28, 2024
590649d
docs: update copy
kgryte Mar 28, 2024
89415bc
refactor: bind variables to REPL instance to allow "toggabilty"
kgryte Mar 28, 2024
0f577cc
refactor: move symbols table to separate file
kgryte Mar 28, 2024
d4e0730
fix: update require path
kgryte Mar 28, 2024
1f14f24
refactor: convert auto-matcher to a class
kgryte Mar 28, 2024
e4f50ba
refactor: make private properties read-only
kgryte Mar 28, 2024
53ae830
fix: only perform preview completion when no collisions are possible
kgryte Mar 28, 2024
0af02a2
refactor: clean implementation with scoped variables
kgryte Mar 28, 2024
acc8ab6
refactor: use helper functions
kgryte Mar 28, 2024
0c55033
docs: add FIXME
kgryte Mar 28, 2024
ec2c283
refactor: add modules for specifying settings arguments amenable to a…
kgryte Mar 28, 2024
5212dcc
refactor: add module exporting a regexp for matching settings APIs
kgryte Mar 28, 2024
da738c4
refactor: add support for settings name auto-completion
kgryte Mar 28, 2024
a90fc2d
refactor: defer to completer when receiving a TAB character
kgryte Mar 29, 2024
0059b77
refactor: use internal utility to support suppressing log messages
kgryte Mar 29, 2024
5e26c45
refactor: reorder cases in alphabetical order
kgryte Mar 30, 2024
98364f6
refactor: fix order
kgryte Mar 30, 2024
ab671c2
refactor: update implementation to use AST
kgryte Mar 31, 2024
691b45b
style: add lint warnings
kgryte Mar 31, 2024
cc6627b
style: address lint warning
kgryte Mar 31, 2024
1be8b6b
test: add auto-match tests and move fixture
kgryte Mar 31, 2024
ec672ab
refactor: rename setting
kgryte Mar 31, 2024
5434e3b
docs: rename setting
kgryte Mar 31, 2024
1ff156f
refactor: remove unused property
kgryte Mar 31, 2024
662e1cf
fix: update property name
kgryte Mar 31, 2024
6d8390d
fix: allow auto-closing within template and object expressions
kgryte Mar 31, 2024
8e09e8e
test: add RegExp test
kgryte Mar 31, 2024
8f9dce8
fix: address completer bug when completing after special characters
kgryte Mar 31, 2024
0bb6ae9
refactor: add support for auto-deleting character pairs
kgryte Mar 31, 2024
c6d997d
refactor: move deletion logic to auto-closer due to shared state
kgryte Mar 31, 2024
d0d1dbf
fix: ensure corresponding closing symbol when auto-deleting pairs
kgryte Mar 31, 2024
d3fd4ef
docs: update copy
kgryte Mar 31, 2024
ff0a086
docs: fix jsdoc
Snehil-Shah Mar 31, 2024
10de907
test: add tests for auto-deletion
Snehil-Shah Mar 31, 2024
2ae5f73
Merge branch 'stdlib-js:develop' into repl
Snehil-Shah Mar 31, 2024
2f53984
Revert "docs: fix jsdoc"
Snehil-Shah Mar 31, 2024
a1477a3
test: fix tests
Snehil-Shah Mar 31, 2024
6ab1028
refactor: separate auto-delete & auto-closing tests
Snehil-Shah Mar 31, 2024
6b1f6f0
refactor: move conditional to the method itself
Snehil-Shah Mar 31, 2024
b8344c8
refactor: early return to avoid unnecessary indentation and rename pa…
kgryte Mar 31, 2024
d27f4c5
docs: document properties
kgryte Mar 31, 2024
a70003f
test: add separate test generation script
kgryte Mar 31, 2024
0afd3b8
docs: update parameter type to reflect usage
kgryte Mar 31, 2024
b25fcaa
refactor: move regular expression to separate file
kgryte Mar 31, 2024
a960530
refactor: access preceding character directly
kgryte Apr 1, 2024
aee610c
refactor: replicate logic in private method
kgryte Apr 1, 2024
5653b88
refactor: delegate open symbol processing to private method
kgryte Apr 1, 2024
f7cc5c7
refactor: copy logic for handling a closing symbol to a private method
kgryte Apr 1, 2024
badfc2c
refactor: delegate to private method for handling a closing symbol
kgryte Apr 1, 2024
840e972
refactor: implement handling of opening symbol during auto-deletion i…
kgryte Apr 1, 2024
52de42c
refactor: delegate to private method
kgryte Apr 1, 2024
03b1fd0
docs: update param type
kgryte Apr 1, 2024
24bb5cc
docs: fix copyright year
kgryte Apr 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/node_modules/@stdlib/repl/lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var onVars = require( './commands/vars.js' );
var onVarsWorkspace = require( './commands/vars_workspace.js' );
var onWorkspace = require( './commands/workspace.js' );
var onWorkspaces = require( './commands/workspaces.js' );
var onSettings = require( './commands/settings.js' );


// MAIN //
Expand Down Expand Up @@ -122,6 +123,7 @@ function commands( repl ) {
cmds.push( [ 'rerequire', onRerequire( repl ), false ] );
cmds.push( [ 'rerun', onRerun( repl ), false ] );
cmds.push( [ 'reset', onReset( repl ), false ] );
cmds.push( [ 'settings', onSettings( repl ), false ] );
cmds.push( [ 'tutorial', onTutorial( repl ), false ] );
cmds.push( [ 'userDoc', onUserDoc( repl ), false ] );
cmds.push( [ 'vars', onVars( repl ), false ] );
Expand Down
136 changes: 136 additions & 0 deletions lib/node_modules/@stdlib/repl/lib/commands/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint-disable no-underscore-dangle */

'use strict';

// MODULES //

var logger = require( 'debug' );
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var isBoolean = require( '@stdlib/assert/is-boolean' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var objectKeys = require( '@stdlib/utils/keys' );
var format = require( '@stdlib/string/format' );


// VARIABLES //

var debug = logger( 'repl:command:settings' );
var SETTINGS = {
'autoCloseSymbols': {
'desc': 'Auto-close brackets and quotations.'
}
};
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved


// FUNCTIONS //

/**
* Returns settings help text.
*
* @private
* @returns {string} settings help text
*/
function help() {
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
var HELP_TEXT;
var names;
var o;
var i;

names = objectKeys( SETTINGS );
HELP_TEXT = '\n';
for ( i = 0; i < names.length; i++ ) {
o = SETTINGS[ names[ i ] ];
HELP_TEXT += names[ i ] + '\n';
HELP_TEXT += ' ';
if ( o.desc ) {
HELP_TEXT += SETTINGS[ names[ i ] ].desc;
} else {
HELP_TEXT += '(no description available)';
}
HELP_TEXT += '\n\n';
}
return HELP_TEXT;
}


// MAIN //

/**
* Returns a callback to be invoked upon calling the `settings` command.
*
* @private
* @param {REPL} repl - REPL instance
* @returns {Function} callback
*/
function command( repl ) {
return onCommand;

/**
* Manages REPL settings.
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
*
* If no arguments are given, it prints all settings with their description.
* If one argument is given, it fetches the value of the setting with the given name and prints it.
* If two arguments are given, it updates the value of the given setting name to the given value.
*
* @private
* @param {string} [name] - Setting name
* @param {boolean} [value] - New setting value
* @throws {TypeError} First argument must be a string
* @throws {Error} Must recognize setting name
* @throws {TypeError} Second argument must be a boolean
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
*/
function onCommand( name, value ) {
var err;
if ( arguments.length === 0 ) {
repl._ostream.write( help() );
return;
}
if ( !isString( name ) ) {
err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', name ) );
debug( 'Error: %s', err.message );
repl._ostream.write( format( 'Error: %s\n.', err.message ) );
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
return;
}
if ( !hasOwnProp( SETTINGS, name ) ) {
err = new Error( format( 'invalid argument. Unrecognized setting. Value: `%s`.', name ) );
debug( 'Error: %s', err.message );
repl._ostream.write( format( 'Error: %s\n.', err.message ) );
return;
}
if (arguments.length === 1) {
repl._ostream.write('\n'+repl._settings[name]+'\n\n');
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
return;
}
if ( !isBoolean(value) ) {
err = new TypeError( format( 'invalid argument. Second argument must be a boolean. Value: `%s`.', name ) );
debug( 'Error: %s', err.message );
repl._ostream.write( format( 'Error: %s\n.', err.message ) );
return;
}
repl._settings[name] = value;
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
repl._ostream.write( format( '\nUpdated setting %s to %s.\n\n', name, ( value ) ? 'true' : 'false' ) );
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
}
}


// EXPORTS //

module.exports = command;
4 changes: 4 additions & 0 deletions lib/node_modules/@stdlib/repl/lib/help_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ var MSG = [
' userDoc() Add user-defined documentation.',
' clearUserDocs() Clear user-defined documentation.',
'',
' settings() List REPL settings.',
' settings(name) Get setting\'s value.',
' settings(name,value) Update setting with the new value.',
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
'',
' clearHistory() Clear the REPL history.',
'',
' clear() Clear the entire REPL screen and scrollback history.',
Expand Down
82 changes: 80 additions & 2 deletions lib/node_modules/@stdlib/repl/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
var properties = require( '@stdlib/utils/properties' );
var append = require( '@stdlib/utils/append' );
var format = require( '@stdlib/string/format' );
var repeat = require( '@stdlib/string/repeat' );
var Boolean = require( '@stdlib/boolean/ctor' );
var cwd = require( '@stdlib/process/cwd' );
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
Expand Down Expand Up @@ -202,8 +203,18 @@
// Define the current workspace:
setNonEnumerable( this, '_currentWorkspace', 'base' );

// Initialize an internal flag indicating whether a user is entering a multi-line command:
setNonEnumerable( this, '_multiline_mode', false );
// Initialize an internal object storing user settings:
setNonEnumerable( this, '_settings', {} );
setNonEnumerable( this._settings, 'autoCloseSymbols', true );
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved

// Initialize an internal status object for controlling multi-line mode:
setNonEnumerable( this, '_multiline_mode', {} );
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
setNonEnumerable( this._multiline_mode, 'status', false );
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
setNonEnumerable( this._multiline_mode, 'manual', false );
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
setNonEnumerable( this._multiline_mode, 'buffer', '' );

// Initialize an internal flag indicating whether auto closing symbols is in progress
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
setNonEnumerable( this, '_auto_close_status', false );

// Initialize an internal flag indicating whether the REPL has been closed:
setNonEnumerable( this, '_closed', false );
Expand Down Expand Up @@ -235,6 +246,7 @@
this._rli.on( 'close', onClose );
this._rli.on( 'line', onLine );
this._rli.on( 'SIGINT', onSIGINT );
this._rli.input.on( 'keypress', onKeypress );

// Add listener for "command" events:
this.on( 'command', onCommand );
Expand All @@ -242,9 +254,9 @@
// Write a welcome message:
this._ostream.write( opts.welcome );

// TODO: check whether to synchronously initialize a REPL history file

Check warning on line 257 in lib/node_modules/@stdlib/repl/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: check whether to synchronously...'

// TODO: check whether to synchronously initialize a REPL log file

Check warning on line 259 in lib/node_modules/@stdlib/repl/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: check whether to synchronously...'

// Check whether to load and execute a JavaScript file (e.g., prior REPL history) upon startup...
if ( opts.load ) {
Expand All @@ -268,6 +280,72 @@
}
}

/**
* Callback invoked upon a readline interface "keypress" event.
*
* @private
* @param {string} chunk - character pressed by the user
* @param {Object} key - keypress event information
*/
function onKeypress( chunk, key ) {
var charsAfterCursor;
var codeAfterCursor;
var symbols = {
'{': '}',
'[': ']',
'(': ')',
'\'': '\'',
'"': '"',
'`': '`'
};

// For ALT+ENTER keypress, manually enter multi-line mode:
if ( key && key.name === 'return' && key.meta ) {
charsAfterCursor = self._rli.line.length - self._rli.cursor;
codeAfterCursor = self._rli.line.substring( self._rli.cursor );

// Update flag
self._multiline_mode.manual = true;

// Store code after cursor in buffer for next line
self._multiline_mode.buffer = codeAfterCursor;
self._ostream.write( repeat( '\x1b[C', charsAfterCursor ) + repeat( '\b \b', charsAfterCursor ) );
self._rli.line = self._rli.line.substring( 0, self._rli.cursor );

// Simulate `line` event
self._rli.write( null, {
'name': 'return'
});
}

// For a bracket/quotation input, append corresponding closing symbol
if ( self._settings.autoCloseSymbols && symbols[chunk] ) {
self._rli.write( symbols[chunk] );
self._rli.write( null, {
'ctrl': true,
'name': 'b'
} );
self._auto_close_status = true;
return;
}

// Handle instinctive closing symbols
if ( self._auto_close_status ) {
if (
typeof chunk !== 'undefined' &&
symbols[ self._rli.line[ self._rli.cursor - 2 ] ] === chunk
) {
self._rli.write( null, {
'name': 'backspace'
} );
self._rli.write( null, {
'name': 'right'
} );
}
self._auto_close_status = false;
}
}
kgryte marked this conversation as resolved.
Show resolved Hide resolved

/**
* Callback invoked upon a readline interface "close" event.
*
Expand Down Expand Up @@ -337,9 +415,9 @@
// Update the internal command history buffer: [..., <id>, <cmd>, <success>, ...]
self._history.push( self._count, cmd, success );

// TODO: if successful and if necessary, (asynchronously?) write the command to a history file (question: do we only want to write successful commands to the history file? maybe we need to option for limiting to successful commands?)

Check warning on line 418 in lib/node_modules/@stdlib/repl/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: if successful and if necessary,...'

// TODO: if necessary, (asynchronously?) write the command and result to a log file (JSON serialization?)

Check warning on line 420 in lib/node_modules/@stdlib/repl/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: if necessary, (asynchronously?)...'
}
}

Expand Down Expand Up @@ -473,7 +551,7 @@

// Before creating a new execution context in a non-sandboxed environment, remove current workspace variables in order to allow garbage collection and avoid memory leaks (e.g., variables/functions declared during a REPL session which might remain bound to the environment `global` after clearing a REPL):
if ( this._sandbox === false ) {
// WARNING: in a non-sandboxed environment, if a global variable is externally introduced during a REPL session (i.e., introduced via a mechanism outside of the REPL environment), we will delete that global variable, which means the following logic may introduce unintended side-effects for this particular edge case (e.g., application code may expect the presence of the subsequently deleted global variable). While not ideal, (a) user applications should not be introducing globals to begin with and (b) the probability of a user running a REPL session, a user clearing that REPL session, AND a global variable being introduced between starting a REPL and clearing the REPL should be negligible.

Check warning on line 554 in lib/node_modules/@stdlib/repl/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'warning' comment: 'WARNING: in a non-sandboxed environment,...'
tmp = this._context.vars();
for ( i = 0; i < tmp.length; i++ ) {
if ( isConfigurableProperty( this._context, tmp[ i ] ) ) {
Expand Down Expand Up @@ -593,7 +671,7 @@
* // TODO
*/
setNonEnumerableReadOnly( REPL.prototype, 'load', function load( fpath, clbk ) {
var self;

Check warning on line 674 in lib/node_modules/@stdlib/repl/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

File has too many lines (422). Maximum allowed is 300
var file;
var len;
var i;
Expand Down Expand Up @@ -866,9 +944,9 @@
// Clear the command queue:
this._queue.clear();

// TODO: ensure REPL history is saved (flushed) to file before closing the REPL (see https://github.com/nodejs/node/blob/b21e7c7bcf23a2715951e4cd96180e4dbf1dcd4d/lib/repl.js#L805)

Check warning on line 947 in lib/node_modules/@stdlib/repl/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: ensure REPL history is saved...'

// TODO: ensure REPL log is saved (flushed) to file before closing the REPL

Check warning on line 949 in lib/node_modules/@stdlib/repl/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: ensure REPL log is saved (flushed)...'

nextTick( onTick );

Expand All @@ -891,7 +969,7 @@

// If this is a non-sandboxed REPL, remove global variables/properties which were introduced during context creation and by a user during a REPL session...
if ( self._sandbox === false ) {
// WARNING: in a non-sandboxed environment, if a global variable is externally introduced during a REPL session (i.e., introduced via a mechanism outside of the REPL environment), we will delete that global variable, which means the following logic may introduce unintended side-effects for this particular edge case (e.g., application code may expect the presence of the subsequently deleted global variable). While not ideal, (a) user applications should not be introducing globals to begin with and (b) the probability of a user running a REPL session, a user closing that REPL session, AND a global variable being introduced between starting a REPL and closing the REPL should be negligible.

Check warning on line 972 in lib/node_modules/@stdlib/repl/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'warning' comment: 'WARNING: in a non-sandboxed environment,...'
tmp = self._context.vars(); // current workspace variables
for ( i = 0; i < tmp.length; i++ ) {
if ( isConfigurableProperty( self._context, tmp[ i ] ) ) {
Expand Down
19 changes: 16 additions & 3 deletions lib/node_modules/@stdlib/repl/lib/process_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
var logger = require( 'debug' );
var Parser = require( 'acorn' ).Parser;
var parseLoose = require( 'acorn-loose' ).parse;
var repeat = require( '@stdlib/string/repeat' );
var displayPrompt = require( './display_prompt.js' );
var drain = require( './drain.js' );
var multilinePlugin = require( './acorn_detect_multiline_input.js' );
Expand Down Expand Up @@ -62,9 +63,21 @@ function processLine( repl, line ) {
var tmp;

debug( 'Line: %s', line );
repl._multiline_mode = false; // false until proven otherwise
repl._multiline_mode.status = false; // false until proven otherwise

cmd = repl._cmd.join( '\n' ) + line;
if ( repl._multiline_mode.manual ) {
debug( 'Detected multi-line input via modifier-key. Waiting for additional lines...' );
repl._cmd.push( line );
repl._multiline_mode.status = true;
repl._multiline_mode.manual = false;
displayPrompt( repl, false );
repl._ostream.write( repl._multiline_mode.buffer );
repl._ostream.write(repeat('\x1b[D', repl._multiline_mode.buffer.length));
Snehil-Shah marked this conversation as resolved.
Show resolved Hide resolved
repl._rli.line = repl._multiline_mode.buffer;
repl._multiline_mode.buffer = ''; // empty buffer
return;
}
if ( RE_WHITESPACE.test( cmd ) ) {
displayPrompt( repl, false );
return;
Expand All @@ -83,7 +96,7 @@ function processLine( repl, line ) {
if ( hasMultilineError( cmd, AOPTS ) ) {
debug( 'Detected multi-line input. Waiting for additional lines...' );
repl._cmd.push( line );
repl._multiline_mode = true;
repl._multiline_mode.status = true;
displayPrompt( repl, false );
return;
}
Expand All @@ -97,7 +110,7 @@ function processLine( repl, line ) {
if ( hasMultilineError( tmp, AOPTS ) ) {
debug( 'Detected multi-line input. Waiting for additional lines...' );
repl._cmd.push( line );
repl._multiline_mode = true;
repl._multiline_mode.status = true;
displayPrompt( repl, false );
return;
}
Expand Down
Loading