diff --git a/src/app/devsync/compute/Uploader.ts b/src/app/devsync/compute/Uploader.ts index e457b79..f83873d 100644 --- a/src/app/devsync/compute/Uploader.ts +++ b/src/app/devsync/compute/Uploader.ts @@ -86,7 +86,7 @@ export default class Uploader { }); stream.on('data', (dd: any) => { if (_consoleAction != "basic") return; - if (this._consoleCache.length >= 5000) { + if (this._consoleCache.length >= 2000) { this._consoleCache.shift(); }; this._consoleCache.push(dd); @@ -108,6 +108,7 @@ export default class Uploader { }) } + let _localRecordText = ""; var _keypress = (key: string, data: any) => { let isStop = false; for (var a = 1; a <= 9; a++) { @@ -129,7 +130,14 @@ export default class Uploader { switch (data.sequence) { case '\u0003': return; + case '\r': + if (_localRecordText.includes("clear")) { + this._consoleCache = []; + } + _localRecordText = ""; + break; } + _localRecordText += data.sequence; } process.stdin.on("keypress", _keypress) } catch (ex) { @@ -163,6 +171,7 @@ export default class Uploader { } } let timesCloseClick = 0; + let _localRecordText = ""; let _keypress = (key: string, data: any) => { let isStop = false; for (var a = 1; a <= 9; a++) { @@ -204,7 +213,14 @@ export default class Uploader { switch (data.sequence) { case '\u0003': return; + case '\r': + if (_localRecordText.includes("clear")) { + _consoleCaches[index] = []; + } + _localRecordText = ""; + break; } + _localRecordText += data.sequence; } process.stdin.on("keypress", _keypress) @@ -259,7 +275,7 @@ export default class Uploader { if (_consoleAction != index) return; // console.log('data',_consoleAction,' and ',index); - if (_consoleCaches[index].length >= 5000) { + if (_consoleCaches[index].length >= 2000) { _consoleCaches[index].shift(); }; _consoleCaches[index].push(dd); @@ -269,7 +285,7 @@ export default class Uploader { stream.stderr.on('data', (data: any) => { // console.log('data',_consoleAction,' and ',index); if (_consoleAction != index) return; - if (_consoleCaches[index].length >= 5000) { + if (_consoleCaches[index].length >= 2000) { _consoleCaches[index].shift(); }; _consoleCaches[index].push(data); @@ -349,7 +365,7 @@ export default class Uploader { return; } if (_consoleAction != index) return; - if (_consoleCaches[index].length >= 5000) { + if (_consoleCaches[index].length >= 2000) { _consoleCaches[index].shift(); }; _consoleCaches[index].push(data); @@ -382,6 +398,7 @@ export default class Uploader { }); let timesCloseClick = 0; + let _localRecordText = ""; let _keypress = (key: string, data: any) => { let isStop = false; for (var a = 1; a <= 9; a++) { @@ -418,6 +435,7 @@ export default class Uploader { if (isStop == true) { return; } + switch (data.sequence) { case '\u0003': // theClient.write("exit\r"); @@ -427,7 +445,14 @@ export default class Uploader { case '\u001b[B': theClient.write(data.sequence); return; + case '\r': + if (_localRecordText.includes("clear")) { + _consoleCaches[index] = []; + } + _localRecordText = ""; + break; } + _localRecordText += data.sequence; theClient.write(data.sequence); } process.stdin.on("keypress", _keypress) diff --git a/src/app/devsync/services/DevSyncService.ts b/src/app/devsync/services/DevSyncService.ts index fe0a955..2a49fec 100644 --- a/src/app/devsync/services/DevSyncService.ts +++ b/src/app/devsync/services/DevSyncService.ts @@ -425,7 +425,11 @@ const DevSyncService = BaseService.extend({ // this.uploader._consoleAction = "watch"; this.uploader.startConsole(false); for (var i = 0; i < total_tab; i++) { - this.uploader.startConsoles(i, cache_command[i], false); + if (this.uploader.getConsoleMode(i) == "local") { + this.uploader.startLocalConsoles(i, cache_command[i], false); + } else if (this.uploader.getConsoleMode(i) == "remote") { + this.uploader.startConsoles(i, cache_command[i], false); + } } this._actionMode = "devsync"; this.watcher.actionMode = this._actionMode; @@ -441,12 +445,25 @@ const DevSyncService = BaseService.extend({ case '\u001b2': console.clear(); this._readLine.close(); + process.stdin.removeListener('keypress', remoteFuncKeypress); process.stdout.write(chalk.green('Console | ') + 'Start Console' + '\r'); for (var i = 0; i < total_tab; i++) { - this.uploader.startConsoles(i, cache_command[i], false); + if (this.uploader.getConsoleMode(i) == "local") { + this.uploader.startLocalConsoles(i, cache_command[i], false); + } else if (this.uploader.getConsoleMode(i) == "remote") { + this.uploader.startConsoles(i, cache_command[i], false); + } } setTimeout(() => { - this.uploader.startConsole(true, () => { }); + this.uploader.startConsole(true, (action: string, props: any) => { + switch (action) { + case 'switch': + remoteFuncKeypress(null, props); + break; + case 'exit': + break; + } + }); this._actionMode = "console"; this.watcher.actionMode = this._actionMode; }, 1000); @@ -466,11 +483,12 @@ const DevSyncService = BaseService.extend({ process.stdin.removeListener('keypress', remoteFuncKeypress); process.stdout.write(chalk.green('Console | ') + 'Start Console' + '\r'); this.uploader.startConsole(false); + // console.log('adalah :: ', index, " :: ", this.uploader.getConsoleMode(index), " position :: ", consolePosition); for (var ib = 0; ib < total_tab; ib++) { if (ib != index) { if (this.uploader.getConsoleMode(ib) == "local") { this.uploader.startLocalConsoles(ib, cache_command[ib], false); - } else { + } else if (this.uploader.getConsoleMode(ib) == "remote") { this.uploader.startConsoles(ib, cache_command[ib], false); } } @@ -530,7 +548,7 @@ const DevSyncService = BaseService.extend({ if (cache_command[inin] != null) { if (this.uploader.getConsoleMode(inin) == "local") { excuteLocalCommand('local', inin); - } else { + } else if (this.uploader.getConsoleMode(inin) == "remote") { excuteLocalCommand('remote', inin); } break; @@ -542,7 +560,7 @@ const DevSyncService = BaseService.extend({ for (var i = 0; i < total_tab; i++) { if (this.uploader.getConsoleMode(inin) == "local") { this.uploader.startLocalConsoles(i, cache_command[i], false); - } else { + } else if (this.uploader.getConsoleMode(inin) == "remote") { this.uploader.startConsoles(i, cache_command[i], false); } } diff --git a/src/app/devsync2/services/DevRsyncService.ts b/src/app/devsync2/services/DevRsyncService.ts index e045f11..3906f9f 100644 --- a/src/app/devsync2/services/DevRsyncService.ts +++ b/src/app/devsync2/services/DevRsyncService.ts @@ -2,7 +2,7 @@ import BaseService from "@root/base/BaseService"; import { MasterDataInterface } from "@root/bootstrap/StartMasterData"; import Config, { ConfigInterface } from "../compute/Config"; import { CliInterface } from "./CliService"; -import inquirer from "inquirer"; +import inquirer from "inquirer"; import Watcher from "../compute/Watcher"; import { Uploader } from "../compute/Uploader"; import path from 'path'; @@ -533,7 +533,7 @@ const DevRsyncService = BaseService.extend({ for (var i = 0; i < total_tab; i++) { if (this.uploader.getConsoleMode(i) == "local") { this.uploader.startLocalConsoles(i, cache_command[i], false); - } else { + } else if (this.uploader.getConsoleMode(i) == "remote") { this.uploader.startConsoles(i, cache_command[i], false); } } @@ -559,7 +559,7 @@ const DevRsyncService = BaseService.extend({ for (var i = 0; i < total_tab; i++) { if (this.uploader.getConsoleMode(i) == "local") { this.uploader.startLocalConsoles(i, cache_command[i], false); - } else { + } else if (this.uploader.getConsoleMode(i) == "remote") { this.uploader.startConsoles(i, cache_command[i], false); } } @@ -591,11 +591,12 @@ const DevRsyncService = BaseService.extend({ process.stdin.removeListener('keypress', remoteFuncKeypress); process.stdout.write(chalk.green('Console | ') + 'Start Console' + '\r'); this.uploader.startConsole(false); + // console.log('adalah :: ', this.uploader.getConsoleMode(index)); for (var ib = 0; ib < total_tab; ib++) { if (ib != index) { if (this.uploader.getConsoleMode(ib) == "local") { this.uploader.startLocalConsoles(ib, cache_command[ib], false); - } else { + } else if (this.uploader.getConsoleMode(ib) == "remote") { this.uploader.startConsoles(ib, cache_command[ib], false); } } @@ -655,7 +656,7 @@ const DevRsyncService = BaseService.extend({ if (cache_command[inin] != null) { if (this.uploader.getConsoleMode(inin) == "local") { excuteLocalCommand('local', inin); - } else { + } else if (this.uploader.getConsoleMode(inin) == "remote") { excuteLocalCommand('remote', inin); } break; @@ -667,7 +668,7 @@ const DevRsyncService = BaseService.extend({ for (var i = 0; i < total_tab; i++) { if (this.uploader.getConsoleMode(inin) == "local") { this.uploader.startLocalConsoles(i, cache_command[i], false); - } else { + } else if (this.uploader.getConsoleMode(inin) == "remote") { this.uploader.startConsoles(i, cache_command[i], false); } } @@ -758,8 +759,11 @@ const DevRsyncService = BaseService.extend({ // process.stdin.off('keypress', remoteFuncKeypress); this.task.done(); - // console.clear(); - this.construct(this._cli); + console.clear(); + process.stdout.write(chalk.green('Remote | ') + 'Restarting...' + '\r'); + setTimeout(() => { + this.construct(this._cli); + }, 3000); } var closeRemote = () => { if (this._currentConf.devsync.script.remote.on_stop != "" && this._currentConf.devsync.script.remote.on_stop != null) {