Skip to content

Commit fb87002

Browse files
committed
Add support for "looping" a presentation
1 parent d4b93ba commit fb87002

File tree

10 files changed

+29
-5
lines changed

10 files changed

+29
-5
lines changed

lib/node_modules/@stdlib/repl/data/help.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ load,"\nload( fpath )\n Loads and evaluates a JavaScript file, such as a REPL
2424
loadWorkspace,"\nloadWorkspace( name[, options] )\n Loads variables from a specified workspace into the current workspace.\n\n Parameters\n ----------\n name: string\n Workspace name.\n\n options: Object (optional)\n Options.\n\n options.include: RegExp|ArrayLikeObject (optional)\n Variable name inclusion filter.\n\n options.exclude: RegExp|ArrayLikeObject (optional)\n Variable name exclusion filter.\n\n options.override: boolean (optional)\n Boolean indicating whether to override existing workspace variables.\n Default: true.\n\n Examples\n --------\n > workspace( 'foobar' );\n > var x = 3.14;\n > workspace( 'barfoo' );\n > typeof x\n > loadWorkspace( 'foobar' );\n > x\n\n See Also\n --------\n vars, varsWorkspace, workspace, workspaces\n\n"
2525
logStart,"\nlogStart( fpath )\n Starts logging commands and printed output to a specified file path.\n\n Parameters\n ----------\n fpath: string\n File path.\n\n Returns\n -------\n id: number\n Record identifier.\n\n Examples\n --------\n > var id = logStart( './path/to/file.txt' );\n > 1 + 1\n 2\n > 'foo'\n 'foo'\n > logStop( id );\n\n See Also\n --------\n logStop\n\n"
2626
logStop,"\nlogStop( id )\n Stops logging commands and printed output to a file path associated with a\n specified record identifier.\n\n Parameters\n ----------\n id: number\n Record identifier.\n\n Returns\n -------\n bool: boolean\n Boolean indicating whether the REPL successfully stopped logging\n evaluated commands.\n\n Examples\n --------\n > var id = logStart( './path/to/file.txt' );\n > 1 + 1\n 2\n > 'foo'\n 'foo'\n > logStop( id );\n\n See Also\n --------\n logfileStart\n\n"
27-
presentationStart,"\npresentationStart( [text, ][options] )\n Starts a REPL presentation.\n\n When not provided presentation text, an options argument must specify a\n presentation file to load.\n\n If a specified workspace already exists, the workspace is silently cleared\n and a new presentation bound. In order to preserve an existing workspace,\n specify an alternative presentation workspace name.\n\n Parameters\n ----------\n text: string (optional)\n Presentation text.\n\n options: Object (optional)\n Presentation options.\n\n options.borderTop: string (optional)\n Top border character sequence. Default: '*'.\n\n options.borderBottom: string (optional)\n Bottom border character sequence. Default: '*'.\n\n options.borderLeft: string (optional)\n Left border character sequence. Default: '* '.\n\n options.borderRight: string (optional)\n Right border character sequence. Default: ' *'.\n\n options.counter: string|boolean (optional)\n Slide counter. If `true`, each slide displays a slide counter. If set to\n 'progress', each slide displays a progress counter. If `false`, no\n counter is displayed. Default: false.\n\n options.width: integer|null (optional)\n Presentation width. If `null`, the presentation width is either computed\n based on the screen size (if a REPL output stream is TTY) or set to `80`\n characters. Default: null.\n\n options.height: integer|null (optional)\n Presentation height. If `null`, the presentation height is either\n computed based on the screen size (if a REPL output stream is TTY) or\n set to `25` rows. Default: null.\n\n options.workspace: string (optional)\n REPL workspace name. A presentation adds commands to the specified\n workspace, thus allowing presentation navigation and interaction.\n Default: `'presentation-<n>'`, where `n` is an assigned presentation\n identifier.\n\n options.load: string (optional)\n File path specifying a presentation file to load. If presentation text\n is provided, this option is ignored. Otherwise, this option is required.\n\n options.watch: boolean (optional)\n Boolean indicating whether to watch a presentation source file for\n changes. This option is only applicable if not provided presentation\n text and the options object specifies a presentation file to load.\n Default: false.\n\n options.autoClear: boolean (optional)\n Boolean indicating whether to automatically clear the screen before\n writing a rendered slide to the REPL. Default: true.\n\n Returns\n -------\n id: integer\n Presentation identifier.\n\n Examples\n --------\n > var id = presentationStart( 'beep\n---boop\n' );\n\n See Also\n --------\n presentationStop, workspace, workspaces\n\n"
27+
presentationStart,"\npresentationStart( [text, ][options] )\n Starts a REPL presentation.\n\n When not provided presentation text, an options argument must specify a\n presentation file to load.\n\n If a specified workspace already exists, the workspace is silently cleared\n and a new presentation bound. In order to preserve an existing workspace,\n specify an alternative presentation workspace name.\n\n Parameters\n ----------\n text: string (optional)\n Presentation text.\n\n options: Object (optional)\n Presentation options.\n\n options.borderTop: string (optional)\n Top border character sequence. Default: '*'.\n\n options.borderBottom: string (optional)\n Bottom border character sequence. Default: '*'.\n\n options.borderLeft: string (optional)\n Left border character sequence. Default: '* '.\n\n options.borderRight: string (optional)\n Right border character sequence. Default: ' *'.\n\n options.counter: string|boolean (optional)\n Slide counter. If `true`, each slide displays a slide counter. If set to\n 'progress', each slide displays a progress counter. If `false`, no\n counter is displayed. Default: false.\n\n options.width: integer|null (optional)\n Presentation width. If `null`, the presentation width is either computed\n based on the screen size (if a REPL output stream is TTY) or set to `80`\n characters. Default: null.\n\n options.height: integer|null (optional)\n Presentation height. If `null`, the presentation height is either\n computed based on the screen size (if a REPL output stream is TTY) or\n set to `25` rows. Default: null.\n\n options.workspace: string (optional)\n REPL workspace name. A presentation adds commands to the specified\n workspace, thus allowing presentation navigation and interaction.\n Default: `'presentation-<n>'`, where `n` is an assigned presentation\n identifier.\n\n options.load: string (optional)\n File path specifying a presentation file to load. If presentation text\n is provided, this option is ignored. Otherwise, this option is required.\n\n options.watch: boolean (optional)\n Boolean indicating whether to watch a presentation source file for\n changes. This option is only applicable if not provided presentation\n text and the options object specifies a presentation file to load.\n Default: false.\n\n options.autoClear: boolean (optional)\n Boolean indicating whether to automatically clear the screen before\n writing a rendered slide to the REPL. Default: true.\n\n options.loop: boolean (optional)\n Boolean indicating whether to \"loop\" a presentation. Default: false.\n\n Returns\n -------\n id: integer\n Presentation identifier.\n\n Examples\n --------\n > var id = presentationStart( 'beep\n---boop\n' );\n\n See Also\n --------\n presentationStop, workspace, workspaces\n\n"
2828
presentationStop,"\npresentationStop( [id] )\n Stops a REPL presentation.\n\n If provided a presentation identifier, the corresponding presentation is\n stopped. Otherwise, assuming the command is invoked in a presentation\n workspace, the current presentation is stopped.\n\n When stopping a REPL presentation, the presentation's REPL workspace is\n both cleared and deleted.\n\n Parameters\n ----------\n id: number|string (optional)\n Presentation identifier. Must be provided if not currently in a\n presentation workspace.\n\n Returns\n -------\n bool: boolean\n Boolean indicating whether the REPL successfully stopped a REPL\n presentation.\n\n Examples\n --------\n > var id = presentationStart( 'beep\n---\nboop\n' );\n > presentationStop();\n\n See Also\n --------\n presentationStart, workspace, workspaces\n\n"
2929
quit,"\nquit()\n Exits the REPL.\n\n Examples\n --------\n > quit()\n\n See Also\n --------\n clear, save\n\n"
3030
renameWorkspace,"\nrenameWorkspace( oldName, newName )\n Renames a workspace.\n\n The new workspace name must not already exist. The only exception is when\n the old name and the new name are the same; in which case, invoking this\n function is a non-operation.\n\n As a 'base' workspace must always exist, when renaming the 'base' workspace,\n variables from the 'base' workspace are simply copied to a new workspace and\n the 'base' workspace cleared of user-defined variables.\n\n Parameters\n ----------\n oldName: string\n Name of workspace to rename.\n\n newName: string\n New workspace name.\n\n Examples\n --------\n // Create a new workspace:\n > workspace( 'foobar' );\n > var x = 3.14;\n\n // List current workspaces:\n > workspaces()\n\n // Switch to another workspace:\n > workspace( 'barfoo' );\n\n // List current workspaces:\n > workspaces()\n\n // Rename the first workspace:\n > renameWorkspace( 'foobar', 'beepboop' );\n\n // Check the updated list of workspaces:\n > workspaces()\n\n // Switch to the renamed workspace:\n > workspace( 'beepboop' );\n\n // Confirm that workspace contains previously defined variables:\n > x\n\n\n See Also\n --------\n currentWorkspace, deleteWorkspace, loadWorkspace, workspace, workspaces\n\n"

lib/node_modules/@stdlib/repl/data/help.json

+1-1
Large diffs are not rendered by default.

lib/node_modules/@stdlib/repl/docs/commands/presentation_start.txt

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ presentationStart( [text, ][options] )
6464
Boolean indicating whether to automatically clear the screen before
6565
writing a rendered slide to the REPL. Default: true.
6666

67+
options.loop: boolean (optional)
68+
Boolean indicating whether to "loop" a presentation. Default: false.
69+
6770
Returns
6871
-------
6972
id: integer

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

+2
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ The function accepts the following `options`:
305305
- **workspace**: [REPL][@stdlib/repl] workspace name. A presentation instance adds presentation commands to the specified workspace, thus allowing presentation navigation and interaction. Default: `'presentation'`.
306306
- **load**: file path specifying a presentation file to load. If a presentation `text` is provided, this option is **ignored**.
307307
- **autoClear**: `boolean` indicating whether to automatically clear the screen before writing a rendered slide to the [REPL][@stdlib/repl]. Default: `true`.
308+
- **loop**: `boolean` indicating whether to "loop" a presentation (i.e., proceed to the first slide after the last slide and have the last slide precede the first slide). Default: `false`.
308309

309310
To initialize a presentation upon instantiating a `Presentation` instance, **either** provide a `string` as the first argument containing the presentation text to render **or** set the `load` option to specify a presentation file to load.
310311

@@ -1449,6 +1450,7 @@ Options:
14491450
--timeout <timeout> Milliseconds before terminating a command.
14501451
--quiet Disable printing of REPL logs and diagnostics.
14511452
--no-autoclear Disable automatic clearing when rendering.
1453+
--loop Loop a presentation.
14521454
--watch Watch the source presentation file for changes.
14531455
```
14541456

lib/node_modules/@stdlib/repl/presentation/bin/cli

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ function main() {
130130
if ( flags.autoclear === false ) {
131131
opts2.autoClear = flags.autoclear;
132132
}
133+
if ( flags.loop ) {
134+
opts2.loop = flags.loop;
135+
}
133136
// Check if we are receiving data from `stdin`...
134137
if ( !process.stdin.isTTY ) {
135138
if ( IS_WINDOWS ) {

lib/node_modules/@stdlib/repl/presentation/docs/usage.txt

+1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ Options:
2121
--timeout <timeout> Milliseconds before terminating a command.
2222
--quiet Disable printing of REPL logs and diagnostics.
2323
--no-autoclear Disable automatic clearing when rendering.
24+
--loop Loop a presentation.
2425
--watch Watch the source presentation file for changes.
2526

lib/node_modules/@stdlib/repl/presentation/etc/cli_opts.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"version",
2121
"quiet",
2222
"no-autoclear",
23+
"loop",
2324
"watch"
2425
],
2526
"alias": {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ function defaults() {
3838
'height': null,
3939
'counter': false,
4040
'workspace': 'presentation',
41-
'autoClear': true
41+
'autoClear': true,
42+
'loop': false
4243
};
4344
return options;
4445
}

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read
3333
var setNonEnumerableReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); // eslint-disable-line id-length
3434
var setNonEnumerable = require( '@stdlib/utils/define-nonenumerable-property' );
3535
var clamp = require( '@stdlib/math/base/special/clamp' );
36+
var wrap = require( '@stdlib/math/base/special/wrap' );
3637
var readFile = require( '@stdlib/fs/read-file' ).sync;
3738
var repeat = require( '@stdlib/string/repeat' );
3839
var constructorName = require( '@stdlib/utils/constructor-name' );
@@ -76,6 +77,7 @@ var DEFAULT_HEIGHT = 25;
7677
* @param {string} [options.workspace="presentation"] - REPL workspace name
7778
* @param {string} [options.load] - file path specifying a presentation file to load
7879
* @param {boolean} [options.autoClear=true] - boolean indicating whether to automatically clear the screen before writing a rendered slide to the REPL
80+
* @param {boolean} [options.loop=false] - boolean indicating whether to "loop" a presentation
7981
* @throws {Error} must provide a REPL instance
8082
* @throws {TypeError} presentation text argument must be a string
8183
* @throws {TypeError} REPL argument must be a REPL instance
@@ -243,9 +245,13 @@ setNonEnumerableReadOnly( Presentation.prototype, '_select', function select( n,
243245
var fc;
244246
var N;
245247

246-
// Limit the slide cursor range to one position before/after the first/last slide in order to avoid multiple previous/next calls moving the cursors indefinitely away from the slide deck...
248+
// Limit the slide cursor range in order to avoid multiple previous/next calls moving the cursors indefinitely away from the slide deck...
247249
N = this.length;
248-
sc = clamp( n, -1, N );
250+
if ( this._opts.loop ) {
251+
sc = wrap( n, 0, N );
252+
} else {
253+
sc = clamp( n, -1, N );
254+
}
249255
if ( sc === -1 || sc === N ) {
250256
debug( 'Unable to select slide. Slide cursor out-of-range.' );
251257
this._slide = null;

lib/node_modules/@stdlib/repl/presentation/lib/validate.js

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimit
4545
* @param {string} [options.workspace] - REPL workspace name
4646
* @param {string} [options.load] - file path specifying a presentation file to load
4747
* @param {boolean} [options.autoClear] - boolean indicating whether to automatically clear the screen before writing a rendered slide to the REPL
48+
* @param {boolean} [options.loop] - boolean indicating whether to "loop" a presentation
4849
* @throws {Error} must provide valid options
4950
* @returns {(Error|null)} error or null
5051
*
@@ -122,6 +123,12 @@ function validate( opts, options ) {
122123
return new TypeError( 'invalid option. `autoClear` option must be a boolean. Option: `' + options.autoClear + '`.' );
123124
}
124125
}
126+
if ( hasOwnProp( options, 'loop' ) ) {
127+
opts.loop = options.loop;
128+
if ( !isBoolean( options.loop ) ) {
129+
return new TypeError( 'invalid option. `loop` option must be a boolean. Option: `' + options.loop + '`.' );
130+
}
131+
}
125132
return null;
126133
}
127134

0 commit comments

Comments
 (0)