diff --git a/README.md b/README.md index 53ba21a..c49f748 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ TODO * Make VM and transformMultiplyLoops use a Proxied object that gives out 0 for nonexistent elements for tape and allows using [] interface * Keep a cache of compiled programs in `ircbotRun()` -* Replace non-IRC low bytes with their U+2400 versions in `ircbotRun()` * Support for other types of EOF? ### gir.html diff --git a/gir.js b/gir.js index 80893c5..5662a83 100644 --- a/gir.js +++ b/gir.js @@ -937,6 +937,18 @@ function ircbotRun(program, input, maxCycles = 400000) { let result = runVM(vm, maxCycles); let output = decodeUTF8(result.state.output); + // Replace all characters < 0x20 except for IRC formatting codes + // with their graphical representations at U+24xx + let formattingChars = [0x02, 0x03, 0x0f, 0x12, 0x15]; + output = Array.from(output).map(c => { + let codePoint = c.codePointAt(0); + if(codePoint < 0x20 && !formattingChars.includes(codePoint)) { + return String.fromCodePoint(0x2400 + codePoint); + } else { + return c; + } + }).join(''); + // Did we run into maxCycles? let executedTooLong = maxCycles != null && result.cycles >= maxCycles;