import { Injectable, EventEmitter } from '@angular/core'; import { Node } from '../cartography/models/node'; import { Subject } from 'rxjs'; @Injectable() export class NodeConsoleService { public nodeConsoleTrigger = new EventEmitter(); public closeNodeConsoleTrigger = new Subject(); public consoleResized = new Subject(); public openConsoles: number = 0; public readonly defaultConsoleWidth = 720; public readonly defaultConsoleHeight = 408; public readonly defaultNumberOfColumns = 80; public readonly defaultNumberOfRows = 24; private lastNumberOfColumns: number; private lastNumberOfRows: number; constructor() {} getNumberOfColumns() { return this.lastNumberOfColumns; } getNumberOfRows() { return this.lastNumberOfRows; } setNumberOfColumns(value: number) { this.lastNumberOfColumns = value; } setNumberOfRows(value: number) { this.lastNumberOfRows = value; } openConsoleForNode(node: Node) { this.nodeConsoleTrigger.emit(node); } closeConsoleForNode(node: Node) { this.closeNodeConsoleTrigger.next(node); } resizeTerminal(event: ConsoleResizedEvent) { this.consoleResized.next(event); } getLineWidth() { return this.defaultConsoleWidth / this.defaultNumberOfColumns; } getLineHeight() { return this.defaultConsoleHeight / this.defaultNumberOfRows; } } export interface ConsoleResizedEvent { width: number, height: number }