From 4f7dd21b7fa60d44440236569630c99fe80aec07 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 30 Aug 2024 12:18:08 -0400 Subject: [PATCH] chore: add actual z/os behavior :yum: Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/zowe-explorer/l10n/bundle.l10n.json | 7 ++- packages/zowe-explorer/l10n/poeditor.json | 2 +- .../src/commands/MvsCommandHandler.ts | 5 +- .../src/commands/TsoCommandHandler.ts | 2 +- .../src/commands/UnixCommandHandler.ts | 8 ++- .../src/commands/ZoweCommandProvider.ts | 59 +++++++++++-------- .../zowe-explorer/src/tools/ZoweTerminal.ts | 47 ++++++++------- 7 files changed, 77 insertions(+), 53 deletions(-) diff --git a/packages/zowe-explorer/l10n/bundle.l10n.json b/packages/zowe-explorer/l10n/bundle.l10n.json index 3814278b17..e7d89acc6e 100644 --- a/packages/zowe-explorer/l10n/bundle.l10n.json +++ b/packages/zowe-explorer/l10n/bundle.l10n.json @@ -1034,6 +1034,12 @@ "All jobs": "All jobs", "Ascending": "Ascending", "Descending": "Descending", + "Welcome to the integrated terminal for: {0}/Terminal Name": { + "message": "Welcome to the integrated terminal for: {0}", + "comment": [ + "Terminal Name" + ] + }, "Profile is invalid": "Profile is invalid", "Issuing commands is not supported for this profile type, {0}./Profile type": { "message": "Issuing commands is not supported for this profile type, {0}.", @@ -1096,7 +1102,6 @@ "Zowe TSO Command": "Zowe TSO Command", "Account Number": "Account Number", "Enter the account number for the TSO connection.": "Enter the account number for the TSO connection.", - "Operation Cancelled.": "Operation Cancelled.", "MVS command submitted.": "MVS command submitted.", "$(plus) Create a new MVS command": "$(plus) Create a new MVS command", "Select an MVS profile for this command": "Select an MVS profile for this command", diff --git a/packages/zowe-explorer/l10n/poeditor.json b/packages/zowe-explorer/l10n/poeditor.json index b005cfab02..e8561088f8 100644 --- a/packages/zowe-explorer/l10n/poeditor.json +++ b/packages/zowe-explorer/l10n/poeditor.json @@ -854,6 +854,7 @@ "All jobs": "", "Ascending": "", "Descending": "", + "Welcome to the integrated terminal for: {0}": "", "Profile is invalid": "", "Issuing commands is not supported for this profile type, {0}.": "", "Issuing UNIX commands is not supported for this profile type, {0}.": "", @@ -880,7 +881,6 @@ "Zowe TSO Command": "", "Account Number": "", "Enter the account number for the TSO connection.": "", - "Operation Cancelled.": "", "MVS command submitted.": "", "$(plus) Create a new MVS command": "", "Select an MVS profile for this command": "", diff --git a/packages/zowe-explorer/src/commands/MvsCommandHandler.ts b/packages/zowe-explorer/src/commands/MvsCommandHandler.ts index 458aac46a7..975e27ea8f 100644 --- a/packages/zowe-explorer/src/commands/MvsCommandHandler.ts +++ b/packages/zowe-explorer/src/commands/MvsCommandHandler.ts @@ -92,11 +92,10 @@ export class MvsCommandHandler extends ZoweCommandProvider { if (this.profileInstance.validProfile !== Validation.ValidationType.INVALID) { const commandApi = ZoweExplorerApiRegister.getInstance().getCommandApi(profile); if (commandApi) { - let command1: string = command; if (!command) { - command1 = await this.getQuickPick([session && session.ISession ? session.ISession.hostname : "unknown"]); + command = await this.getQuickPick([session && session.ISession ? session.ISession.hostname : "unknown"]); } - await this.issueCommand(profile, command1); + await this.issueCommand(profile, command); } else { Gui.errorMessage(vscode.l10n.t("Profile is invalid")); return; diff --git a/packages/zowe-explorer/src/commands/TsoCommandHandler.ts b/packages/zowe-explorer/src/commands/TsoCommandHandler.ts index db5a67bc98..af526e4fd6 100644 --- a/packages/zowe-explorer/src/commands/TsoCommandHandler.ts +++ b/packages/zowe-explorer/src/commands/TsoCommandHandler.ts @@ -182,7 +182,7 @@ export class TsoCommandHandler extends ZoweCommandProvider { }; tsoParms.account = await Gui.showInputBox(InputBoxOptions); if (!tsoParms.account) { - Gui.showMessage(vscode.l10n.t("Operation Cancelled.")); + Gui.showMessage(this.operationCancelled); return; } } diff --git a/packages/zowe-explorer/src/commands/UnixCommandHandler.ts b/packages/zowe-explorer/src/commands/UnixCommandHandler.ts index b16606a7d9..e595ad89a9 100644 --- a/packages/zowe-explorer/src/commands/UnixCommandHandler.ts +++ b/packages/zowe-explorer/src/commands/UnixCommandHandler.ts @@ -41,7 +41,6 @@ export class UnixCommandHandler extends ZoweCommandProvider { private static instance: UnixCommandHandler; private nodeProfile: imperative.IProfileLoaded = undefined; private unixCmdMsgs = { - opCancelledMsg: vscode.l10n.t("Operation Cancelled"), issueCmdNotSupportedMsg: (profileType: string) => vscode.l10n.t({ message: "Issuing commands is not supported for this profile type, {0}.", @@ -134,6 +133,9 @@ export class UnixCommandHandler extends ZoweCommandProvider { if (this.isSshRequiredForProf) { await this.getSshProfile(); + if (!this.sshProfile) { + return; + } const cmdArgs: imperative.ICommandArguments = this.getSshCmdArgs(this.sshProfile.profile); // create the ssh session @@ -162,8 +164,8 @@ export class UnixCommandHandler extends ZoweCommandProvider { } if (this.sshCwd == undefined) { this.nodeProfile = undefined; - ZoweLogger.info(this.unixCmdMsgs.opCancelledMsg); - Gui.showMessage(this.unixCmdMsgs.opCancelledMsg); + ZoweLogger.info(this.operationCancelled); + Gui.showMessage(this.operationCancelled); return; } } diff --git a/packages/zowe-explorer/src/commands/ZoweCommandProvider.ts b/packages/zowe-explorer/src/commands/ZoweCommandProvider.ts index 5b518ed0d9..d88e907976 100644 --- a/packages/zowe-explorer/src/commands/ZoweCommandProvider.ts +++ b/packages/zowe-explorer/src/commands/ZoweCommandProvider.ts @@ -37,7 +37,7 @@ export interface ICommandProviderDialogs { export abstract class ZoweCommandProvider { // eslint-disable-next-line no-magic-numbers private static readonly totalFilters: number = 10; - private readonly operationCancelled: string = vscode.l10n.t("Operation cancelled"); + protected readonly operationCancelled: string = vscode.l10n.t("Operation cancelled"); public profileInstance: Profiles; public history: ZowePersistentFilters; // Event Emitters used to notify subscribers that the refresh event has fired @@ -50,18 +50,13 @@ export abstract class ZoweCommandProvider { public terminal: vscode.Terminal; public pseudoTerminal: ZoweTerminal; - public constructor(terminalName: string) { + public constructor(protected terminalName: string) { this.history = new ZowePersistentFilters(PersistenceSchemaEnum.Commands, ZoweCommandProvider.totalFilters); this.profileInstance = Profiles.getInstance(); this.useIntegratedTerminals = SettingsConfig.getDirectValue(Constants.SETTINGS_COMMANDS_INTEGRATED_TERMINALS) ?? true; - if (this.useIntegratedTerminals) { - // this.pseudoTerminal = new CustomPseudoterminal(); - this.pseudoTerminal = new ZoweTerminal(terminalName); - this.terminal = vscode.window.createTerminal({ name: terminalName, pty: this.pseudoTerminal }); - } else { - // Initialize terminal or output channel - this.outputChannel = Gui.createOutputChannel(terminalName); + if (!this.useIntegratedTerminals) { + this.outputChannel = Gui.createOutputChannel(this.terminalName); } } @@ -69,23 +64,41 @@ export abstract class ZoweCommandProvider { public abstract runCommand(profile: imperative.IProfileLoaded, command: string): Promise; public async issueCommand(profile: imperative.IProfileLoaded, command: string): Promise { - ZoweLogger.trace("MvsCommandHandler.issueCommand called."); + ZoweLogger.trace("ZoweCommandProvider.issueCommand called."); + if (profile == null || command == null) { + return; + } try { - if (!this.useIntegratedTerminals) this.outputChannel.appendLine(this.formatCommandLine(command)); - - const response = await Gui.withProgress( - { - location: vscode.ProgressLocation.Notification, - title: this.dialogs.commandSubmitted, - }, - () => { - return this.runCommand(profile, command); - } - ); if (this.useIntegratedTerminals) { - // this.terminal.sendText(response); - this.terminal.show(true); + this.pseudoTerminal = new ZoweTerminal( + this.terminalName, + async (command: string): Promise => { + this.history.addSearchHistory(command); + return this.runCommand(profile, command); + }, + { + message: vscode.l10n.t({ + message: "Welcome to the integrated terminal for: {0}", + args: [this.terminalName], + comment: ["Terminal Name"], + }), + history: [...this.history.getSearchHistory()].reverse() ?? [], + startup: command, + } + ); + this.terminal = vscode.window.createTerminal({ name: this.terminalName, pty: this.pseudoTerminal }); + this.terminal.show(); } else { + this.outputChannel.appendLine(this.formatCommandLine(command)); + const response = await Gui.withProgress( + { + location: vscode.ProgressLocation.Notification, + title: this.dialogs.commandSubmitted, + }, + () => { + return this.runCommand(profile, command); + } + ); this.outputChannel.appendLine(response); this.outputChannel.show(true); } diff --git a/packages/zowe-explorer/src/tools/ZoweTerminal.ts b/packages/zowe-explorer/src/tools/ZoweTerminal.ts index 2b9eea1836..10959e631e 100644 --- a/packages/zowe-explorer/src/tools/ZoweTerminal.ts +++ b/packages/zowe-explorer/src/tools/ZoweTerminal.ts @@ -27,11 +27,17 @@ export class ZoweTerminal implements vscode.Pseudoterminal { BACKSPACE: "\x7f", }; - public constructor(terminalName: string, message?: string, history: string[] = []) { + public constructor( + terminalName: string, + private processCmd: (cmd: string) => Promise, + options?: { startup?: string; message?: string; history?: string[] } + ) { this.mTerminalName = terminalName; - this.mMessage = message ?? `Welcome to the ${this.mTerminalName} Terminal!`; - this.mHistory = history; - this.historyIndex = history.length; + this.mMessage = options?.message ?? `Welcome to the ${this.mTerminalName} Terminal!`; + this.mHistory = options?.history ?? []; + this.historyIndex = this.mHistory.length; + this.command = options?.startup ?? ""; + this.cursorPosition = this.command.length; } private mMessage: string; @@ -57,8 +63,8 @@ export class ZoweTerminal implements vscode.Pseudoterminal { this.writeLine(this.mMessage); } - protected command: string = ""; - protected cursorPosition = 0; + protected command: string; + protected cursorPosition: number; public onDidWrite: vscode.Event = this.writeEmitter.event; @@ -68,6 +74,10 @@ export class ZoweTerminal implements vscode.Pseudoterminal { // Start is called when the terminal is opened public open(initialDimensions: vscode.TerminalDimensions | undefined): void { this.writeLine(this.mMessage); + if (this.command.length > 0) { + this.write(this.command); + this.handleInput(ZoweTerminal.Keys.ENTER); + } } // Close is called when the terminal is closed @@ -76,8 +86,7 @@ export class ZoweTerminal implements vscode.Pseudoterminal { } // Handle input from the terminal - public handleInput(data: string): void { - console.log(data, this.historyIndex, this.mHistory); + public async handleInput(data: string): Promise { if (data === ZoweTerminal.Keys.UP) { this.historyIndex = Math.max(0, this.historyIndex - 1); this.command = this.mHistory[this.historyIndex] ?? ""; @@ -122,8 +131,6 @@ export class ZoweTerminal implements vscode.Pseudoterminal { this.command = tmp.join(""); this.cursorPosition = Math.max(0, this.cursorPosition - 1); - - // this.refreshCmd(); return; } if (data === ZoweTerminal.Keys.ENTER) { @@ -132,19 +139,17 @@ export class ZoweTerminal implements vscode.Pseudoterminal { this.write(ZoweTerminal.Keys.EMPTY_LINE); return; } - if (this.command === "hello") { - this.writeLine("Hello there!"); - } else if (this.command === ":clear") { - this.clear(); - } else if (this.command === "date") { - this.writeLine(`Current date: ${new Date().toLocaleString()}`); - } else if (this.command === ":exit") { - this.writeLine("Exiting..."); - this.closeEmitter.fire(); + + if (this.command[0] === ":") { + if (this.command === ":clear") { + this.clear(); + } else if (this.command === ":exit") { + this.closeEmitter.fire(); + } } else { - this.writeLine(`Unknown command: ${this.command}`); + const output = await this.processCmd(this.command); + this.writeLine(output.trim().split("\n").join("\r\n")); } - this.mHistory.push(this.command); this.historyIndex = this.mHistory.length; this.cursorPosition = 0;