Skip to content

refactor!: abstract part of REPL into a base implementation #5115

New issue

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

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

Already on GitHub? Sign in to your account

Draft
wants to merge 26 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
489a912
refactor!: move presentation into the `cli` namespace
Snehil-Shah Feb 8, 2025
e4e0c68
refactor!: abstract part of REPL into a base implementation
Snehil-Shah Feb 8, 2025
9367245
refactor: move example
Snehil-Shah Feb 8, 2025
1808c07
refactor: move commands to client implementation
Snehil-Shah Mar 6, 2025
fdbd335
fix: remove `command` token from themes
Snehil-Shah Mar 6, 2025
b7b5082
refactor: move base implementation to `ctor` package
Snehil-Shah Mar 8, 2025
d48530c
fix: update redundant paths for make and cli
Snehil-Shah Mar 8, 2025
87377b3
fix: update import paths
Snehil-Shah Mar 8, 2025
cdf34d2
build: update workflow paths
Snehil-Shah Mar 8, 2025
00846de
chore: update copyright years
stdlib-bot Mar 8, 2025
f865e10
style: convert indents to 2 spaces
Snehil-Shah Mar 8, 2025
fd1951a
fix: revert redundant changes
Snehil-Shah Mar 8, 2025
cce54d7
docs: update package paths
Snehil-Shah Mar 8, 2025
2ec1573
fix: apply review comments
Snehil-Shah Mar 10, 2025
d4fa088
docs: update package keywords
Snehil-Shah Mar 10, 2025
1ad2eea
refactor!: move `repl/cli` to `repl`
Snehil-Shah Mar 12, 2025
85223c0
refactor!: workspaces
Snehil-Shah Mar 15, 2025
d208192
docs: fix examples
Snehil-Shah Mar 15, 2025
9c83422
refactor: separate concern of streams
Snehil-Shah Mar 15, 2025
ccdfd71
refactor: clean up context creation
Snehil-Shah Mar 17, 2025
99a38e7
fix: heal examples
Snehil-Shah Mar 17, 2025
3410341
docs: document `setCommands`
Snehil-Shah Mar 21, 2025
9cefae1
refactor: evalin command
Snehil-Shah Mar 21, 2025
abc23ee
refactor: move `_cmd` and run logic
Snehil-Shah Mar 21, 2025
0c27bb5
refactor: move `_history` and create accessor for count
Snehil-Shah Mar 21, 2025
d02e494
refactor: abstract alias resolution
Snehil-Shah Mar 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1,908 changes: 954 additions & 954 deletions bin/cli_commands.json

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions lib/node_modules/@stdlib/repl/base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!--

@license Apache-2.0

Copyright (c) 2025 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.

-->

# Base

> Base REPL functionality.

<section class="usage">

## Usage

```javascript
var ns = require( '@stdlib/repl/base' );
```

#### ns

Namespace containing "base" (i.e., lower-level) REPL functionality.

```javascript
var o = ns;
// returns {...}
```

<!-- <toc pattern="*"> -->

<div class="namespace-toc">

</div>

<!-- </toc> -->

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var objectKeys = require( '@stdlib/utils/keys' );
var ns = require( '@stdlib/repl/base' );

console.log( objectKeys( ns ) );
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

<!-- <toc-links> -->

<!-- </toc-links> -->

</section>

<!-- /.links -->
271 changes: 271 additions & 0 deletions lib/node_modules/@stdlib/repl/base/ctor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
<!--

@license Apache-2.0

Copyright (c) 2025 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.

-->

# REPL

> Base class for Read-Eval-Print Loop (REPL) environment.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

A Read-Eval-Print Loop (REPL) environment is an interactive programming environment which takes individual user inputs (e.g., single expressions), evaluates those inputs, and returns the result. Accordingly, a program written in a REPL environment is executed piecewise and sequentially.

REPL environments find common use in exploratory programming, prototyping, and debugging.

The REPL environment exposed here is available both as a standalone application and as a library which is embeddable in other libraries and applications.

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var REPL = require( '@stdlib/repl/base/ctor' );
```

#### REPL( \[options] )

Returns a `REPL` instance.

```javascript
// Create a new REPL:
var repl = new REPL();

// ...

// Execute a command:
repl.emit( 'input', '2 + 3' );

// ...

// Close the REPL:
repl.close();
```

The function accepts the following `options`:

- **input**: input (readable) stream. Default: [`stdin`][@stdlib/streams/node/stdin].
- **output**: output (writable) stream. Default: [`stdout`][@stdlib/streams/node/stdout].
- **error**: error (writable) stream. Default: [`stderr`][@stdlib/streams/node/stderr].
- **sandbox**: boolean indicating whether to run a REPL in a sandboxed context. Default: `false`.
- **timeout**: number of milliseconds to execute a command before terminating execution. Default: `4294967295`.
- **save**: file path specifying where to save REPL command history.
- **log**: file path specifying where to save REPL commands and printed output.
- **quiet**: boolean indicating whether log information, confirmation messages, and other possible REPL diagnostics should be silenced. Default: `false`.

#### REPL.prototype.createContext()

Returns a REPL context.

```javascript
// Create a new REPL:
var repl = new REPL();

// ...

// Return a new REPL context:
var ctx = repl.createContext();

// ...

// Close the REPL:
repl.close();
```

#### REPL.prototype.resetContext()

Resets a REPL's execution context.

```javascript
// Create a new REPL:
var repl = new REPL();

// ...

// Reset the REPL context:
repl.resetContext();

// ...

// Close the REPL:
repl.close();
```

#### REPL.prototype.clearHistory()

Clears a REPL's history.

```javascript
// Create a new REPL:
var repl = new REPL();

// ...

// Clear the REPL history:
repl.clearHistory();

// ...

// Close the REPL:
repl.close();
```

#### REPL.prototype.clearUserDocs()

Clears user-defined documentation.

```javascript
// Create a new REPL:
var repl = new REPL();

// ...

// Clear user-defined documentation:
repl.clearUserDocs();

// ...

// Close the REPL:
repl.close();
```

#### REPL.prototype.reset()

Resets a REPL.

```javascript
// Create a new REPL:
var repl = new REPL();

// ...

// Reset the REPL:
repl.reset();

// ...

// Close the REPL:
repl.close();
```

#### REPL.prototype.close()

Closes a REPL.

```javascript
// Create a new REPL:
var repl = new REPL();

// ...

// Close the REPL:
repl.close();
```

* * *

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

* * *

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var REPL = require( '@stdlib/repl/base/ctor' );

function onCommand( cmd, success, res ) {
console.log( cmd + ' = ' + res.toString() );
}

// Create a new REPL:
var repl = new REPL();
repl.on( 'command', onCommand );

// Execute a command:
repl.emit( 'input', '3 + 2' );

// Close the REPL:
repl.close();
console.log( 'REPL closed.' );
```

</section>

<!-- /.examples -->

* * *

<section class="notes">

</section>

<!-- /.notes -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/streams/node/stdin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/streams/node/stdin

[@stdlib/streams/node/stdout]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/streams/node/stdout

[@stdlib/streams/node/stderr]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/streams/node/stderr

</section>

<!-- /.links -->
Loading