2021-08-29 14:18:45 +02:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-09-08 15:18:24 +02:00
|
|
|
#include <hex/helpers/lang.hpp>
|
|
|
|
using namespace hex::lang_literals;
|
|
|
|
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
#include <hex/helpers/fmt.hpp>
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
#include "math_evaluator.hpp"
|
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
void registerCommandPaletteCommands() {
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
ContentRegistry::CommandPaletteCommands::add(
|
|
|
|
ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
|
2021-02-13 15:15:32 +01:00
|
|
|
"#", "hex.builtin.command.calc.desc",
|
2021-01-22 18:01:39 +01:00
|
|
|
[](auto input) {
|
|
|
|
hex::MathEvaluator evaluator;
|
|
|
|
evaluator.registerStandardVariables();
|
|
|
|
evaluator.registerStandardFunctions();
|
|
|
|
|
|
|
|
std::optional<long double> result;
|
|
|
|
|
|
|
|
try {
|
|
|
|
result = evaluator.evaluate(input);
|
2021-02-08 19:56:04 +01:00
|
|
|
} catch (std::exception &e) {}
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
if (result.has_value())
|
2021-10-07 16:25:59 +02:00
|
|
|
return hex::format("#{0} = {1}", input.data(), result.value());
|
2021-01-22 18:01:39 +01:00
|
|
|
else
|
2021-10-07 16:25:59 +02:00
|
|
|
return std::string("???");
|
2021-01-22 18:01:39 +01:00
|
|
|
});
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
ContentRegistry::CommandPaletteCommands::add(
|
|
|
|
ContentRegistry::CommandPaletteCommands::Type::KeywordCommand,
|
2021-02-13 15:15:32 +01:00
|
|
|
"/web", "hex.builtin.command.web.desc",
|
2021-02-08 19:56:04 +01:00
|
|
|
[](auto input) {
|
2021-02-11 23:09:45 +01:00
|
|
|
return hex::format("hex.builtin.command.web.result"_lang, input.data());
|
2021-02-08 19:56:04 +01:00
|
|
|
},
|
|
|
|
[](auto input) {
|
|
|
|
hex::openWebpage(input);
|
|
|
|
});
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
ContentRegistry::CommandPaletteCommands::add(
|
|
|
|
ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
|
2021-08-22 21:43:31 +02:00
|
|
|
"$", "hex.builtin.command.cmd.desc",
|
|
|
|
[](auto input) {
|
|
|
|
return hex::format("hex.builtin.command.cmd.result"_lang, input.data());
|
|
|
|
},
|
|
|
|
[](auto input) {
|
|
|
|
hex::runCommand(input);
|
|
|
|
});
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|