mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2024-12-05 02:31:33 +00:00
Create initial version of TerminadoService
WebSocket address is hardcoded temporarily
This commit is contained in:
parent
caef4360b0
commit
4607219ed6
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user