@@ -28,23 +28,33 @@ var repeat = require( '@stdlib/string/repeat' );
2828// FUNCTIONS //
2929
3030/**
31- * Callback invoked upon a `drain` event.
31+ * Returns a callback to be invoked upon a `drain` event.
3232*
3333* @private
3434* @param {Presentation } pres - presentation instance
35+ * @returns {Function } callback
3536*/
36- function onDrain ( pres ) {
37- /*
38- * [ANSI escape sequences][1]:
39- *
40- * - `\u001b`: ESC, the escape character
41- * - `[1T`: scroll down one line
42- * - `[1G`: move the cursor to the beginning of the line
37+ function createDrainHandler ( pres ) {
38+ return onDrain ;
39+
40+ /**
41+ * Callback invoked upon a `drain` event.
4342 *
44- * [1]: https://en.wikipedia.org/wiki/ANSI_escape_code
43+ * @private
4544 */
46- var str = '\u001b[1T\u001b[1G' ;
47- pres . _repl . _ostream . write ( str ) ;
45+ function onDrain ( ) {
46+ /*
47+ * [ANSI escape sequences][1]:
48+ *
49+ * - `\u001b`: ESC, the escape character
50+ * - `[1T`: scroll down one line
51+ * - `[1G`: move the cursor to the beginning of the line
52+ *
53+ * [1]: https://en.wikipedia.org/wiki/ANSI_escape_code
54+ */
55+ var str = '\u001b[1T\u001b[1G' ;
56+ pres . _repl . _ostream . write ( str ) ;
57+ }
4858}
4959
5060
@@ -69,16 +79,7 @@ function command( pres ) {
6979 var str = repeat ( pres . _opts . newline , pres . height + 1 ) ;
7080 pres . _repl . _ostream . write ( str ) ;
7181
72- pres . _repl . once ( 'drain' , drain ) ;
73-
74- /**
75- * Callback invoked upon a `drain` event.
76- *
77- * @private
78- */
79- function drain ( ) {
80- onDrain ( pres ) ;
81- }
82+ pres . _repl . once ( 'drain' , createDrainHandler ( pres ) ) ;
8283 }
8384}
8485
0 commit comments