Create initial version of TerminadoService

WebSocket address is hardcoded temporarily
This commit is contained in:
Bálint Bokros 2018-01-17 17:24:56 +01:00
parent caef4360b0
commit 4607219ed6
2 changed files with 39 additions and 1 deletions

View File

@ -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

View 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();
}
}