diff --git a/src/app/components/project-map/console-wrapper/console-wrapper.component.ts b/src/app/components/project-map/console-wrapper/console-wrapper.component.ts index 0f3411be..0efada5b 100644 --- a/src/app/components/project-map/console-wrapper/console-wrapper.component.ts +++ b/src/app/components/project-map/console-wrapper/console-wrapper.component.ts @@ -119,6 +119,8 @@ export class ConsoleWrapperComponent implements OnInit { height: `${event.rectangle.height - 60}px`, width: `${event.rectangle.width}px` }; + + this.consoleService.resizeTerminal(); } close() { diff --git a/src/app/components/project-map/web-console/web-console.component.ts b/src/app/components/project-map/web-console/web-console.component.ts index 0fe3e1f2..38c550bb 100644 --- a/src/app/components/project-map/web-console/web-console.component.ts +++ b/src/app/components/project-map/web-console/web-console.component.ts @@ -9,7 +9,7 @@ import { NodeConsoleService } from '../../../services/nodeConsole.service'; @Component({ - encapsulation: ViewEncapsulation.None, + encapsulation: ViewEncapsulation.ShadowDom, selector: 'app-web-console', templateUrl: './web-console.component.html', styleUrls: ['../../../../../node_modules/xterm/css/xterm.css'] @@ -18,17 +18,23 @@ export class WebConsoleComponent implements OnInit, AfterViewInit { @Input() server: Server; @Input() project: Project; @Input() node: Node; - public term: Terminal; + + public term: Terminal = new Terminal(); + public fitAddon: FitAddon = new FitAddon(); + @ViewChild('terminal', {static: false}) terminal: ElementRef; constructor( private consoleService: NodeConsoleService ) {} - ngOnInit() {} + ngOnInit() { + this.consoleService.consoleResized.subscribe(ev => { + this.fitAddon.fit(); + }); + } ngAfterViewInit() { - this.term = new Terminal(); setTimeout(() => { this.term.open(this.terminal.nativeElement); const socket = new WebSocket(this.getUrl()); @@ -44,9 +50,10 @@ export class WebConsoleComponent implements OnInit, AfterViewInit { this.term.loadAddon(attachAddon); this.term.setOption('cursorBlink', true); - const fitAddon = new FitAddon(); - this.term.loadAddon(fitAddon); - fitAddon.activate(this.term); + this.term.loadAddon(this.fitAddon); + this.fitAddon.activate(this.term); + + this.term.focus(); }, 1000); } diff --git a/src/app/services/nodeConsole.service.ts b/src/app/services/nodeConsole.service.ts index 77892a6d..77467943 100644 --- a/src/app/services/nodeConsole.service.ts +++ b/src/app/services/nodeConsole.service.ts @@ -6,6 +6,7 @@ import { Subject } from 'rxjs'; export class NodeConsoleService { public nodeConsoleTrigger = new EventEmitter(); public closeNodeConsoleTrigger = new Subject(); + public consoleResized = new Subject(); constructor() {} @@ -14,6 +15,10 @@ export class NodeConsoleService { } closeConsoleForNode(node: Node) { - this.closeNodeConsoleTrigger.next(node) + this.closeNodeConsoleTrigger.next(node); + } + + resizeTerminal() { + this.consoleResized.next(true); } }