This commit is contained in:
Sourabh Jain 2025-04-09 16:18:48 +05:30
parent 441c3c5752
commit 2a44c619c5
5 changed files with 51 additions and 4 deletions

View File

@ -36,6 +36,7 @@ export const CloudShellTerminalComponent: React.FC<CloudShellTerminalComponentPr
term.loadAddon(fitAddon); term.loadAddon(fitAddon);
fitAddon.fit(); // Fit the terminal to the container size
// Attach terminal to the DOM // Attach terminal to the DOM
if (terminalRef.current) { if (terminalRef.current) {
term.open(terminalRef.current); term.open(terminalRef.current);

View File

@ -19,6 +19,11 @@ import { ShellTypeHandlerFactory } from "./ShellTypes/ShellTypeFactory";
import { AttachAddon } from "./Utils/AttachAddOn"; import { AttachAddon } from "./Utils/AttachAddOn";
import { askConfirmation, wait } from "./Utils/CommonUtils"; import { askConfirmation, wait } from "./Utils/CommonUtils";
import { getNormalizedRegion } from "./Utils/RegionUtils"; import { getNormalizedRegion } from "./Utils/RegionUtils";
import {
formatErrorMessage,
formatInfoMessage,
formatWarningMessage
} from "./Utils/TerminalLogFormats";
// Constants // Constants
const DEFAULT_CLOUDSHELL_REGION = "westus"; const DEFAULT_CLOUDSHELL_REGION = "westus";
@ -36,12 +41,12 @@ export const startCloudShellTerminal =
const resolvedRegion = determineCloudShellRegion(); const resolvedRegion = determineCloudShellRegion();
// Ask for user consent for region // Ask for user consent for region
const consentGranted = await askConfirmation(terminal, "This shell might be in a different region than the database region. Do you want to proceed?"); const consentGranted = await askConfirmation(terminal, formatWarningMessage("This shell might be in a different region than the database region. Do you want to proceed?"));
if (!consentGranted) { if (!consentGranted) {
return null; // Exit if user declined return null; // Exit if user declined
} }
terminal.writeln(`Connecting to CloudShell.....`); terminal.writeln(formatInfoMessage("Connecting to CloudShell....."));
let sessionDetails: { let sessionDetails: {
socketUri?: string; socketUri?: string;
@ -52,6 +57,7 @@ export const startCloudShellTerminal =
sessionDetails = await provisionCloudShellSession(resolvedRegion, terminal); sessionDetails = await provisionCloudShellSession(resolvedRegion, terminal);
if (!sessionDetails.socketUri) { if (!sessionDetails.socketUri) {
terminal.writeln(formatErrorMessage("Failed to establish a connection. Please try again later."));
return null; return null;
} }

View File

@ -36,6 +36,6 @@ export class MongoShellHandler extends AbstractShellHandler {
} }
public getTerminalSuppressedData(): string { public getTerminalSuppressedData(): string {
return "Non-Generic MongoDB Shell"; return "Warning: Non-Genuine MongoDB Detected";
} }
} }

View File

@ -36,6 +36,6 @@ export class VCoreMongoShellHandler extends AbstractShellHandler {
} }
public getTerminalSuppressedData(): string { public getTerminalSuppressedData(): string {
return "Non-Generic MongoDB Shell"; return "Warning: Non-Genuine MongoDB Detected";
} }
} }

View File

@ -0,0 +1,40 @@
// Terminal color codes
export const TERMINAL_COLORS = {
RESET: "\x1b[0m",
BRIGHT: "\x1b[1m",
DIM: "\x1b[2m",
BLACK: "\x1b[30m",
RED: "\x1b[31m",
GREEN: "\x1b[32m",
YELLOW: "\x1b[33m",
BLUE: "\x1b[34m",
MAGENTA: "\x1b[35m",
CYAN: "\x1b[36m",
WHITE: "\x1b[37m",
BG_BLACK: "\x1b[40m",
BG_RED: "\x1b[41m",
BG_GREEN: "\x1b[42m",
BG_YELLOW: "\x1b[43m",
BG_BLUE: "\x1b[44m",
BG_MAGENTA: "\x1b[45m",
BG_CYAN: "\x1b[46m",
BG_WHITE: "\x1b[47m"
};
export const START_MARKER = `echo "START INITIALIZATION" > /dev/null`;
export const END_MARKER = `echo "END INITIALIZATION" > /dev/null`;
// Terminal message formatting functions
export const formatInfoMessage = (message: string): string =>
`${TERMINAL_COLORS.BRIGHT}${TERMINAL_COLORS.CYAN}${message}${TERMINAL_COLORS.RESET}`;
export const formatSuccessMessage = (message: string): string =>
`${TERMINAL_COLORS.BRIGHT}${TERMINAL_COLORS.GREEN}${message}${TERMINAL_COLORS.RESET}`;
export const formatWarningMessage = (message: string): string =>
`${TERMINAL_COLORS.BRIGHT}${TERMINAL_COLORS.YELLOW}${message}${TERMINAL_COLORS.RESET}`;
export const formatErrorMessage = (message: string): string =>
`${TERMINAL_COLORS.BRIGHT}${TERMINAL_COLORS.RED}${message}${TERMINAL_COLORS.RESET}`;