mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 12:22:54 +00:00 
			
		
		
		
	Create initial version of TerminadoService
WebSocket address is hardcoded temporarily
This commit is contained in:
		@@ -10,6 +10,7 @@ import { AppComponent } from './app.component';
 | 
			
		||||
import { HeaderComponent } from './header/header.component';
 | 
			
		||||
import { LoginComponent } from './login/login.component';
 | 
			
		||||
import { MarkdownService } from './markdown.service';
 | 
			
		||||
import { TerminadoService } from './terminado.service';
 | 
			
		||||
import { WebideComponent } from './webide/webide.component';
 | 
			
		||||
import { LogsComponent } from './logs/logs.component';
 | 
			
		||||
import { TestButtonComponent } from './test-button/test-button.component';
 | 
			
		||||
@@ -34,7 +35,8 @@ import { WebSocketService } from './websocket.service';
 | 
			
		||||
  ],
 | 
			
		||||
  providers: [
 | 
			
		||||
    MarkdownService,
 | 
			
		||||
    WebSocketService
 | 
			
		||||
    WebSocketService,
 | 
			
		||||
    TerminadoService
 | 
			
		||||
  ],
 | 
			
		||||
  bootstrap: [
 | 
			
		||||
    AppComponent
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								src/app/terminado.service.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/app/terminado.service.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
import { Injectable } from '@angular/core';
 | 
			
		||||
import { Terminal } from 'xterm';
 | 
			
		||||
import * as fit from 'xterm/lib/addons/fit/fit';
 | 
			
		||||
import * as terminado from 'xterm/lib/addons/terminado/terminado';
 | 
			
		||||
 | 
			
		||||
@Injectable()
 | 
			
		||||
export class TerminadoService {
 | 
			
		||||
  xterm: Terminal;
 | 
			
		||||
  ws: WebSocket;
 | 
			
		||||
 | 
			
		||||
  constructor() {
 | 
			
		||||
    Terminal.applyAddon(fit);
 | 
			
		||||
    Terminal.applyAddon(terminado);
 | 
			
		||||
    this.xterm = new Terminal();
 | 
			
		||||
    this.ws = new WebSocket('ws://localhost:7878/terminal');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  attach(element: HTMLElement) {
 | 
			
		||||
    this.ws.onopen = () => {
 | 
			
		||||
      (<any>this.xterm).terminadoAttach(this.ws);
 | 
			
		||||
      this.xterm.open(element);
 | 
			
		||||
      this.fit();
 | 
			
		||||
      this.xterm.blur();
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  detach() {
 | 
			
		||||
    (<any>this.xterm).terminadoDetach(this.ws);
 | 
			
		||||
    this.xterm.destroy();
 | 
			
		||||
    this.ws.close();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fit() {
 | 
			
		||||
    (<any>this.xterm).fit();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user