diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-01-15 15:45:20 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-01-15 15:45:20 +1100 |
| commit | 47aa362b888259954214952f675e0cf93b5f8941 (patch) | |
| tree | b4c9ab1284fc2eb4fdbdf23dc11215aac588c58a | |
| parent | tooltip: add namespace prefix (diff) | |
| download | caelestia-shell-47aa362b888259954214952f675e0cf93b5f8941.tar.gz caelestia-shell-47aa362b888259954214952f675e0cf93b5f8941.tar.bz2 caelestia-shell-47aa362b888259954214952f675e0cf93b5f8941.zip | |
launcher: math derive short form + help
| -rw-r--r-- | modules/launcher.tsx | 4 | ||||
| -rw-r--r-- | services/math.ts | 16 |
2 files changed, 13 insertions, 7 deletions
diff --git a/modules/launcher.tsx b/modules/launcher.tsx index a35f85a..a15052b 100644 --- a/modules/launcher.tsx +++ b/modules/launcher.tsx @@ -121,9 +121,9 @@ const Result = ({ <button className="result" cursor="pointer" onClicked={onClicked}> <box> {icon && Astal.Icon.lookup_icon(icon) ? ( - <icon className="icon" icon={icon} /> + <icon valign={Gtk.Align.START} className="icon" icon={icon} /> ) : ( - <label className="icon" label={materialIcon} /> + <label valign={Gtk.Align.START} className="icon" label={materialIcon} /> )} {sublabel ? ( <box vertical valign={Gtk.Align.CENTER} className="has-sublabel"> diff --git a/services/math.ts b/services/math.ts index 2c7fabd..c66798c 100644 --- a/services/math.ts +++ b/services/math.ts @@ -95,7 +95,12 @@ export default class Math extends GObject.Object { let result: string, icon: string; try { - if (equation.includes("=")) { + if (equation.startsWith("help")) { + equation = "Help"; + result = + "This is a calculator powered by Math.js.\nAvailable functions:\n\thelp: show help\n\tclear: clear history\n\t<x> = <equation>: sets <x> to <equation>\n\tsimplify <equation>: simplifies <equation>\n\tderive <x> <equation>: derives <equation> with respect to <x>\n\tdd<x> <equation>: short form of derive\n\trationalize <equation>: rationalizes <equation>\n\t<equation>: evaluates <equation>\nSee the documentation for syntax and inbuilt functions."; + icon = "help"; + } else if (equation.includes("=")) { const [left, right] = equation.split("="); try { this.#variables[left.trim()] = simplify(right).toString(); @@ -107,10 +112,11 @@ export default class Math extends GObject.Object { } else if (equation.startsWith("simplify")) { result = simplify(equation.slice(8), this.#variables).toString(); icon = "function"; - } else if (equation.startsWith("derive")) { - const respectTo = equation.split(" ")[1]; - if (!respectTo) throw new Error("Format: derive <respect-to> <equation>"); - result = derivative(equation.slice(7 + respectTo.length), respectTo).toString(); + } else if (equation.startsWith("derive") || equation.startsWith("dd")) { + const isShortForm = equation.startsWith("dd"); + const respectTo = isShortForm ? equation.split(" ")[0].slice(2) : equation.split(" ")[1]; + if (!respectTo) throw new Error(`Format: ${isShortForm ? "dd" : "derive "}<respect-to> <equation>`); + result = derivative(equation.slice((isShortForm ? 2 : 7) + respectTo.length), respectTo).toString(); icon = "function"; } else if (equation.startsWith("rationalize")) { result = rationalize(equation.slice(11), this.#variables).toString(); |