Skip to content

Commit 7f24f4c

Browse files
committed
feat: outputHanzi option for ide
1 parent 26d41cd commit 7f24f4c

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/parser.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,9 @@ function hanzinize(value) {
790790
}
791791
}
792792

793-
function outputHanziWrapper(log) {
793+
function outputHanziWrapper(log, outputHanzi) {
794794
return function output(...args) {
795-
log(...args.map(i => hanzinize(i)));
795+
log(...args.map(i => (outputHanzi ? hanzinize(i) : i)));
796796
};
797797
}
798798

@@ -810,9 +810,7 @@ function evalCompiled(compiledCode, options = {}) {
810810

811811
(() => {
812812
const _console_log = console.log;
813-
if (outputHanzi) {
814-
console.log = outputHanziWrapper(output);
815-
}
813+
console.log = outputHanziWrapper(output, outputHanzi);
816814
try {
817815
if (!scoped && "window" in this) {
818816
window.eval(code);
@@ -822,7 +820,7 @@ function evalCompiled(compiledCode, options = {}) {
822820
} catch (e) {
823821
throw e;
824822
} finally {
825-
if (outputHanzi) console.log = _console_log;
823+
console.log = _console_log;
826824
}
827825
})();
828826
}

tools/make_ide.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ function main() {
136136
selr.onchange = run;
137137

138138
var hidestd = document.getElementById("hide-std");
139+
var outputHanzi = document.getElementById("output-hanzi");
139140
var outdiv = document.getElementById("out");
140141

141142
hidestd.onchange = run;
143+
outputHanzi.onchange = run;
142144

143145
function run() {
144146
highlightCode();
@@ -158,6 +160,7 @@ function main() {
158160
hljs.highlightBlock(document.getElementById("js"));
159161

160162
evalCompiled(code, {
163+
outputHanzi: outputHanzi.checked,
161164
output: (...args) => {
162165
outdiv.innerText += args.join(" ") + "\n";
163166
}
@@ -185,7 +188,19 @@ pre{tab-size: 4;}
185188
<script>${utils.catsrc()}</script>
186189
<body style="background:#272822;padding:20px;color:white;font-family:sans-serif;">
187190
<h2><i>wenyan-lang</i></h2>
188-
<table><tr><td><select id="pick-example"></select><button id="run">Run</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="auto-hl"/><small>Auto Highlight</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="hide-std" checked=""/><small>Hide Imported Code</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<small>Romanization</small><select id="pick-roman"></select></td></tr><tr><td id="in" valign="top"><div class="tbar">EDITOR</div></td><td rowspan="2" valign="top"><div class="tbar">COMPILED JAVASCRIPT</div><pre id="js"></pre></td></tr><tr><td valign="top"><div class="tbar">OUTPUT</div><pre id="out"></pre></td></tr></table>
191+
<table><tr><td>
192+
<select id="pick-example"></select><button id="run">Run</button>
193+
194+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
195+
<input type="checkbox" id="auto-hl"/><small>Auto Highlight</small>
196+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
197+
<input type="checkbox" id="hide-std" checked=""/><small>Hide Imported Code</small>
198+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
199+
<input type="checkbox" id="output-hanzi" checked=""/><small>Output Hanzi</small>
200+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
201+
<small>Romanization</small><select id="pick-roman"></select>
202+
203+
</td></tr><tr><td id="in" valign="top"><div class="tbar">EDITOR</div></td><td rowspan="2" valign="top"><div class="tbar">COMPILED JAVASCRIPT</div><pre id="js"></pre></td></tr><tr><td valign="top"><div class="tbar">OUTPUT</div><pre id="out"></pre></td></tr></table>
189204
<script>var STDLIB = ${JSON.stringify(lib)};</script>
190205
<script>var prgms = ${JSON.stringify(prgms)};</script>
191206
<script>var examplesAlias = ${JSON.stringify(examplesAlias)};</script>

0 commit comments

Comments
 (0)