mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 01:11:25 +00:00
Close mongo and casssandra terminal tabs once the shells are exited (#1183)
* initial commit for closing terminal * added extra case * lint changes and hostee explorer fixes * fixed lint errors * fixed compile error * fixed review comments
This commit is contained in:
committed by
GitHub
parent
591782195d
commit
b765cae088
@@ -2,15 +2,48 @@
|
||||
* JupyterLab applications based on jupyterLab components
|
||||
*/
|
||||
import { ServerConnection, TerminalManager } from "@jupyterlab/services";
|
||||
import { IMessage } from "@jupyterlab/services/lib/terminal/terminal";
|
||||
import { Terminal } from "@jupyterlab/terminal";
|
||||
import { Panel, Widget } from "@phosphor/widgets";
|
||||
import { userContext } from "UserContext";
|
||||
|
||||
export class JupyterLabAppFactory {
|
||||
public static async createTerminalApp(serverSettings: ServerConnection.ISettings) {
|
||||
private isShellClosed: boolean;
|
||||
private onShellExited: () => void;
|
||||
private checkShellClosed: ((content: string | undefined) => boolean | undefined) | undefined;
|
||||
|
||||
constructor(closeTab: () => void) {
|
||||
this.onShellExited = closeTab;
|
||||
this.isShellClosed = false;
|
||||
this.checkShellClosed = undefined;
|
||||
|
||||
switch (userContext.apiType) {
|
||||
case "Mongo":
|
||||
this.checkShellClosed = JupyterLabAppFactory.isMongoShellClosed;
|
||||
break;
|
||||
case "Cassandra":
|
||||
this.checkShellClosed = JupyterLabAppFactory.isCassandraShellClosed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public async createTerminalApp(serverSettings: ServerConnection.ISettings) {
|
||||
const manager = new TerminalManager({
|
||||
serverSettings: serverSettings,
|
||||
});
|
||||
const session = await manager.startNew();
|
||||
session.messageReceived.connect(async (_, message: IMessage) => {
|
||||
const content = message.content && message.content[0]?.toString();
|
||||
if (this.checkShellClosed && message.type == "stdout") {
|
||||
//Close the terminal tab once the shell closed messages are received
|
||||
if (this.checkShellClosed(content)) {
|
||||
this.isShellClosed = true;
|
||||
} else if (content?.includes("cosmosuser@") && this.isShellClosed) {
|
||||
this.onShellExited();
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
const term = new Terminal(session, { theme: "dark", shutdownOnClose: true });
|
||||
|
||||
if (!term) {
|
||||
@@ -38,4 +71,12 @@ export class JupyterLabAppFactory {
|
||||
panel.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
private static isMongoShellClosed(content: string | undefined) {
|
||||
return content?.endsWith("bye\r\n") || (content?.includes("Stopped") && content?.includes("mongo --host"));
|
||||
}
|
||||
|
||||
private static isCassandraShellClosed(content: string | undefined) {
|
||||
return content == "\r\n" || (content?.includes("Stopped") && content?.includes("cqlsh"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user