Skip to content

Commit

Permalink
web: Add 'base' command to REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddiM8 committed Jan 24, 2023
1 parent 021eb8f commit 94571bb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion web/src/KalkCalculator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
let inputElement: HTMLTextAreaElement;
let highlightedTextElement: HTMLElement;
let ignoreNextInput = false;
let currentBase = 10;
enum HighlightType {
Output,
Expand Down Expand Up @@ -100,6 +101,7 @@
try {
if (!kalkContext) kalkContext = new kalk.Context();
const result = kalkContext.evaluate(input.replaceAll(/\s+/g, " "));
result?.setRadix(currentBase);
return [result?.toPrettyString(), true];
} catch (err) {
Expand Down Expand Up @@ -153,12 +155,14 @@
output = `<a style="color: ${linkcolor}"
href="https://kalker.xyz/#usage"
target="blank">Link to usage guide</a>`;
} else if (/base\s\d\d?/.test(input.trim())) {
currentBase = +input.trim().slice(5);
} else if (input.trim() == "clear") {
outputLines = [];
setText("");
return;
} else {
const [result, success] = calculate(kalk, input);
let [result, success] = calculate(kalk, input);
output = success
? highlight(result, HighlightType.Output)[0]
Expand Down

0 comments on commit 94571bb

Please sign in to comment.