2021-01-22 17:01:39 +00:00
|
|
|
#include <hex/plugin.hpp>
|
|
|
|
|
|
|
|
#include "math_evaluator.hpp"
|
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
void registerCommandPaletteCommands() {
|
|
|
|
|
|
|
|
hex::ContentRegistry::CommandPaletteCommands::add(
|
|
|
|
hex::ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
|
2021-02-13 14:15:32 +00:00
|
|
|
"#", "hex.builtin.command.calc.desc",
|
2021-01-22 17:01:39 +00:00
|
|
|
[](auto input) {
|
|
|
|
hex::MathEvaluator evaluator;
|
|
|
|
evaluator.registerStandardVariables();
|
|
|
|
evaluator.registerStandardFunctions();
|
|
|
|
|
|
|
|
std::optional<long double> result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
result = evaluator.evaluate(input);
|
2021-02-08 18:56:04 +00:00
|
|
|
} catch (std::exception &e) {}
|
|
|
|
|
2021-01-22 17:01:39 +00:00
|
|
|
|
|
|
|
if (result.has_value())
|
|
|
|
return hex::format("#%s = %Lf", input.data(), result.value());
|
|
|
|
else
|
|
|
|
return hex::format("#%s = ???", input.data());
|
|
|
|
});
|
|
|
|
|
2021-02-08 18:56:04 +00:00
|
|
|
hex::ContentRegistry::CommandPaletteCommands::add(
|
|
|
|
hex::ContentRegistry::CommandPaletteCommands::Type::KeywordCommand,
|
2021-02-13 14:15:32 +00:00
|
|
|
"/web", "hex.builtin.command.web.desc",
|
2021-02-08 18:56:04 +00:00
|
|
|
[](auto input) {
|
2021-02-11 22:09:45 +00:00
|
|
|
return hex::format("hex.builtin.command.web.result"_lang, input.data());
|
2021-02-08 18:56:04 +00:00
|
|
|
},
|
|
|
|
[](auto input) {
|
|
|
|
hex::openWebpage(input);
|
|
|
|
});
|
|
|
|
|
2021-01-22 17:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|