diff --git a/kalk_web/public/index.html b/kalk_web/public/index.html index f166422..c1505b1 100644 --- a/kalk_web/public/index.html +++ b/kalk_web/public/index.html @@ -16,6 +16,10 @@ background-color: #212121; } + .hint { + color: #9c9c9c; + } + .calculator { width: 850px; height: 350px; @@ -33,7 +37,12 @@
- + + kalk + + Type 'help' for instructions. + +
diff --git a/kalk_web/src/KalkCalculator.svelte b/kalk_web/src/KalkCalculator.svelte index 7bf71c9..d1e8f11 100644 --- a/kalk_web/src/KalkCalculator.svelte +++ b/kalk_web/src/KalkCalculator.svelte @@ -26,20 +26,20 @@ function calculate( kalk: Kalk, input: string - ): [result: string, error: string] { + ): [result: string, success: boolean] { try { if (!kalkContext) kalkContext = new kalk.Context(); const result = kalkContext.evaluate(input) ?? ""; if (result) { const sciNot = result.toScientificNotation(); if (sciNot.exponent > 7 || sciNot.exponent < -6) { - return [sciNot.toString(), null]; + return [sciNot.toString(), true]; } } - return [result.toString(), null]; + return [result?.toString(), true]; } catch (err) { - return [undefined, err]; + return [err, false]; } } @@ -55,10 +55,10 @@ href="https://kalk.netlify.app/#usage" target="blank">Link to usage guide`; } else { - const [result, err] = calculate(kalk, input); - output = - highlight(result)[0] ?? - `${err}`; + const [result, success] = calculate(kalk, input); + output = success + ? highlight(result)[0] + : `${result}`; } outputLines = output @@ -178,6 +178,7 @@ } function highlight(input: string): [string, number] { + if (!input) return ["", 0]; let result = input; let offset = 0; result = result.replaceAll(