Skip to content

Commit

Permalink
feat: add support for auto-closing brackets/quotations in the REPL
Browse files Browse the repository at this point in the history
PR-URL: 	stdlib-js#1680
Closes: stdlib-js#1672
Co-authored-by: Athan Reines <[email protected]>
Reviewed-by: Athan Reines <[email protected]> 
Signed-off-by: Snehil Shah <[email protected]>
Signed-off-by: Snehil Shah <[email protected]>
  • Loading branch information
Snehil-Shah and kgryte committed Apr 1, 2024
1 parent 396a40e commit 8314237
Show file tree
Hide file tree
Showing 95 changed files with 5,625 additions and 198 deletions.
98 changes: 95 additions & 3 deletions lib/node_modules/@stdlib/repl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,24 @@ 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].
- **sandbox**: `boolean` indicating whether to run a REPL in a sandboxed context. Default: `false`.
- **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`.
- **isTTY**: `boolean` indicating whether the input and output streams should be treated like a TTY (terminal) and whether the REPL should use ANSI/VT100 escape codes when writing to the output stream.
- **isTTY**: boolean indicating whether the input and output streams should be treated like a TTY (terminal) and whether the REPL should use ANSI/VT100 escape codes when writing to the output stream.
- **inputPrompt**: input prompt. If the input prompt includes the character sequence `%d`, the input prompt includes line numbers. Default: `'In [%d]: '`.
- **outputPrompt**: output prompt. If the output prompt includes the character sequence `%d`, the output prompt includes line numbers. Default: `'Out[%d]: '`.
- **welcome**: welcome message.
- **padding**: number of empty lines between consecutive commands. Default: `1`.
- **load**: file path specifying a JavaScript file to load and evaluate line-by-line (e.g., a previous REPL history file).
- **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`.
- **quiet**: boolean indicating whether log information, confirmation messages, and other possible REPL diagnostics should be silenced. Default: `false`.
- **settings**: object specifying REPL settings.

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`.
- **completionPreviews**: boolean indicating whether to display completion previews for auto-completion. When streams are TTY, the default is `true`; otherwise, the default is `false`.

#### REPL.prototype.createContext()

Expand Down Expand Up @@ -289,6 +296,71 @@ repl.clearCommand();
repl.close();
```

#### REPL.prototype.settings( \[name\[, value]] )

Returns REPL settings.

```javascript
var debug = require( '@stdlib/streams/node/debug-sink' );

// Create a new REPL:
var repl = new REPL({
'output': debug()
});

// ...

// Retrieve REPL settings:
var o = repl.settings();

// ...

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

To retrieve the current value for a specific setting, provide a `name` argument.

```javascript
var debug = require( '@stdlib/streams/node/debug-sink' );

// Create a new REPL:
var repl = new REPL({
'output': debug()
});

// ...

// Retrieve current setting value:
var v = repl.settings( 'autoClosePairs' );

// ...

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

To update a specific setting, provide a `value` argument.

```javascript
var debug = require( '@stdlib/streams/node/debug-sink' );

// Create a new REPL:
var repl = new REPL({
'output': debug()
});

// ...

// Update setting value:
repl.settings( 'autoClosePairs', false );

// ...

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

#### REPL.prototype.close()

Closes a REPL.
Expand Down Expand Up @@ -966,6 +1038,26 @@ Stops saving commands to a file path associated with a specified record identifi
// TODO
```

#### settings( \[name\[, value]] )

Displays REPL settings.

```text
In [1]: settings()
```

To retrieve the current value for a specific setting, provide a `name` argument.

```text
In [1]: settings( 'autoClosePairs' )
```

To update a specific setting, provide a `value` argument.

```text
In [1]: settings( 'autoClosePairs', false )
```

#### tutorial( \[name, \[options]] )

Starts a tutorial.
Expand Down
Loading

0 comments on commit 8314237

Please sign in to comment.