Skip to content

Commit

Permalink
chore: add actual z/os behavior 😋
Browse files Browse the repository at this point in the history
Signed-off-by: zFernand0 <[email protected]>
  • Loading branch information
zFernand0 committed Oct 9, 2024
1 parent d3b5975 commit 4f7dd21
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 53 deletions.
7 changes: 6 additions & 1 deletion packages/zowe-explorer/l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}.",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/l10n/poeditor.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}.": "",
Expand All @@ -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": "",
Expand Down
5 changes: 2 additions & 3 deletions packages/zowe-explorer/src/commands/MvsCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/src/commands/TsoCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/zowe-explorer/src/commands/UnixCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}.",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
59 changes: 36 additions & 23 deletions packages/zowe-explorer/src/commands/ZoweCommandProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,42 +50,55 @@ 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);
}
}

public abstract formatCommandLine(command: string): string;
public abstract runCommand(profile: imperative.IProfileLoaded, command: string): Promise<string>;

public async issueCommand(profile: imperative.IProfileLoaded, command: string): Promise<void> {
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<string> => {
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);
}
Expand Down
47 changes: 26 additions & 21 deletions packages/zowe-explorer/src/tools/ZoweTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>,
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;
Expand All @@ -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<string> = this.writeEmitter.event;

Expand All @@ -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
Expand All @@ -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<void> {
if (data === ZoweTerminal.Keys.UP) {
this.historyIndex = Math.max(0, this.historyIndex - 1);
this.command = this.mHistory[this.historyIndex] ?? "";
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 4f7dd21

Please sign in to comment.