From 52b7623c5237a0e1787b2172d8052449e6094b28 Mon Sep 17 00:00:00 2001 From: Rahul Yadav Date: Thu, 5 Sep 2024 00:44:54 +0530 Subject: [PATCH 1/2] fix: remove html log message parsing (#100) There is no HTML message, so parsing is not required. --- src/hooks/logActivity.hooks.ts | 3 +-- src/utility/utils.ts | 28 ---------------------------- 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/src/hooks/logActivity.hooks.ts b/src/hooks/logActivity.hooks.ts index 893369e..3f4d878 100644 --- a/src/hooks/logActivity.hooks.ts +++ b/src/hooks/logActivity.hooks.ts @@ -1,7 +1,6 @@ import { LogEntry, LogType } from '@/interfaces/log.interface'; import { logState } from '@/state/log.state'; import EventEmitter from '@/utility/eventEmitter'; -import { htmlToAnsi, isHTML } from '@/utility/utils'; import { useRecoilState } from 'recoil'; export function useLogActivity() { @@ -40,7 +39,7 @@ export function useLogActivity() { return; } const logEntry: LogEntry = { - text: isHTML(text.trim()) ? htmlToAnsi(text.trim()) : text, + text, type, timestamp: !disableTimestamp ? new Date().toISOString() : '', }; diff --git a/src/utility/utils.ts b/src/utility/utils.ts index 8cc910c..bd765ef 100644 --- a/src/utility/utils.ts +++ b/src/utility/utils.ts @@ -88,34 +88,6 @@ export const getContractURL = ( }tonviewer.com/${contractAddress}`; }; -export const htmlToAnsi = (html: string) => { - // Replace and tags with ANSI escape codes for bold and italic - html = html.replace(/(.*?)<\/b>/g, '\x1b[1m$1\x1b[22m'); // Bold - html = html.replace(/(.*?)<\/i>/g, '\x1b[3m$1\x1b[23m'); // Italic - - // Replace elements with ANSI escape codes for color - html = html.replace( - /(.*?)<\/span>/g, - (_, color, content) => { - const colorMap: Record = { - red: '\x1b[31m', - green: '\x1b[32m', - yellow: '\x1b[33m', - blue: '\x1b[34m', - reset: '\x1b[0m', - }; - return `${colorMap[color]}${content}${colorMap.reset}`; - }, - ); - - // Remove other HTML tags - html = html.replace(/<\/?[^>]+(>|$)/g, ''); - - return html; -}; - -export const isHTML = RegExp.prototype.test.bind(/(<([^>]+)>)/i); - export const getFileNameFromPath = (filePath: string): string => { const pathArray = filePath.split('/'); From 143f54a6e9114bdbfdb321303b5cfa9b3f52fe15 Mon Sep 17 00:00:00 2001 From: Rahul Yadav Date: Thu, 5 Sep 2024 17:13:28 +0530 Subject: [PATCH 2/2] fix: convert HTML logs to ANSI format (#102) --- .../workspace/BuildProject/BuildProject.tsx | 9 +++++-- src/utility/utils.ts | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/components/workspace/BuildProject/BuildProject.tsx b/src/components/workspace/BuildProject/BuildProject.tsx index 7af0c51..0936201 100644 --- a/src/components/workspace/BuildProject/BuildProject.tsx +++ b/src/components/workspace/BuildProject/BuildProject.tsx @@ -15,6 +15,7 @@ import { buildTs } from '@/utility/typescriptHelper'; import { delay, getFileExtension, + htmlToAnsi, isIncludesTypeCellOrSlice, tonHttpEndpoint, } from '@/utility/utils'; @@ -290,7 +291,9 @@ const BuildProject: FC = ({ projectId, contract, updateContract }) => { const wallet = await blockchain.treasury('user'); globalWorkspace.sandboxWallet = wallet; createLog( - `Sandbox account created. Address: ${wallet.address.toString()}`, + htmlToAnsi( + `Sandbox account created. Address: ${wallet.address.toString()}`, + ), 'info', false, ); @@ -312,7 +315,9 @@ const BuildProject: FC = ({ projectId, contract, updateContract }) => { environment: environment.toLowerCase(), }); createLog( - `Contract deployed on ${environment}
Contract address: ${_contractAddress}}`, + htmlToAnsi( + `Contract deployed on ${environment}
Contract address: ${_contractAddress}`, + ), 'success', ); diff --git a/src/utility/utils.ts b/src/utility/utils.ts index bd765ef..fff7834 100644 --- a/src/utility/utils.ts +++ b/src/utility/utils.ts @@ -88,6 +88,32 @@ export const getContractURL = ( }tonviewer.com/${contractAddress}`; }; +export const htmlToAnsi = (html: string) => { + // Replace and tags with ANSI escape codes for bold and italic + html = html.replace(/(.*?)<\/b>/g, '\x1b[1m$1\x1b[22m'); // Bold + html = html.replace(/(.*?)<\/i>/g, '\x1b[3m$1\x1b[23m'); // Italic + + // Replace elements with ANSI escape codes for color + html = html.replace( + /(.*?)<\/span>/g, + (_, color, content) => { + const colorMap: Record = { + red: '\x1b[31m', + green: '\x1b[32m', + yellow: '\x1b[33m', + blue: '\x1b[34m', + reset: '\x1b[0m', + }; + return `${colorMap[color]}${content}${colorMap.reset}`; + }, + ); + + // Remove other HTML tags + html = html.replace(/<\/?[^>]+(>|$)/g, ''); + + return html; +}; + export const getFileNameFromPath = (filePath: string): string => { const pathArray = filePath.split('/');