ng-terminal-app
v0.0.0
Published
[](https://travis-ci.org/qwefgh90/ng-terminal) [](https://www.npmjs.com/package/ng-terminal) [ is called.
//...
export class YourComponent implements AfterViewInit{
@ViewChild('term', { static: true }) child: NgTerminal;
ngAfterViewInit(){
this.child.keyEventInput.subscribe(e => {
console.log('keyboard event:' + e.domEvent.keyCode + ', ' + e.key);
const ev = e.domEvent;
const printable = !ev.altKey && !ev.ctrlKey && !ev.metaKey;
if (ev.keyCode === 13) {
this.child.write('\r\n$ ');
} else if (ev.keyCode === 8) {
// Do not delete the prompt
if (this.child.underlying.buffer.cursorX > 2) {
this.child.write('\b \b');
}
} else if (printable) {
this.child.write(e.key);
}
})
}
//...API
There are two ways to control the terminal. Calling API which is a interface of NgTerminal provides is a direct way to control the terminal. You can bind a instance by using @ViewChild. Another way is to use input/output properties.
NgTerminal (API)
NgTerminal is a interface to provide public APIs you can call directly. You can get a object by using @ViewChild with a type of NgTerminal.
import { NgTerminal } from 'ng-terminal';
...
@ViewChild('term') child: NgTerminal; // for Angular 7
@ViewChild('term', { static: true }) child: NgTerminal; // for Angular 8NgTerminalComponent (input/output properties)
NgTerminalComponent is a component to implement NgTerminal and draw the terminal.
<ng-terminal #term [dataSource]="writeSubject" (keyEvent)="onKeyEvent($event)" [displayOption]="displayOptionBounded"></ng-terminal>Underlying object
You can control a instance of the xtermjs directly by getting a property of underlying. Check out API of the Terminal from the API document
Control sequences
Control sequences is a programing interface to control terminal emulators. There are functions to return control sequences in a class of FunctionUsingCSI.
import { FunctionsUsingCSI } from 'ng-terminal';
...
const sequences = "data..1" + FunctionsUsingCSI.cursorBackward(1) + '2';
component.write(sequences);You can also find a full set of sequences here. For example, you can break lines by passing \x1b[1E to write(). Try in the sample page
Contribution
NgTerminal is developed with Angular CLI. You can always write issue and contribute through PR to master branch.
