Skip to content

Commit 7f31a89

Browse files
committed
docs: document added prototype methods and settings
Signed-off-by: Snehil Shah <[email protected]>
1 parent 570f24e commit 7f31a89

File tree

3 files changed

+156
-4
lines changed

3 files changed

+156
-4
lines changed

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

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ The function accepts the following `options`:
7171
- **outputPrompt**: output prompt. If the output prompt includes the character sequence `%d`, the output prompt includes line numbers. Default: `'Out[%d]: '`.
7272
- **welcome**: welcome message.
7373
- **padding**: number of empty lines between consecutive commands. Default: `1`.
74+
- **themes**: table mapping of color themes to load for syntax-highlighting
7475
- **load**: file path specifying a JavaScript file to load and evaluate line-by-line (e.g., a previous REPL history file).
7576
- **save**: file path specifying where to save REPL command history.
7677
- **log**: file path specifying where to save REPL commands and printed output.
@@ -83,6 +84,28 @@ The function supports specifying the following settings:
8384
- **autoDeletePairs**: boolean indicating whether to automatically delete adjacent matching brackets, parentheses, and quotes. Default: `true`.
8485
- **autoPage**: boolean indicating whether to automatically page return values having a display size exceeding the visible screen. When streams are TTY, the default is `true`; otherwise, the default is `false`.
8586
- **completionPreviews**: boolean indicating whether to display completion previews for auto-completion. When streams are TTY, the default is `true`; otherwise, the default is `false`.
87+
- **syntaxHighlighting**: boolean indicating whether to enable syntax highlighting of the input. When streams are TTY, the default is `true`; otherwise, the default is `false`.
88+
- **theme**: theme to set upon REPL startup. Default: `default`.
89+
- **defaultTheme**: default theme to set upon REPL startup. Default: `default`.
90+
91+
#### REPL.prototype.viewport()
92+
93+
Returns the REPL viewport.
94+
95+
```javascript
96+
var debug = require( '@stdlib/streams/node/debug-sink' );
97+
98+
// Create a new REPL:
99+
var repl = new REPL({
100+
'output': debug()
101+
});
102+
103+
// Query the REPL viewport:
104+
var v = repl.viewport();
105+
106+
// Close the REPL:
107+
repl.close();
108+
```
86109

87110
#### REPL.prototype.createContext()
88111

@@ -176,6 +199,126 @@ repl.clearUserDocs();
176199
repl.close();
177200
```
178201

202+
#### Repl.prototype.themes()
203+
204+
Returns all available themes in the syntax-highlighter.
205+
206+
```javascript
207+
var debug = require( '@stdlib/streams/node/debug-sink' );
208+
209+
// Create a new REPL:
210+
var repl = new REPL({
211+
'output': debug()
212+
});
213+
214+
// ...
215+
216+
// Fetch all available themes:
217+
repl.themes();
218+
219+
// ...
220+
221+
// Close the REPL:
222+
repl.close();
223+
```
224+
225+
#### Repl.prototype.getTheme()
226+
227+
Returns all available themes in the syntax-highlighter.
228+
229+
```javascript
230+
var debug = require( '@stdlib/streams/node/debug-sink' );
231+
232+
// Create a new REPL:
233+
var repl = new REPL({
234+
'output': debug()
235+
});
236+
237+
// ...
238+
239+
// Fetch all available themes:
240+
repl.themes();
241+
242+
// ...
243+
244+
// Close the REPL:
245+
repl.close();
246+
```
247+
248+
#### Repl.prototype.addTheme()
249+
250+
Adds a color theme to the syntax-highlighter.
251+
252+
```javascript
253+
var debug = require( '@stdlib/streams/node/debug-sink' );
254+
255+
// Create a new REPL:
256+
var repl = new REPL({
257+
'output': debug()
258+
});
259+
260+
// ...
261+
262+
// Add a user-defined theme:
263+
repl.addTheme( 'myTheme', {
264+
'keyword': 'red',
265+
'variable': 'green'
266+
267+
// ...
268+
});
269+
270+
// ...
271+
272+
// Close the REPL:
273+
repl.close();
274+
```
275+
276+
#### Repl.prototype.deleteTheme()
277+
278+
Deletes a specified theme from the syntax-highlighter.
279+
280+
```javascript
281+
var debug = require( '@stdlib/streams/node/debug-sink' );
282+
283+
// Create a new REPL:
284+
var repl = new REPL({
285+
'output': debug()
286+
});
287+
288+
// ...
289+
290+
// Delete an existing theme:
291+
repl.deleteTheme( 'myTheme' );
292+
293+
// ...
294+
295+
// Close the REPL:
296+
repl.close();
297+
```
298+
299+
#### Repl.prototype.renameTheme()
300+
301+
Renames a specified theme in the syntax-highlighter.
302+
303+
```javascript
304+
var debug = require( '@stdlib/streams/node/debug-sink' );
305+
306+
// Create a new REPL:
307+
var repl = new REPL({
308+
'output': debug()
309+
});
310+
311+
// ...
312+
313+
// Rename an existing theme:
314+
repl.renameTheme( 'myTheme', 'yourTheme' );
315+
316+
// ...
317+
318+
// Close the REPL:
319+
repl.close();
320+
```
321+
179322
#### REPL.prototype.load( fpath, clbk )
180323

181324
Loads and evaluates a JavaScript file line-by-line.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,16 @@ function defaults() {
9090
'autoPage': void 0,
9191

9292
// Flag indicating whether to enable the display of completion previews for auto-completion (note: default depends on whether TTY):
93-
'completionPreviews': void 0
93+
'completionPreviews': void 0,
94+
95+
// Flag indicating whether to enable syntax highlighting of the input (note: default depends on whether TTY):
96+
'syntaxHighlighting': void 0,
97+
98+
// Theme for syntax highlighting:
99+
'theme': 'default',
100+
101+
// Default theme for syntax highlighting:
102+
'defaultTheme': 'default'
94103
}
95104
};
96105
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ function REPL( options ) {
150150
opts.settings.autoPage = ( opts.settings.autoPage === void 0 ) ? opts.isTTY : opts.settings.autoPage; // eslint-disable-line max-len
151151
opts.settings.completionPreviews = ( opts.settings.completionPreviews === void 0 ) ? opts.isTTY : opts.settings.completionPreviews; // eslint-disable-line max-len
152152
opts.settings.syntaxHighlighting = ( opts.settings.syntaxHighlighting === void 0 ) ? opts.isTTY : opts.settings.syntaxHighlighting; // eslint-disable-line max-len
153-
opts.settings.theme = ( opts.settings.theme === void 0 ) ? 'default' : opts.settings.theme;
154-
opts.settings.defaultTheme = ( opts.settings.defaultTheme === void 0 ) ? 'default' : opts.settings.defaultTheme;
155153

156154
debug( 'Options: %s', JSON.stringify({
157155
'input': '<readable_stream>',
@@ -822,7 +820,7 @@ setNonEnumerableReadOnly( REPL.prototype, 'clearUserDocs', function clearUserDoc
822820
*
823821
* // ...
824822
*
825-
* // Fetch all themes:
823+
* // Fetch all available themes:
826824
* repl.themes();
827825
*
828826
* // ...
@@ -895,6 +893,8 @@ setNonEnumerableReadOnly( REPL.prototype, 'getTheme', function getTheme( theme )
895893
* repl.addTheme( 'myTheme', {
896894
* 'keyword': 'red',
897895
* 'variable': 'green'
896+
*
897+
* // ...
898898
* });
899899
*
900900
* // ...

0 commit comments

Comments
 (0)