Skip to content

Commit

Permalink
Convert UTF-8 output to UTF-16 in Try Owl.
Browse files Browse the repository at this point in the history
Thanks to @modulovalue for the report.
  • Loading branch information
ianh committed Nov 16, 2023
1 parent 27fca39 commit 75d6bff
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions try/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
}
} else {
inESC = false;
format.push({type: "char", code: ch});
format.push({type: "utf8", code: ch});
}
}
function applyCSI()
Expand Down Expand Up @@ -354,25 +354,41 @@
var nextStyle = -1;
var text = "";
var linkTarget = "";
for (var i = 0; i < format.length; ++i) {
if (format[i].type == "char") {
var utf8 = [];
function processCommand(cmd) {
if (cmd.type == "char") {
if (nextStyle != currentStyle) {
appendStyledText(elem, text, currentStyle, linkTarget);
currentStyle = nextStyle;
text = "";
}
text += String.fromCharCode(format[i].code);
} else if (format[i].type == "style")
nextStyle = format[i].code;
else if (format[i].type == "clear-style")
text += String.fromCharCode(cmd.code);
} else if (cmd.type == "style")
nextStyle = cmd.code;
else if (cmd.type == "clear-style")
nextStyle = -1;
else if (format[i].type == "link") {
else if (cmd.type == "link") {
appendStyledText(elem, text, currentStyle, linkTarget);
currentStyle = nextStyle;
text = "";
linkTarget = format[i].target;
linkTarget = cmd.target;
}
}
function flushUTF8() {
var string = new TextDecoder().decode(new Uint8Array(utf8));
utf8 = [];
for (var i = 0; i < string.length; ++i)
processCommand({type:"char", code:string.charCodeAt(i)});
}
for (var i = 0; i < format.length; ++i) {
if (format[i].type == "utf8")
utf8.push(format[i].code);
else {
flushUTF8();
processCommand(format[i]);
}
}
flushUTF8();
appendStyledText(elem, text, currentStyle, linkTarget);
}
function appendStyledText(elem, text, styleCode, linkTarget)
Expand Down

0 comments on commit 75d6bff

Please sign in to comment.