Skip to content

Commit 0c27bb5

Browse files
committed
refactor: move _history and create accessor for count
Signed-off-by: Snehil Shah <[email protected]> --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- Signed-off-by: Snehil Shah <[email protected]>
1 parent abc23ee commit 0c27bb5

File tree

6 files changed

+115
-62
lines changed

6 files changed

+115
-62
lines changed

lib/node_modules/@stdlib/repl/base/ctor/README.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,36 @@ var ws = repl.currentWorkspace;
9292
repl.close();
9393
```
9494

95+
#### REPL.prototype.quiet
96+
97+
Boolean indicating whether log information, confirmation messages, and other possible REPL diagnostics should be silenced.
98+
99+
```javascript
100+
// Create a new REPL:
101+
var repl = new REPL();
102+
103+
// Check if the REPL is quiet:
104+
var out = repl.quiet;
105+
106+
// Close the REPL:
107+
repl.close();
108+
```
109+
110+
#### REPL.prototype.count
111+
112+
Command count.
113+
114+
```javascript
115+
// Create a new REPL:
116+
var repl = new REPL();
117+
118+
// Get command count:
119+
var cnt = repl.count;
120+
121+
// Close the REPL:
122+
repl.close();
123+
```
124+
95125
### Methods
96126

97127
#### REPL.prototype.isMultilineInput( input )
@@ -453,25 +483,6 @@ var d = repl.clearWorkspace( 'base' );
453483
repl.close();
454484
```
455485

456-
#### REPL.prototype.clearHistory()
457-
458-
Clears a REPL's history.
459-
460-
```javascript
461-
// Create a new REPL:
462-
var repl = new REPL();
463-
464-
// ...
465-
466-
// Clear the REPL history:
467-
repl.clearHistory();
468-
469-
// ...
470-
471-
// Close the REPL:
472-
repl.close();
473-
```
474-
475486
#### REPL.prototype.reset()
476487

477488
Resets a REPL.

lib/node_modules/@stdlib/repl/base/ctor/lib/main.js

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ function REPL( options ) {
155155
// Initialize an internal command queue:
156156
setNonEnumerableReadOnly( this, '_queue', fifo() );
157157

158-
// Initialize a strided internal buffer for storing the command history:
159-
setNonEnumerableReadOnly( this, '_history', [] );
160-
161158
// Initialize a executed command counter:
162159
setNonEnumerable( this, '_count', -1 );
163160

@@ -257,13 +254,10 @@ function REPL( options ) {
257254
* @param {*} res - result
258255
* @param {boolean} silent - boolean indicating whether the command output should be silenced
259256
*/
260-
function onCommand( cmd, success ) {
257+
function onCommand() {
261258
self._count += 1;
262259
debug( 'Command count: %d', self._count );
263260

264-
// Update the internal command history buffer: [..., <id>, <cmd>, <success>, ...]
265-
self._history.push( self._count, cmd, success );
266-
267261
// 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?)
268262

269263
// TODO: if necessary, (asynchronously?) write the command and result to a log file (JSON serialization?)
@@ -296,6 +290,48 @@ setReadOnlyAccessor( REPL.prototype, 'currentWorkspace', function get() {
296290
return this._currentWorkspace;
297291
});
298292

293+
/**
294+
* Boolean indicating whether log information, confirmation messages, and other possible REPL diagnostics should be silenced.
295+
*
296+
* @name quiet
297+
* @memberof REPL.prototype
298+
* @type {boolean}
299+
*
300+
* @example
301+
* // Create a new REPL:
302+
* var repl = new REPL();
303+
*
304+
* // Check if the REPL is quiet:
305+
* var out = repl.quiet;
306+
*
307+
* // Close the REPL:
308+
* repl.close();
309+
*/
310+
setReadOnlyAccessor( REPL.prototype, 'quiet', function get() {
311+
return this._quiet;
312+
});
313+
314+
/**
315+
* Command count.
316+
*
317+
* @name count
318+
* @memberof REPL.prototype
319+
* @type {number}
320+
*
321+
* @example
322+
* // Create a new REPL:
323+
* var repl = new REPL();
324+
*
325+
* // Get command count:
326+
* var cnt = repl.count;
327+
*
328+
* // Close the REPL:
329+
* repl.close();
330+
*/
331+
setReadOnlyAccessor( REPL.prototype, 'count', function get() {
332+
return this._count;
333+
});
334+
299335
/**
300336
* Checks if the given input is a possible multi-line command.
301337
*
@@ -1328,34 +1364,6 @@ setNonEnumerableReadOnly( REPL.prototype, 'clearWorkspace', function clearWorksp
13281364
return d;
13291365
});
13301366

1331-
/**
1332-
* Clears a REPL's history.
1333-
*
1334-
* @name clearHistory
1335-
* @memberof REPL.prototype
1336-
* @type {Function}
1337-
* @returns {REPL} REPL instance
1338-
*
1339-
* @example
1340-
* // Create a new REPL:
1341-
* var repl = new REPL();
1342-
*
1343-
* // ...
1344-
*
1345-
* // Clear the REPL history:
1346-
* repl.clearHistory();
1347-
*
1348-
* // ...
1349-
*
1350-
* // Close the REPL:
1351-
* repl.close();
1352-
*/
1353-
setNonEnumerableReadOnly( REPL.prototype, 'clearHistory', function clearHistory() {
1354-
debug( 'Resetting REPL history...' );
1355-
this._history.length = 0;
1356-
return this;
1357-
});
1358-
13591367
/**
13601368
* Resets a REPL.
13611369
*
@@ -1388,9 +1396,6 @@ setNonEnumerableReadOnly( REPL.prototype, 'reset', function onReset() {
13881396
// Reset the command queue:
13891397
this._queue.clear();
13901398

1391-
// Clear the command history:
1392-
this.clearHistory();
1393-
13941399
// Reset the execution context:
13951400
this.resetContext();
13961401

lib/node_modules/@stdlib/repl/lib/display_prompt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function displayPrompt( repl, preserveCursor ) {
4747
}
4848
len = repl._cmd.length;
4949
if ( len === 0 ) {
50-
if ( repl._padding && repl._count >= 0 ) {
50+
if ( repl._padding && repl.count >= 0 ) {
5151
repl._ostream.write( repeat( '\n', repl._padding ) );
5252
}
5353
repl._rli.setPrompt( repl._prompt() );

lib/node_modules/@stdlib/repl/lib/eager_evaluator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey
323323
res = res.slice( 0, index ) + '...';
324324
}
325325
cursorPosition = this._rli.cursor;
326-
pre = replace( this._repl._outputPrompt, '%d', ( this._repl._count+1 ).toString() );
326+
pre = replace( this._repl._outputPrompt, '%d', ( this._repl.count+1 ).toString() );
327327
this._repl._ostream.write( '\n' + ANSI_GRAY + pre + res + ANSI_RESET );
328328
readline.moveCursor( this._repl._ostream, 0, -1 );
329329
readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() );

lib/node_modules/@stdlib/repl/lib/log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @param {string} msg - message
3535
*/
3636
function log( repl, msg ) {
37-
if ( repl._quiet === false ) {
37+
if ( repl.quiet === false ) {
3838
repl._ostream.write( msg+'\n' );
3939
}
4040
}

lib/node_modules/@stdlib/repl/lib/main.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ function REPL( options ) {
209209
// Initialize an internal buffer for storing the current command:
210210
setNonEnumerableReadOnly( this, '_cmd', [] );
211211

212+
// Initialize a strided internal buffer for storing the command history:
213+
setNonEnumerableReadOnly( this, '_history', [] );
214+
212215
// Initialize a strided internal buffer for storing user-defined documentation:
213216
setNonEnumerableReadOnly( this, '_userdocs', [] );
214217

@@ -469,10 +472,13 @@ function REPL( options ) {
469472
var pre;
470473
var tmp;
471474

475+
// Update the internal command history buffer: [..., <id>, <cmd>, <success>, ...]
476+
self._history.push( self.count, cmd, success );
477+
472478
if ( success === false ) {
473479
self._ostream.write( 'Error: '+res.message+'\n' );
474480
} else if ( !silent && res !== void 0 ) {
475-
pre = replace( self._outputPrompt, '%d', self._count.toString() );
481+
pre = replace( self._outputPrompt, '%d', self.count.toString() );
476482

477483
if ( isndarrayLike( res ) ) {
478484
tmp = res.toString(); // FIXME: this is a hack in order to avoid printing private ndarray properties in the REPL, as done by the built-in `util.inspect`. Ideally, we'd roll our own inspector which specifically accommodates stdlib's ndarray and other specialized classes.
@@ -521,7 +527,7 @@ setNonEnumerableReadOnly( REPL.prototype, '_displayPrompt', function showPrompt(
521527
* @returns {string} command prompt
522528
*/
523529
setNonEnumerableReadOnly( REPL.prototype, '_prompt', function prompt() {
524-
return inputPrompt( this._inputPrompt, this._count );
530+
return inputPrompt( this._inputPrompt, this.count );
525531
});
526532

527533
/**
@@ -1094,6 +1100,9 @@ setNonEnumerableReadOnly( REPL.prototype, 'reset', function onReset() {
10941100
// Call the parent method:
10951101
BaseREPL.prototype.reset.call( this );
10961102

1103+
// Clear the command history:
1104+
this.clearHistory();
1105+
10971106
// Clear any command which has been buffered but not yet executed:
10981107
this.clearCommand();
10991108

@@ -1134,6 +1143,34 @@ setNonEnumerableReadOnly( REPL.prototype, 'clearUserDocs', function clearUserDoc
11341143
return this;
11351144
});
11361145

1146+
/**
1147+
* Clears a REPL's history.
1148+
*
1149+
* @name clearHistory
1150+
* @memberof REPL.prototype
1151+
* @type {Function}
1152+
* @returns {REPL} REPL instance
1153+
*
1154+
* @example
1155+
* // Create a new REPL:
1156+
* var repl = new REPL();
1157+
*
1158+
* // ...
1159+
*
1160+
* // Clear the REPL history:
1161+
* repl.clearHistory();
1162+
*
1163+
* // ...
1164+
*
1165+
* // Close the REPL:
1166+
* repl.close();
1167+
*/
1168+
setNonEnumerableReadOnly( REPL.prototype, 'clearHistory', function clearHistory() {
1169+
debug( 'Resetting REPL history...' );
1170+
this._history.length = 0;
1171+
return this;
1172+
});
1173+
11371174
/**
11381175
* Clears the entire REPL screen and scrollback history.
11391176
*

0 commit comments

Comments
 (0)