Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jun 21, 2024
1 parent c9b888c commit 676acac
Show file tree
Hide file tree
Showing 6 changed files with 648 additions and 165 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

##### Features

- [`32b9ebf`](https://github.com/stdlib-js/stdlib/commit/32b9ebf43277ff53c079178ba563fb3597661a2c) - add multiline editing in the REPL [(#2347)](https://github.com/stdlib-js/stdlib/pull/2347)
- [`0856277`](https://github.com/stdlib-js/stdlib/commit/0856277523259bf111501ff87d54104b361b0fa3) - add combined styles and inbuilt syntax highlighting themes in the REPL
- [`b4c12b7`](https://github.com/stdlib-js/stdlib/commit/b4c12b7c4a76cfa71164d1b01fcbfca0426abbb3) - add APIs, commands, and tests for REPL syntax-highlighting [(#2291)](https://github.com/stdlib-js/stdlib/pull/2291)
- [`24f4a8f`](https://github.com/stdlib-js/stdlib/commit/24f4a8f24c08dd25686afc4cfb78be2e0045e844) - add syntax highlighting in the REPL
Expand Down Expand Up @@ -53,9 +54,9 @@

##### Closed Issues

A total of 4 issues were closed in this release:
A total of 5 issues were closed in this release:

[#1672](https://github.com/stdlib-js/stdlib/issues/1672), [#1775](https://github.com/stdlib-js/stdlib/issues/1775), [#2149](https://github.com/stdlib-js/stdlib/issues/2149), [#2175](https://github.com/stdlib-js/stdlib/issues/2175)
[#1672](https://github.com/stdlib-js/stdlib/issues/1672), [#1775](https://github.com/stdlib-js/stdlib/issues/1775), [#2060](https://github.com/stdlib-js/stdlib/issues/2060), [#2149](https://github.com/stdlib-js/stdlib/issues/2149), [#2175](https://github.com/stdlib-js/stdlib/issues/2175)

</section>

Expand Down Expand Up @@ -233,9 +234,9 @@ A total of 4 issues were closed in this release:

### Closed Issues

A total of 4 issues were closed in this release:
A total of 5 issues were closed in this release:

[#1672](https://github.com/stdlib-js/stdlib/issues/1672), [#1775](https://github.com/stdlib-js/stdlib/issues/1775), [#2149](https://github.com/stdlib-js/stdlib/issues/2149), [#2175](https://github.com/stdlib-js/stdlib/issues/2175)
[#1672](https://github.com/stdlib-js/stdlib/issues/1672), [#1775](https://github.com/stdlib-js/stdlib/issues/1775), [#2060](https://github.com/stdlib-js/stdlib/issues/2060), [#2149](https://github.com/stdlib-js/stdlib/issues/2149), [#2175](https://github.com/stdlib-js/stdlib/issues/2175)

</section>

Expand Down Expand Up @@ -267,6 +268,7 @@ A total of 9 people contributed to this release. Thank you to the following cont

<details>

- [`32b9ebf`](https://github.com/stdlib-js/stdlib/commit/32b9ebf43277ff53c079178ba563fb3597661a2c) - **feat:** add multiline editing in the REPL [(#2347)](https://github.com/stdlib-js/stdlib/pull/2347) _(by Snehil Shah, Athan Reines)_
- [`ba4ce18`](https://github.com/stdlib-js/stdlib/commit/ba4ce188564d0207be7b780202dd4966b8dd9459) - **feat:** add `amskput` to namespace _(by Athan Reines)_
- [`3eb5c20`](https://github.com/stdlib-js/stdlib/commit/3eb5c20b3f683af347e2c502e670fb6c88527f6c) - **feat:** add `aplace` to namespace _(by Athan Reines)_
- [`642d473`](https://github.com/stdlib-js/stdlib/commit/642d4736d832f9dd83df75dfb63e56689e1fbb89) - **docs:** update REPL namespace documentation [(#2416)](https://github.com/stdlib-js/stdlib/pull/2416) _(by stdlib-bot, Athan Reines)_
Expand Down
15 changes: 9 additions & 6 deletions lib/completer_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,34 +246,37 @@ setNonEnumerableReadOnly( PreviewCompleter.prototype, 'onKeypress', function onK
* @type {Function}
* @param {string} data - input data
* @param {(Object|void)} key - key object
* @returns {void}
* @returns {boolean} boolean indicating whether the preview was auto-completed
*/
setNonEnumerableReadOnly( PreviewCompleter.prototype, 'beforeKeypress', function beforeKeypress( data, key ) {
if ( !this._enabled ) {
return;
return false;
}
if ( !key || this._preview === '' ) {
return;
return false;
}
// Avoid clashing with existing TAB completion behavior...
if ( key.name === 'tab' ) {
return this.clear();
this.clear();
return false;
}
// Handle the case where the user is not at the end of the line...
if ( this._rli.cursor !== this._rli.line.length ) {
// If a user is in the middle of a line and presses ENTER, clear the preview string, as the preview was not accepted prior to executing the expression...
if ( key.name === 'return' || key.name === 'enter' ) {
debug( 'Received an ENTER keypress event while in the middle of the line.' );
return this.clear();
this.clear();
}
return;
return false;
}
// When the user is at the end of the line, auto-complete the line with the completion preview when a user presses RETURN or the RIGHT arrow key (note: pressing ENTER will result in both completion AND execution)...
if ( key.name === 'return' || key.name === 'enter' || key.name === 'right' ) {
debug( 'Completion preview accepted. Performing auto-completion...' );
this._rli.write( this._preview );
this._preview = '';
return true;
}
return false;
});


Expand Down
25 changes: 16 additions & 9 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ var commands = require( './commands.js' );
var displayPrompt = require( './display_prompt.js' );
var inputPrompt = require( './input_prompt.js' );
var OutputStream = require( './output_stream.js' );
var processLine = require( './process_line.js' );
var completerFactory = require( './completer.js' );
var MultilineHandler = require( './multiline_handler.js' );
var PreviewCompleter = require( './completer_preview.js' );
var AutoCloser = require( './auto_close_pairs.js' );
var SyntaxHighlighter = require( './syntax_highlighter.js' );
Expand Down Expand Up @@ -237,11 +237,6 @@ function REPL( options ) {
// Define the current workspace:
setNonEnumerable( this, '_currentWorkspace', 'base' );

// Initialize an internal status object for multi-line mode:
setNonEnumerable( this, '_multiline', {} );
setNonEnumerable( this._multiline, 'active', false );
setNonEnumerable( this._multiline, 'mode', 'incomplete_expression' );

// Initialize an internal flag indicating whether the REPL has been closed:
setNonEnumerable( this, '_closed', false );

Expand Down Expand Up @@ -273,6 +268,9 @@ function REPL( options ) {
'completer': this._completer
}));

// Initialize a multi-line handler:
setNonEnumerableReadOnly( this, '_multilineHandler', new MultilineHandler( this, this._rli._ttyWrite ) );

// Create a new auto-closer:
setNonEnumerableReadOnly( this, '_autoCloser', new AutoCloser( this._rli, this._settings.autoClosePairs, this._settings.autoDeletePairs ) );

Expand Down Expand Up @@ -337,12 +335,20 @@ function REPL( options ) {
* @param {(Object|void)} key - key object
*/
function beforeKeypress( data, key ) {
var completed;

if ( self._ostream.isPaging ) {
self._ostream.beforeKeypress( data, key );
return;
}
self._autoCloser.beforeKeypress( data, key );
self._previewCompleter.beforeKeypress( data, key );
completed = self._previewCompleter.beforeKeypress( data, key );

// If completion was auto-completed, don't trigger multi-line keybindings to avoid double operations...
if ( !completed ) {
self._multilineHandler.beforeKeypress( data, key );
return;
}
self._ttyWrite.call( self._rli, data, key );
}

Expand All @@ -366,6 +372,7 @@ function REPL( options ) {
if ( autoClosed ) {
self._previewCompleter.clear();
}
self._multilineHandler.onKeypress( data, key );
self._syntaxHighlighter.onKeypress();
self._previewCompleter.onKeypress( data, key );
}
Expand All @@ -379,7 +386,7 @@ function REPL( options ) {
function onLine( line ) {
self._SIGINT = false; // reset flag
if ( self._closed === false ) {
processLine( self, line );
self._multilineHandler.processLine( line );
}
}

Expand Down Expand Up @@ -1261,7 +1268,7 @@ setNonEnumerableReadOnly( REPL.prototype, 'clearCommand', function onClearComman
throw new Error( 'invalid operation. Cannot clear the command buffer of a REPL which has already closed.' );
}
// Clear any command which has been buffered but not yet executed:
this._cmd.length = 0;
this._multilineHandler.resetInput();

return this;
});
Expand Down
Loading

0 comments on commit 676acac

Please sign in to comment.