@@ -23,7 +23,7 @@ import {
2323 * - Auto-complete hooks
2424 */
2525export default class LocalEchoController {
26- constructor ( term , options = { } ) {
26+ constructor ( term = null , options = { } ) {
2727 this . term = term ;
2828 this . _handleTermData = this . handleTermData . bind ( this ) ;
2929 this . _handleTermResize = this . handleTermResize . bind ( this )
@@ -38,11 +38,25 @@ export default class LocalEchoController {
3838 this . _activePrompt = null ;
3939 this . _activeCharPrompt = null ;
4040 this . _termSize = {
41- cols : this . term . cols ,
42- rows : this . term . rows
41+ cols : 0 ,
42+ rows : 0 ,
4343 } ;
44+
45+ this . _disposables = [ ] ;
4446
45- this . attach ( )
47+ if ( term ) {
48+ if ( term . loadAddon ) term . loadAddon ( this ) ;
49+ else this . attach ( ) ;
50+ }
51+ }
52+
53+ // xterm.js new plugin API:
54+ activate ( term ) {
55+ this . term = term ;
56+ this . attach ( ) ;
57+ }
58+ dispose ( ) {
59+ this . detach ( ) ;
4660 }
4761
4862 /////////////////////////////////////////////////////////////////////////////
@@ -53,16 +67,30 @@ export default class LocalEchoController {
5367 * Detach the controller from the terminal
5468 */
5569 detach ( ) {
56- this . term . off ( "data" , this . _handleTermData ) ;
57- this . term . off ( "resize" , this . _handleTermResize ) ;
70+ if ( this . term . off ) {
71+ this . term . off ( "data" , this . _handleTermData ) ;
72+ this . term . off ( "resize" , this . _handleTermResize ) ;
73+ } else {
74+ this . _disposables . forEach ( d => d . dispose ( ) ) ;
75+ this . _disposables = [ ] ;
76+ }
5877 }
5978
6079 /**
6180 * Attach controller to the terminal, handling events
6281 */
6382 attach ( ) {
64- this . term . on ( "data" , this . _handleTermData ) ;
65- this . term . on ( "resize" , this . _handleTermResize ) ;
83+ if ( this . term . on ) {
84+ this . term . on ( "data" , this . _handleTermData ) ;
85+ this . term . on ( "resize" , this . _handleTermResize ) ;
86+ } else {
87+ this . _disposables . push ( this . term . onData ( this . _handleTermData ) ) ;
88+ this . _disposables . push ( this . term . onResize ( this . _handleTermResize ) ) ;
89+ }
90+ this . _termSize = {
91+ cols : this . term . cols ,
92+ rows : this . term . rows ,
93+ } ;
6694 }
6795
6896 /**
0 commit comments