2021-08-29 12:18:45 +00:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-22 17:01:39 +00:00
|
|
|
|
2022-02-01 17:09:40 +00:00
|
|
|
#include <hex/api/localization.hpp>
|
2021-09-08 13:18:24 +00:00
|
|
|
|
2021-08-29 20:15:18 +00:00
|
|
|
#include <hex/helpers/utils.hpp>
|
|
|
|
#include <hex/helpers/fmt.hpp>
|
|
|
|
|
2021-01-22 17:01:39 +00:00
|
|
|
#include "math_evaluator.hpp"
|
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
void registerCommandPaletteCommands() {
|
|
|
|
|
2021-08-29 12:18:45 +00:00
|
|
|
ContentRegistry::CommandPaletteCommands::add(
|
2022-01-24 19:53:17 +00:00
|
|
|
ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
|
|
|
|
"#",
|
|
|
|
"hex.builtin.command.calc.desc",
|
|
|
|
[](auto input) {
|
2022-05-27 18:42:07 +00:00
|
|
|
hex::MathEvaluator<long double> evaluator;
|
2022-01-24 19:53:17 +00:00
|
|
|
evaluator.registerStandardVariables();
|
|
|
|
evaluator.registerStandardFunctions();
|
2021-01-22 17:01:39 +00:00
|
|
|
|
2022-01-24 19:53:17 +00:00
|
|
|
std::optional<long double> result;
|
2021-01-22 17:01:39 +00:00
|
|
|
|
2022-05-27 18:42:07 +00:00
|
|
|
result = evaluator.evaluate(input);
|
2022-01-24 19:53:17 +00:00
|
|
|
if (result.has_value())
|
|
|
|
return hex::format("#{0} = {1}", input.data(), result.value());
|
2022-05-27 18:42:07 +00:00
|
|
|
else if (evaluator.hasError())
|
|
|
|
return hex::format("Error: {}", *evaluator.getLastError());
|
2022-01-24 19:53:17 +00:00
|
|
|
else
|
|
|
|
return std::string("???");
|
|
|
|
});
|
2021-01-22 17:01:39 +00:00
|
|
|
|
2021-08-29 12:18:45 +00:00
|
|
|
ContentRegistry::CommandPaletteCommands::add(
|
2022-01-24 19:53:17 +00:00
|
|
|
ContentRegistry::CommandPaletteCommands::Type::KeywordCommand,
|
|
|
|
"/web",
|
|
|
|
"hex.builtin.command.web.desc",
|
|
|
|
[](auto input) {
|
|
|
|
return hex::format("hex.builtin.command.web.result"_lang, input.data());
|
|
|
|
},
|
|
|
|
[](auto input) {
|
|
|
|
hex::openWebpage(input);
|
|
|
|
});
|
2021-02-08 18:56:04 +00:00
|
|
|
|
2021-08-29 12:18:45 +00:00
|
|
|
ContentRegistry::CommandPaletteCommands::add(
|
2022-01-24 19:53:17 +00:00
|
|
|
ContentRegistry::CommandPaletteCommands::Type::SymbolCommand,
|
|
|
|
"$",
|
|
|
|
"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 17:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|