Home page carousel
[eliot.git] / blueprints / common / eliot-ui / frontend-src / src / app / terminal / terminal.component.ts
1 import { Component, OnInit, ViewChild } from '@angular/core';
2
3 // import { NgTerminal } from 'NgterminalModule';
4
5 // import { NgTerminal } from '@angular/material/NgTerminal';
6 import { NgTerminal } from 'ng-terminal';
7 import { Terminal } from 'xterm';
8 @Component({
9   selector: 'app-terminal',
10   templateUrl: './terminal.component.html',
11   styleUrls: ['./terminal.component.scss']
12 })
13 export class TerminalComponent implements OnInit {
14
15   @ViewChild('term', { static: true }) child: NgTerminal;
16   obj = {} 
17   
18   constructor() {
19     this.obj = new Terminal(
20       {
21
22       }
23     );
24   }
25
26   ngOnInit() {
27     
28   }
29   
30   ngAfterViewInit(){
31   this.child.keyEventInput.subscribe(e => {
32     console.log('keyboard event:' + e.domEvent.keyCode + ', ' + e.key);
33
34     const ev = e.domEvent;
35     const printable = !ev.altKey && !ev.ctrlKey && !ev.metaKey;
36
37     if (ev.keyCode === 13) {
38       this.child.write('\r\neliot@sample$ ');
39     } else if (ev.keyCode === 8) {
40       // Do not delete the prompt
41       if (this.child.underlying.buffer.cursorX > 14) {
42         this.child.write('\b \b');
43       }
44     } else if (printable) {
45       this.child.write(e.key);
46     }
47
48     
49   })
50   }
51 }