Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display exec error or exit information in the UI cloud shell. #89

Merged
merged 1 commit into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cloud-shell/src/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2020 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

export namespace ANSIControlSequences {
export const RESET_COLOR = '\u001b[0m'
export const RED_COLOR = '\u001b[31m'
export const GREEN_COLOR = '\u001b[32m'
}
15 changes: 13 additions & 2 deletions cloud-shell/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import { CloudShellTerminal, TerminalHandler } from "./terminal";
import { JsonRpcConnection } from "./json-rpc-connection";
import { GenericNotificationHandler } from "vscode-jsonrpc";
import { MachineExec } from "./terminal-protocol";
import { MachineExec, EXIT_METHOD, ERROR_METHOD, ExecExitEvent, ExecErrorEvent } from "./terminal-protocol";
import { NotificationType } from 'vscode-ws-jsonrpc';
import { ANSIControlSequences as CS } from './const';

const terminalElem = document.getElementById('terminal-container');

Expand All @@ -33,7 +35,7 @@ rpcConnecton.create().then(connection => {
const exec: MachineExec = {
tty: true,
cols: terminal.cols,
rows: terminal.rows,
rows: terminal.rows
};

connection.sendRequest<{}>('create', exec).then((value: {}) => {
Expand Down Expand Up @@ -67,6 +69,15 @@ rpcConnecton.create().then(connection => {
}
});
});
const exitNotification = new NotificationType<ExecExitEvent, void>(EXIT_METHOD);
connection.onNotification(exitNotification, (event: ExecExitEvent) => {
terminal.sendLine(CS.GREEN_COLOR + "Process completed." + CS.RESET_COLOR)
});

const errorNotification = new NotificationType<ExecErrorEvent, void>(ERROR_METHOD);
connection.onNotification(errorNotification, (event: ExecErrorEvent) => {
terminal.sendLine(CS.RED_COLOR + 'Failed to create terminal. Error: ' + event.stack + CS.RESET_COLOR)
});
}).catch(err => {
console.log('Fatal. Unable to connect to container.', err);
})
13 changes: 13 additions & 0 deletions cloud-shell/src/terminal-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Red Hat, Inc. - initial API and implementation
*/

export const EXIT_METHOD: string = 'onExecExit';
export const ERROR_METHOD: string = 'onExecError';

export interface MachineIdentifier {
machineName: string,
workspaceId: string
Expand All @@ -22,6 +25,16 @@ export interface MachineExec {
id?: number
}

export interface ExecExitEvent {
id: number;
code: number;
}

export interface ExecErrorEvent {
id: number;
stack: string;
}

export interface IdParam {
id: number
}
Expand Down