|
24 | 24 |
|
25 | 25 | var logger = require( 'debug' ); |
26 | 26 | var isString = require( '@stdlib/assert/is-string' ).isPrimitive; |
27 | | -var noop = require( '@stdlib/utils/noop' ); |
28 | | -var displayPrompt = require( './../display_prompt.js' ); |
29 | 27 |
|
30 | 28 |
|
31 | 29 | // VARIABLES // |
@@ -60,14 +58,38 @@ function command( repl ) { |
60 | 58 | repl._ostream.write( 'Error: '+err.message+'\n' ); |
61 | 59 | return; |
62 | 60 | } |
63 | | - // Reset the display prompt: |
64 | | - repl._rli.write( '\n' ); |
65 | | - displayPrompt( repl, false ); |
66 | | - |
67 | | - // FIXME: fix error handling here (e.g., file does not exist, etc) |
| 61 | + repl.once( 'drain', onDrain ); |
| 62 | + |
| 63 | + /** |
| 64 | + * Callback invoked upon a 'drain' event. |
| 65 | + * |
| 66 | + * @private |
| 67 | + */ |
| 68 | + function onDrain() { |
| 69 | + try { |
| 70 | + debug( 'Loading a file...' ); |
| 71 | + repl.load( fpath, clbk ); |
| 72 | + } catch ( error ) { |
| 73 | + debug( 'Error: %s', error.message ); |
| 74 | + |
| 75 | + // TODO: determine whether we need to perform ANSI escape magic here! (the error message gets printed on the wrong line!) |
| 76 | + repl._ostream.write( 'Error: '+error.message+'\n' ); |
| 77 | + } |
| 78 | + } |
68 | 79 |
|
69 | | - debug( 'Loading a file...' ); |
70 | | - repl.load( fpath, noop ); |
| 80 | + /** |
| 81 | + * Callback invoked upon loading a file. |
| 82 | + * |
| 83 | + * @private |
| 84 | + * @param {Error} [error] - error object |
| 85 | + */ |
| 86 | + function clbk( error ) { |
| 87 | + if ( error ) { |
| 88 | + debug( 'Error: %s', error.message ); |
| 89 | + return; |
| 90 | + } |
| 91 | + debug( 'Successfully loaded file.' ); |
| 92 | + } |
71 | 93 | } |
72 | 94 | } |
73 | 95 |
|
|
0 commit comments