1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | "use strict" ;
|
28 |
|
29 |
|
30 |
|
31 | const termkit = require( './termkit' ) ;
|
32 | const stringWidth = termkit.stringWidth ;
|
33 | const string = require( 'string-kit' ) ;
|
34 | const NextGenEvents = require( 'nextgen-events' ) ;
|
35 | const Promise = require( 'seventh' ) ;
|
36 |
|
37 |
|
38 |
|
39 | const defaultKeyBindings = {
|
40 | ENTER: 'submit' ,
|
41 | KP_ENTER: 'submit' ,
|
42 | UP: 'previous' ,
|
43 | DOWN: 'next' ,
|
44 | TAB: 'cycleNext' ,
|
45 | SHIFT_TAB: 'cyclePrevious' ,
|
46 | HOME: 'first' ,
|
47 | END: 'last' ,
|
48 | BACKSPACE: 'cancel' ,
|
49 | DELETE: 'cancel' ,
|
50 | ESCAPE: 'escape'
|
51 | } ;
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | module.exports = function singleColumnMenu( menuItemsArg , options , callback ) {
|
97 | if ( arguments.length < 1 ) { throw new Error( '[terminal] singleColumnMenu() needs at least an array of menuItems' ) ; }
|
98 | if ( ! Array.isArray( menuItemsArg ) || ! menuItemsArg.length ) { throw new TypeError( '[terminal] singleColumnMenu(): argument #0 should be a non-empty array' ) ; }
|
99 |
|
100 | if ( typeof options === 'function' ) { callback = options ; options = {} ; }
|
101 | else if ( ! options || typeof options !== 'object' ) { options = {} ; }
|
102 |
|
103 | if ( ! options.style ) { options.style = this ; }
|
104 | if ( ! options.selectedStyle ) { options.selectedStyle = this.inverse ; }
|
105 | if ( ! options.submittedStyle ) { options.submittedStyle = this.bgGray.bold ; }
|
106 | if ( ! options.disabledStyle ) { options.disabledStyle = this.dim ; }
|
107 | if ( ! options.disabledSelectedStyle ) { options.disabledSelectedStyle = this.bgGray.dim ; }
|
108 | if ( ! options.disabledSubmittedStyle ) { options.disabledSubmittedStyle = this.bgGray ; }
|
109 |
|
110 | if ( options.leftPadding === undefined ) { options.leftPadding = ' ' ; }
|
111 | if ( options.selectedLeftPadding === undefined ) { options.selectedLeftPadding = options.leftPadding ; }
|
112 | if ( options.submittedLeftPadding === undefined ) { options.submittedLeftPadding = options.leftPadding ; }
|
113 |
|
114 | if ( typeof options.extraLines !== 'number' || options.extraLines < 0 ) { options.extraLines = 1 ; }
|
115 |
|
116 | if ( ! options.itemMaxWidth ) { options.itemMaxWidth = this.width - 1 ; }
|
117 |
|
118 | if ( ! options.unsubmittableIndexes ) { options.unsubmittableIndexes = [] ; }
|
119 |
|
120 | var selectedIndex = options.selectedIndex || 0 ;
|
121 | var submittedIndex = options.submitted ? options.selectedIndex : null ;
|
122 | var paused = !! options.paused ;
|
123 |
|
124 | var keyBindings = options.keyBindings || defaultKeyBindings ;
|
125 |
|
126 | if ( ! this.grabbing ) { this.grabInput() ; }
|
127 |
|
128 |
|
129 | var start = {} , end = {} , textWidth , outerWidth , paddingLength ,
|
130 | menuItems , offsetY = 0 , lineCount = 0 , scrollLines = 0 ,
|
131 | controller , finished = false , alreadyCleanedUp = false ;
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | var init = () => {
|
140 | computeItems( menuItemsArg ) ;
|
141 |
|
142 | if ( options.y !== undefined ) {
|
143 | this.moveTo( 1 , options.y ) ;
|
144 | finishInit( 1 , options.y ) ;
|
145 | }
|
146 | else {
|
147 | this( '\n' ) ;
|
148 | this.getCursorLocation( ( error , x , y ) => {
|
149 | if ( error ) {
|
150 |
|
151 |
|
152 |
|
153 | this.row.eraseLineAfter( this.height )( '\n' ) ;
|
154 | x = 1 ;
|
155 | y = this.height ;
|
156 | }
|
157 |
|
158 | finishInit( x , y ) ;
|
159 | } ) ;
|
160 | }
|
161 | } ;
|
162 |
|
163 |
|
164 |
|
165 | var computeItems = ( menuItems_ ) => {
|
166 | textWidth = 0 ;
|
167 |
|
168 | paddingLength = Math.max( stringWidth( options.leftPadding ) , stringWidth( options.selectedLeftPadding ) ) ;
|
169 |
|
170 | menuItems_ = menuItems_.map( element => {
|
171 | if ( typeof element !== 'string' ) { element = '' + element ; }
|
172 | textWidth = Math.max( textWidth , stringWidth( element ) ) ;
|
173 | return element ;
|
174 | } ) ;
|
175 |
|
176 | if ( ! options.oneLineItem && textWidth > options.itemMaxWidth - paddingLength ) {
|
177 | outerWidth = Math.min( textWidth + paddingLength , this.width ) ;
|
178 |
|
179 | menuItems = menuItems_.map( ( element , index ) => {
|
180 |
|
181 | var item , lines ,
|
182 | lineLength = options.itemMaxWidth - paddingLength ;
|
183 |
|
184 | lines = string.wordwrap( element , {
|
185 | width: lineLength ,
|
186 | noJoin: true ,
|
187 | fill: true ,
|
188 | skipFn: termkit.escapeSequenceSkipFn
|
189 | } ) ;
|
190 |
|
191 | item = {
|
192 | offsetY: offsetY ,
|
193 | index: index ,
|
194 | text: element ,
|
195 | displayText: lines
|
196 | } ;
|
197 |
|
198 | offsetY += lines.length ;
|
199 |
|
200 | return item ;
|
201 | } ) ;
|
202 |
|
203 | lineCount = offsetY ;
|
204 | }
|
205 | else {
|
206 | textWidth = Math.min( textWidth , options.itemMaxWidth - paddingLength ) ;
|
207 | outerWidth = Math.min( textWidth + paddingLength , this.width ) ;
|
208 |
|
209 | menuItems = menuItems_.map( ( element , index ) => {
|
210 | var elementWidth = stringWidth( element ) ;
|
211 |
|
212 | return {
|
213 | offsetY: index ,
|
214 | index: index ,
|
215 | text: element ,
|
216 | displayText: [ elementWidth > textWidth ?
|
217 | element.slice( 0 , textWidth - 1 ) + '…' :
|
218 | element + ' '.repeat( textWidth - elementWidth ) ]
|
219 | } ;
|
220 | } ) ;
|
221 |
|
222 | lineCount = menuItems.length ;
|
223 | }
|
224 | } ;
|
225 |
|
226 |
|
227 |
|
228 | var finishInit = ( x , y ) => {
|
229 |
|
230 | if ( finished ) { return ; }
|
231 |
|
232 | prepareArea( x , y ) ;
|
233 | redraw() ;
|
234 |
|
235 | this.on( 'key' , onKey ) ;
|
236 | if ( this.mouseGrabbing ) { this.on( 'mouse' , onMouse ) ; }
|
237 |
|
238 | controller.emit( 'ready' ) ;
|
239 | emitHighlight() ;
|
240 | } ;
|
241 |
|
242 |
|
243 |
|
244 | var emitHighlight = () => {
|
245 | var item = menuItems[ selectedIndex ] ;
|
246 |
|
247 | controller.emit( 'highlight' , {
|
248 | highlightedIndex: item.index ,
|
249 | highlightedText: item.text ,
|
250 | submitted: submittedIndex !== null ,
|
251 | x: 1 ,
|
252 | y: start.y + item.offsetY
|
253 | } ) ;
|
254 |
|
255 | } ;
|
256 |
|
257 |
|
258 |
|
259 | var prepareArea = ( x , y ) => {
|
260 | start.x = x ;
|
261 | start.y = y ;
|
262 |
|
263 | end.x = 1 ;
|
264 | end.y = y + lineCount ;
|
265 |
|
266 | scrollLines = start.y + lineCount - ( options.scrollRegionBottom || this.height ) - 1 + options.extraLines ;
|
267 |
|
268 | if ( scrollLines > 0 ) {
|
269 |
|
270 | this( '\n'.repeat( scrollLines ) ) ;
|
271 | start.y -= scrollLines ;
|
272 | end.y -= scrollLines ;
|
273 | }
|
274 | } ;
|
275 |
|
276 |
|
277 |
|
278 | var cleanup = ( error , data , eraseMenu ) => {
|
279 | if ( alreadyCleanedUp ) { return ; }
|
280 | alreadyCleanedUp = true ;
|
281 |
|
282 | finished = true ;
|
283 | this.removeListener( 'key' , onKey ) ;
|
284 | this.removeListener( 'mouse' , onMouse ) ;
|
285 |
|
286 | if ( error === 'abort' ) { return ; }
|
287 |
|
288 | if ( controller.hasState( 'ready' ) ) {
|
289 | if ( eraseMenu ) { erase() ; }
|
290 | else { this.moveTo( 1 , end.y ) ; }
|
291 | }
|
292 |
|
293 | if ( error ) {
|
294 | if ( callback ) { callback( error ) ; }
|
295 | else { controller.promise.reject( error ) ; }
|
296 | return ;
|
297 | }
|
298 |
|
299 | var value = data !== undefined ? data : {
|
300 | selectedIndex: selectedIndex ,
|
301 | selectedText: menuItems[ selectedIndex ].text ,
|
302 | submitted: submittedIndex !== null ,
|
303 | x: 1 ,
|
304 | y: start.y + menuItems[ selectedIndex ].offsetY
|
305 | } ;
|
306 |
|
307 | if ( callback ) { callback( undefined , value ) ; }
|
308 | else { controller.promise.resolve( value ) ; }
|
309 | } ;
|
310 |
|
311 |
|
312 |
|
313 | var erase = () => {
|
314 | if ( ! controller.hasState( 'ready' ) ) { controller.once( 'ready' , erase ) ; return ; }
|
315 |
|
316 | var i , j ;
|
317 |
|
318 | for ( i = start.x , j = start.y ; j <= end.y ; i = 1 , j ++ ) {
|
319 | this.moveTo.eraseLineAfter( i , j ) ;
|
320 | }
|
321 |
|
322 | this.moveTo( 1 , start.y ) ;
|
323 | } ;
|
324 |
|
325 |
|
326 |
|
327 |
|
328 | var redraw = () => {
|
329 | for ( var i = 0 ; i < menuItems.length ; i ++ ) { redrawItem( i ) ; }
|
330 | redrawCursor() ;
|
331 | } ;
|
332 |
|
333 |
|
334 |
|
335 | var redrawItem = ( index ) => {
|
336 |
|
337 |
|
338 |
|
339 |
|
340 | var item = menuItems[ index ] ;
|
341 |
|
342 | item.displayText.forEach( ( text , line ) => {
|
343 |
|
344 | this.moveTo( 1 , start.y + item.offsetY + line ) ;
|
345 |
|
346 | if ( paused || options.unsubmittableIndexes[ index ] ) {
|
347 | if ( index === submittedIndex ) {
|
348 | if ( line ) { options.disabledSubmittedStyle.forceStyleOnReset.noFormat( options.leftPadding ) ; }
|
349 | else { options.disabledSubmittedStyle.forceStyleOnReset.noFormat( options.submittedLeftPadding ) ; }
|
350 |
|
351 | options.disabledSubmittedStyle.forceStyleOnReset.noFormat( text ) ;
|
352 | }
|
353 | else if ( index === selectedIndex ) {
|
354 | if ( line ) { options.disabledSelectedStyle.forceStyleOnReset.noFormat( options.leftPadding ) ; }
|
355 | else { options.disabledSelectedStyle.forceStyleOnReset.noFormat( options.selectedLeftPadding ) ; }
|
356 |
|
357 | options.disabledSelectedStyle.forceStyleOnReset.noFormat( text ) ;
|
358 | }
|
359 | else {
|
360 | options.disabledStyle.forceStyleOnReset.noFormat( options.leftPadding ) ;
|
361 | options.disabledStyle.forceStyleOnReset.noFormat( text ) ;
|
362 | }
|
363 | }
|
364 | else if ( index === submittedIndex ) {
|
365 | if ( line ) { options.submittedStyle.forceStyleOnReset.noFormat( options.leftPadding ) ; }
|
366 | else { options.submittedStyle.forceStyleOnReset.noFormat( options.submittedLeftPadding ) ; }
|
367 |
|
368 | options.submittedStyle.forceStyleOnReset.noFormat( text ) ;
|
369 | }
|
370 | else if ( index === selectedIndex ) {
|
371 | if ( line ) { options.selectedStyle.forceStyleOnReset.noFormat( options.leftPadding ) ; }
|
372 | else { options.selectedStyle.forceStyleOnReset.noFormat( options.selectedLeftPadding ) ; }
|
373 |
|
374 | options.selectedStyle.forceStyleOnReset.noFormat( text ) ;
|
375 | }
|
376 | else {
|
377 | options.style.forceStyleOnReset.noFormat( options.leftPadding ) ;
|
378 | options.style.forceStyleOnReset.noFormat( text ) ;
|
379 | }
|
380 | } ) ;
|
381 | } ;
|
382 |
|
383 |
|
384 |
|
385 | var redrawCursor = () => {
|
386 |
|
387 |
|
388 | this.moveTo( 1 , start.y + menuItems[ selectedIndex ].offsetY ) ;
|
389 | } ;
|
390 |
|
391 |
|
392 |
|
393 | var select = ( index ) => {
|
394 | var oldSelectedIndex = selectedIndex ;
|
395 |
|
396 | if ( selectedIndex !== index && index >= 0 && index < menuItems.length ) {
|
397 | selectedIndex = index ;
|
398 |
|
399 |
|
400 | if ( controller.hasState( 'ready' ) ) {
|
401 | redrawItem( oldSelectedIndex ) ;
|
402 | redrawItem( selectedIndex ) ;
|
403 | redrawCursor() ;
|
404 | emitHighlight() ;
|
405 | }
|
406 | }
|
407 | } ;
|
408 |
|
409 |
|
410 |
|
411 | var submit = () => {
|
412 | if ( submittedIndex !== null || options.unsubmittableIndexes[ selectedIndex ] ) { return ; }
|
413 | submittedIndex = selectedIndex ;
|
414 |
|
415 |
|
416 | if ( controller.hasState( 'ready' ) ) {
|
417 | redrawItem( submittedIndex ) ;
|
418 | redrawCursor() ;
|
419 | }
|
420 |
|
421 | controller.emit( 'submit' , {
|
422 | selectedIndex: submittedIndex ,
|
423 | selectedText: menuItems[ submittedIndex ].text ,
|
424 | submitted: true ,
|
425 | x: 1 ,
|
426 | y: start.y + menuItems[ submittedIndex ].offsetY
|
427 | } ) ;
|
428 |
|
429 | if ( ! options.continueOnSubmit ) { cleanup() ; }
|
430 | } ;
|
431 |
|
432 |
|
433 |
|
434 | var cancel = () => {
|
435 | var oldSelectedIndex = submittedIndex ;
|
436 |
|
437 | if ( submittedIndex === null ) { return ; }
|
438 | submittedIndex = null ;
|
439 | redrawItem( oldSelectedIndex ) ;
|
440 | redrawCursor() ;
|
441 | controller.emit( 'cancel' ) ;
|
442 | } ;
|
443 |
|
444 |
|
445 |
|
446 | var pause = () => {
|
447 | if ( paused ) { return ; }
|
448 | paused = true ;
|
449 |
|
450 |
|
451 | if ( controller.hasState( 'ready' ) ) { redraw() ; }
|
452 | } ;
|
453 |
|
454 |
|
455 |
|
456 | var resume = () => {
|
457 | if ( ! paused ) { return ; }
|
458 | paused = false ;
|
459 |
|
460 |
|
461 | if ( controller.hasState( 'ready' ) ) { redraw() ; }
|
462 | } ;
|
463 |
|
464 |
|
465 |
|
466 | var onKey = ( key , trash , data ) => {
|
467 |
|
468 | if ( finished || paused ) { return ; }
|
469 |
|
470 | var oldSelectedIndex = selectedIndex ;
|
471 |
|
472 | switch ( keyBindings[ key ] ) {
|
473 | case 'submit' :
|
474 | submit() ;
|
475 | break ;
|
476 |
|
477 | case 'previous' :
|
478 | if ( submittedIndex !== null ) { return ; }
|
479 | if ( selectedIndex > 0 ) {
|
480 | selectedIndex -- ;
|
481 | redrawItem( selectedIndex ) ;
|
482 | redrawItem( selectedIndex + 1 ) ;
|
483 | redrawCursor() ;
|
484 |
|
485 | emitHighlight() ;
|
486 | }
|
487 | break ;
|
488 |
|
489 | case 'next' :
|
490 | if ( submittedIndex !== null ) { return ; }
|
491 | if ( selectedIndex < menuItems.length - 1 ) {
|
492 | selectedIndex ++ ;
|
493 | redrawItem( selectedIndex - 1 ) ;
|
494 | redrawItem( selectedIndex ) ;
|
495 | redrawCursor() ;
|
496 |
|
497 | emitHighlight() ;
|
498 | }
|
499 | break ;
|
500 |
|
501 | case 'cyclePrevious' :
|
502 | if ( submittedIndex !== null ) { return ; }
|
503 | selectedIndex -- ;
|
504 |
|
505 | if ( selectedIndex < 0 ) { selectedIndex = menuItems.length - 1 ; }
|
506 |
|
507 | redrawItem( oldSelectedIndex ) ;
|
508 | redrawItem( selectedIndex ) ;
|
509 | redrawCursor() ;
|
510 |
|
511 | emitHighlight() ;
|
512 | break ;
|
513 |
|
514 | case 'cycleNext' :
|
515 | if ( submittedIndex !== null ) { return ; }
|
516 | selectedIndex ++ ;
|
517 |
|
518 | if ( selectedIndex >= menuItems.length ) { selectedIndex = 0 ; }
|
519 |
|
520 | redrawItem( oldSelectedIndex ) ;
|
521 | redrawItem( selectedIndex ) ;
|
522 | redrawCursor() ;
|
523 |
|
524 | emitHighlight() ;
|
525 | break ;
|
526 |
|
527 | case 'first' :
|
528 | if ( submittedIndex !== null ) { return ; }
|
529 | if ( selectedIndex !== 0 ) {
|
530 | selectedIndex = 0 ;
|
531 | redrawItem( oldSelectedIndex ) ;
|
532 | redrawItem( selectedIndex ) ;
|
533 | redrawCursor() ;
|
534 |
|
535 | emitHighlight() ;
|
536 | }
|
537 | break ;
|
538 |
|
539 | case 'last' :
|
540 | if ( submittedIndex !== null ) { return ; }
|
541 | if ( selectedIndex !== menuItems.length - 1 ) {
|
542 | selectedIndex = menuItems.length - 1 ;
|
543 | redrawItem( oldSelectedIndex ) ;
|
544 | redrawItem( selectedIndex ) ;
|
545 | redrawCursor() ;
|
546 |
|
547 | emitHighlight() ;
|
548 | }
|
549 | break ;
|
550 |
|
551 | case 'cancel' :
|
552 | cancel() ;
|
553 | break ;
|
554 |
|
555 | case 'escape' :
|
556 | if ( options.cancelable ) {
|
557 | cleanup( undefined , { canceled: true } ) ;
|
558 | }
|
559 | if ( options.exitOnUnexpectedKey ) {
|
560 | cleanup( undefined , { unexpectedKey: key , unexpectedKeyData: data } ) ;
|
561 | }
|
562 | break ;
|
563 |
|
564 | default :
|
565 | if ( options.exitOnUnexpectedKey ) {
|
566 | cleanup( undefined , { unexpectedKey: key , unexpectedKeyData: data } ) ;
|
567 | }
|
568 | break ;
|
569 | }
|
570 | } ;
|
571 |
|
572 |
|
573 |
|
574 | var onMouse = ( name , data ) => {
|
575 |
|
576 | if ( finished || paused || submittedIndex !== null ) { return ; }
|
577 |
|
578 |
|
579 | if ( data.y < start.y || data.y >= end.y ) { return ; }
|
580 |
|
581 | var i , yMin , yMax ,
|
582 | inBounds = false ;
|
583 |
|
584 | for ( i = 0 ; i < menuItems.length ; i ++ ) {
|
585 | yMin = start.y + menuItems[ i ].offsetY ;
|
586 | yMax = start.y + menuItems[ i ].offsetY + menuItems[ i ].displayText.length - 1 ;
|
587 |
|
588 | if ( data.y >= yMin && data.y <= yMax && data.x < 1 + outerWidth ) {
|
589 | inBounds = true ;
|
590 | select( i ) ;
|
591 | break ;
|
592 | }
|
593 | }
|
594 |
|
595 | if ( inBounds && name === 'MOUSE_LEFT_BUTTON_PRESSED' ) {
|
596 | submit() ;
|
597 | }
|
598 | } ;
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 | controller = Object.create( NextGenEvents.prototype ) ;
|
605 |
|
606 | controller.defineStates( 'ready' ) ;
|
607 |
|
608 |
|
609 | controller.abort = () => {
|
610 | if ( finished ) { return ; }
|
611 | cleanup( 'abort' ) ;
|
612 | } ;
|
613 |
|
614 |
|
615 | controller.stop = ( eraseMenu ) => {
|
616 | if ( finished ) { return ; }
|
617 | cleanup( undefined , undefined , eraseMenu ) ;
|
618 | } ;
|
619 |
|
620 | controller.select = select ;
|
621 | controller.submit = submit ;
|
622 | controller.cancel = cancel ;
|
623 | controller.erase = erase ;
|
624 |
|
625 |
|
626 | controller.pause = pause ;
|
627 | controller.resume = resume ;
|
628 | controller.focus = ( value ) => {
|
629 | if ( value ) { resume() ; }
|
630 | else { pause() ; }
|
631 | } ;
|
632 |
|
633 |
|
634 | controller.getState = () => ( {
|
635 | selectedIndex: selectedIndex ,
|
636 | selectedText: menuItems[ selectedIndex ].text ,
|
637 | submitted: submittedIndex !== null ,
|
638 | start: start ,
|
639 | end: end ,
|
640 | x: 1 ,
|
641 | y: start.y + menuItems[ selectedIndex ].offsetY
|
642 |
|
643 | } ) ;
|
644 |
|
645 |
|
646 | controller.getPosition = () => ( { x: start.x , y: start.y } ) ;
|
647 |
|
648 |
|
649 | controller.hide = () => {
|
650 | if ( ! controller.hasState( 'ready' ) ) { controller.once( 'ready' , controller.hide ) ; return ; }
|
651 | erase() ;
|
652 | } ;
|
653 |
|
654 |
|
655 | controller.show = () => {
|
656 | if ( ! controller.hasState( 'ready' ) ) { controller.once( 'ready' , controller.show ) ; return ; }
|
657 | redraw() ;
|
658 | } ;
|
659 |
|
660 |
|
661 | controller.redraw = () => {
|
662 | if ( ! controller.hasState( 'ready' ) ) { controller.once( 'ready' , controller.redraw ) ; return ; }
|
663 | redraw() ;
|
664 | } ;
|
665 |
|
666 |
|
667 | controller.redrawCursor = () => {
|
668 | if ( ! controller.hasState( 'ready' ) ) { controller.once( 'ready' , controller.redrawCursor ) ; return ; }
|
669 | redrawCursor() ;
|
670 | } ;
|
671 |
|
672 |
|
673 | controller.rebase = () => {
|
674 | if ( ! controller.hasState( 'ready' ) ) { controller.once( 'ready' , controller.rebase ) ; return ; }
|
675 |
|
676 |
|
677 | var wasPaused = paused ;
|
678 | paused = true ;
|
679 |
|
680 | this.getCursorLocation( ( error , x , y ) => {
|
681 | if ( error ) {
|
682 |
|
683 |
|
684 |
|
685 | return ;
|
686 | }
|
687 |
|
688 | paused = wasPaused ;
|
689 | prepareArea( x , y ) ;
|
690 | redraw() ;
|
691 | controller.emit( 'rebased' ) ;
|
692 | } ) ;
|
693 | } ;
|
694 |
|
695 | controller.promise = new Promise() ;
|
696 |
|
697 |
|
698 | init() ;
|
699 |
|
700 | return controller ;
|
701 | } ;
|
702 |
|