From 94571bb850cfd3c986849f2d6a0a5eb1864b333b Mon Sep 17 00:00:00 2001 From: PaddiM8 Date: Tue, 24 Jan 2023 19:48:40 +0100 Subject: [PATCH] web: Add 'base' command to REPL --- web/src/KalkCalculator.svelte | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/src/KalkCalculator.svelte b/web/src/KalkCalculator.svelte index 332b276..2d19613 100644 --- a/web/src/KalkCalculator.svelte +++ b/web/src/KalkCalculator.svelte @@ -46,6 +46,7 @@ let inputElement: HTMLTextAreaElement; let highlightedTextElement: HTMLElement; let ignoreNextInput = false; + let currentBase = 10; enum HighlightType { Output, @@ -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) { @@ -153,12 +155,14 @@ output = `Link to usage guide`; + } 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]