terminal.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var forms_1 = require("@angular/forms");
  14. var common_1 = require("@angular/common");
  15. var domhandler_1 = require("../dom/domhandler");
  16. var terminalservice_1 = require("./terminalservice");
  17. var Terminal = /** @class */ (function () {
  18. function Terminal(el, terminalService) {
  19. var _this = this;
  20. this.el = el;
  21. this.terminalService = terminalService;
  22. this.commands = [];
  23. this.subscription = terminalService.responseHandler.subscribe(function (response) {
  24. _this.commands[_this.commands.length - 1].response = response;
  25. _this.commandProcessed = true;
  26. });
  27. }
  28. Terminal.prototype.ngAfterViewInit = function () {
  29. this.container = domhandler_1.DomHandler.find(this.el.nativeElement, '.ui-terminal')[0];
  30. };
  31. Terminal.prototype.ngAfterViewChecked = function () {
  32. if (this.commandProcessed) {
  33. this.container.scrollTop = this.container.scrollHeight;
  34. this.commandProcessed = false;
  35. }
  36. };
  37. Object.defineProperty(Terminal.prototype, "response", {
  38. set: function (value) {
  39. if (value) {
  40. this.commands[this.commands.length - 1].response = value;
  41. this.commandProcessed = true;
  42. }
  43. },
  44. enumerable: true,
  45. configurable: true
  46. });
  47. Terminal.prototype.handleCommand = function (event) {
  48. if (event.keyCode == 13) {
  49. this.commands.push({ text: this.command });
  50. this.terminalService.sendCommand(this.command);
  51. this.command = '';
  52. }
  53. };
  54. Terminal.prototype.focus = function (element) {
  55. element.focus();
  56. };
  57. Terminal.prototype.ngOnDestroy = function () {
  58. if (this.subscription) {
  59. this.subscription.unsubscribe();
  60. }
  61. };
  62. __decorate([
  63. core_1.Input(),
  64. __metadata("design:type", String)
  65. ], Terminal.prototype, "welcomeMessage", void 0);
  66. __decorate([
  67. core_1.Input(),
  68. __metadata("design:type", String)
  69. ], Terminal.prototype, "prompt", void 0);
  70. __decorate([
  71. core_1.Input(),
  72. __metadata("design:type", Object)
  73. ], Terminal.prototype, "style", void 0);
  74. __decorate([
  75. core_1.Input(),
  76. __metadata("design:type", String)
  77. ], Terminal.prototype, "styleClass", void 0);
  78. __decorate([
  79. core_1.Input(),
  80. __metadata("design:type", String),
  81. __metadata("design:paramtypes", [String])
  82. ], Terminal.prototype, "response", null);
  83. Terminal = __decorate([
  84. core_1.Component({
  85. selector: 'p-terminal',
  86. template: "\n <div [ngClass]=\"'ui-terminal ui-widget ui-widget-content ui-corner-all'\" [ngStyle]=\"style\" [class]=\"styleClass\" (click)=\"focus(in)\">\n <div *ngIf=\"welcomeMessage\">{{welcomeMessage}}</div>\n <div class=\"ui-terminal-content\">\n <div *ngFor=\"let command of commands\">\n <span>{{prompt}}</span>\n <span class=\"ui-terminal-command\">{{command.text}}</span>\n <div>{{command.response}}</div>\n </div>\n </div>\n <div>\n <span class=\"ui-terminal-content-prompt\">{{prompt}}</span>\n <input #in type=\"text\" [(ngModel)]=\"command\" class=\"ui-terminal-input\" autocomplete=\"off\" (keydown)=\"handleCommand($event)\" autofocus>\n </div>\n </div>\n "
  87. }),
  88. __metadata("design:paramtypes", [core_1.ElementRef, terminalservice_1.TerminalService])
  89. ], Terminal);
  90. return Terminal;
  91. }());
  92. exports.Terminal = Terminal;
  93. var TerminalModule = /** @class */ (function () {
  94. function TerminalModule() {
  95. }
  96. TerminalModule = __decorate([
  97. core_1.NgModule({
  98. imports: [common_1.CommonModule, forms_1.FormsModule],
  99. exports: [Terminal],
  100. declarations: [Terminal]
  101. })
  102. ], TerminalModule);
  103. return TerminalModule;
  104. }());
  105. exports.TerminalModule = TerminalModule;
  106. //# sourceMappingURL=terminal.js.map