Skip to content

Commit 0d697f3

Browse files
committed
Add support for receiving a presentation over stdin
1 parent 41f2b29 commit 0d697f3

File tree

1 file changed

+35
-3
lines changed
  • lib/node_modules/@stdlib/repl/presentation/bin

1 file changed

+35
-3
lines changed

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

+35-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
var resolve = require( 'path' ).resolve;
2626
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
2727
var CLI = require( '@stdlib/tools/cli' );
28+
var stdin = require( '@stdlib/process/read-stdin' );
2829
var REPL = require( '@stdlib/repl' );
2930
var lowercase = require( '@stdlib/string/lowercase' );
3031
var Presentation = require( './../lib' ); // eslint-disable-line stdlib/no-redeclare
@@ -36,6 +37,7 @@ var Presentation = require( './../lib' ); // eslint-disable-line stdlib/no-redec
3637
* Main execution sequence.
3738
*
3839
* @private
40+
* @returns {void}
3941
*/
4042
function main() {
4143
var flags;
@@ -84,6 +86,8 @@ function main() {
8486
if ( flags.timeout ) {
8587
opts1.timeout = parseInt( flags.timeout, 10 );
8688
}
89+
// Create a new REPL instance:
90+
repl = new REPL( opts1 );
8791

8892
// Handle presentation options...
8993
opts2 = {};
@@ -121,11 +125,12 @@ function main() {
121125
if ( flags.autoclear === false ) {
122126
opts2.autoClear = flags.autoclear;
123127
}
128+
// Check if we are receiving data from `stdin`...
129+
if ( !process.stdin.isTTY ) {
130+
return stdin( onRead );
131+
}
124132
opts2.load = args[ 0 ];
125133

126-
// Create a new REPL instance:
127-
repl = new REPL( opts1 );
128-
129134
// Create a new REPL presentation:
130135
pres = new Presentation( repl, opts2 );
131136

@@ -146,6 +151,33 @@ function main() {
146151
function onChange() {
147152
pres.show();
148153
}
154+
155+
/**
156+
* Callback invoked upon reading from `stdin`.
157+
*
158+
* @private
159+
* @param {(Error|null)} error - error object
160+
* @param {Buffer} text - text
161+
* @returns {void}
162+
*/
163+
function onRead( error, text ) {
164+
var pres;
165+
if ( error ) {
166+
process.exitCode = 1;
167+
return console.error( 'Error: %s', error.message ); // eslint-disable-line no-console
168+
}
169+
// Create a new REPL presentation:
170+
pres = new Presentation( text.toString(), repl, opts2 );
171+
172+
// Render the first slide:
173+
pres.show();
174+
175+
// Check whether to begin watching the source presentation file...
176+
if ( flags.watch ) {
177+
pres.on( 'change', onChange );
178+
pres.watch();
179+
}
180+
}
149181
}
150182

151183
main();

0 commit comments

Comments
 (0)