Skip to content

Commit

Permalink
improve terminal message order
Browse files Browse the repository at this point in the history
  • Loading branch information
Pop John committed Jul 3, 2024
1 parent 8c93053 commit ea24d07
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
4 changes: 2 additions & 2 deletions backend/src/router/scriptsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ function executePythonScript(path, algorithm, args = '', type) {
let cmd;

if (type === ALGORITHM_TYPES.MULTIFLOW) {
cmd = `source "${process.env.CONDA_SH_PATH}" && cd "${process.env.MACHINE_LEARNING_CORE_PATH}/multiflow" && conda activate modelsmith && python3 -u ${algorithm} ${args}`;
cmd = `source "${process.env.CONDA_SH_PATH}" && cd "${process.env.MACHINE_LEARNING_CORE_PATH}/multiflow" && conda activate modelsmith && python3 ${algorithm} ${args}`;
pythonCmd = `python3 ${algorithm} ${args}`;
} else {
cmd = `source "${process.env.CONDA_SH_PATH}" && conda activate modelsmith && python3 -u "${scriptPath}${algorithm}" ${args}`;
cmd = `source "${process.env.CONDA_SH_PATH}" && conda activate modelsmith && python3 "${scriptPath}${algorithm}" ${args}`;
pythonCmd = `python3 "${scriptPath}${algorithm}" ${args}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ const expert: SidenavItem[] = [
icon: 'icon-Lightning',
key: PageKey.AWQ
},
{
route: 'multi-modal',
label: 'Multi-modal',
icon: 'icon-Environmental'
},
{
route: RoutesList.MODEL_SPECIALIZATION.ROOT,
label: 'Model Specialization',
icon: 'icon-MapTrifold',
key: PageKey.MODEL_SPECIALIZATION
},
{
route: 'multi-modal',
label: 'Multi-modal',
icon: 'icon-Environmental'
},

{
route: RoutesList.ALGORITHM_COMPARISON.ROOT,
label: 'Algorithm Comparison',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ export class MsTerminalComponent implements OnInit, AfterViewInit, OnDestroy {

const formattedMessage = this.formatMessageByType(message);
if (this.displayWebSocketMessages) {
formattedMessage.split('\n').forEach((line) => {
this.terminal.writeln(line);
});
this.writeToTerminal(formattedMessage);
} else {
this.messagesBuffer.push(message);
}
Expand All @@ -97,27 +95,35 @@ export class MsTerminalComponent implements OnInit, AfterViewInit, OnDestroy {
this.fitTerminalToContainer();
}

private writeToTerminal(message: string): void {
const lines = message.split('\n');
lines.forEach((line) => {
this.terminal.writeln(line);
});
}

private loadLatestMessages() {
this.terminalFacadeService.messages$.pipe(skip(1), take(1)).subscribe((messages: TerminalMessage[]) => {
messages.forEach((messageObj: TerminalMessage) => {
const formattedMessage = this.formatMessageByType(messageObj);
formattedMessage.split('\n').forEach((line) => {
this.terminal.writeln(line);
});
this.writeToTerminal(formattedMessage);
});

this.messagesBuffer.forEach((bufferedMessageObj: TerminalMessage) => {
const formattedMessage = this.formatMessageByType(bufferedMessageObj);
formattedMessage.split('\n').forEach((line) => {
this.terminal.writeln(line);
});
this.writeToTerminal(formattedMessage);
});
this.messagesBuffer = [];
this.displayWebSocketMessages = true;
});
this.terminalFacadeService.dispatch(TerminalActions.getLatestMessages());
}

private logMessageWithControlChars(message: string): void {
const visibleMessage = message.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
console.log(visibleMessage);
}

private formatMessageByType(message: TerminalMessage): string {
let colorCode = '';
switch (message.type) {
Expand All @@ -136,7 +142,14 @@ export class MsTerminalComponent implements OnInit, AfterViewInit, OnDestroy {
break;
}

return `${colorCode}${message.data}\x1b[0m`;
this.logMessageWithControlChars(message.data);

let formattedData = message.data;
if (formattedData.endsWith('\n')) {
formattedData = formattedData.slice(0, -1);
}

return `${colorCode}${formattedData}\x1b[0m`;
}

private initializeTerminal(): void {
Expand Down

0 comments on commit ea24d07

Please sign in to comment.