Skip to content

Commit

Permalink
Display exec error or exit information in the UI cloud shell. (#89)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
  • Loading branch information
AndrienkoAleksandr committed Apr 7, 2020
1 parent 1d38b5a commit 5bade22
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
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

0 comments on commit 5bade22

Please sign in to comment.