Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/interpreter/src/js/hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[17669692872757955279, 11420464406527728232, 3770103091118609057, 5444526391971481782, 8889858244860485542, 5052021921702764563, 15193138787416885137, 11339769846046015954]
[17669692872757955279, 11420464406527728232, 3770103091118609057, 5444526391971481782, 8889858244860485542, 3067134038983289342, 15193138787416885137, 11339769846046015954]
2 changes: 1 addition & 1 deletion packages/interpreter/src/js/native.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/interpreter/src/js/patch_console.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 27 additions & 5 deletions packages/interpreter/src/ts/patch_console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,32 @@ export function monkeyPatchConsole(ws: WebSocket) {
const error = console.error;
const debug = console.debug;

// Helper function to strip console formatting placeholders
// Console.log uses %c for styling, but we don't want to send these to the CLI
function stripFormatting(args: any[]): any[] {
if (args.length === 0) return args;

// Check if first argument is a string with %c formatting
if (typeof args[0] === 'string' && args[0].includes('%c')) {
// Remove %c markers and their corresponding style arguments
const formatString = args[0];
const matches = formatString.match(/%c/g);
const numFormatters = matches ? matches.length : 0;

// Strip the %c markers from the format string
const strippedFormat = formatString.replace(/%c/g, '');

// Return the stripped format string and skip the style arguments
return [strippedFormat, ...args.slice(1 + numFormatters)];
}

return args;
}

console.log = function (...args: any[]) {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({
"Log": { level: "log", messages: args }
"Log": { level: "log", messages: stripFormatting(args) }
}));
}
log.apply(console, args);
Expand All @@ -19,7 +41,7 @@ export function monkeyPatchConsole(ws: WebSocket) {
console.info = function (...args: any[]) {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({
"Log": { level: "info", messages: args }
"Log": { level: "info", messages: stripFormatting(args) }
}));
}
info.apply(console, args);
Expand All @@ -28,7 +50,7 @@ export function monkeyPatchConsole(ws: WebSocket) {
console.warn = function (...args: any[]) {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({
"Log": { level: "warn", messages: args }
"Log": { level: "warn", messages: stripFormatting(args) }
}));
}
warn.apply(console, args);
Expand All @@ -37,7 +59,7 @@ export function monkeyPatchConsole(ws: WebSocket) {
console.error = function (...args: any[]) {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({
"Log": { level: "error", messages: args }
"Log": { level: "error", messages: stripFormatting(args) }
}));
}
error.apply(console, args);
Expand All @@ -46,7 +68,7 @@ export function monkeyPatchConsole(ws: WebSocket) {
console.debug = function (...args: any[]) {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({
"Log": { level: "debug", messages: args }
"Log": { level: "debug", messages: stripFormatting(args) }
}));
}
debug.apply(console, args);
Expand Down
Loading