sys: Fixed open webpage command, added run command

This commit is contained in:
WerWolv 2021-08-22 21:43:31 +02:00
parent 08ca626b2f
commit d3a227d0bc
4 changed files with 34 additions and 6 deletions

View File

@ -37,6 +37,16 @@ namespace hex::plugin::builtin {
hex::openWebpage(input); hex::openWebpage(input);
}); });
hex::ContentRegistry::CommandPaletteCommands::add(
hex::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);
});
} }
} }

View File

@ -181,7 +181,8 @@ namespace hex {
std::string toByteString(u64 bytes); std::string toByteString(u64 bytes);
std::string makePrintable(char c); std::string makePrintable(char c);
void openWebpage(std::string_view url); void runCommand(const std::string &command);
void openWebpage(std::string url);
template<typename ... Args> template<typename ... Args>
inline std::string format(std::string_view format, Args ... args) { inline std::string format(std::string_view format, Args ... args) {

View File

@ -175,14 +175,31 @@ namespace hex {
return result; return result;
} }
void openWebpage(std::string_view url) { void runCommand(const std::string &command) {
#if defined(OS_WINDOWS) #if defined(OS_WINDOWS)
system(hex::format("start {0}", url.data()).c_str()); system(hex::format("start {0}", command).c_str());
#elif defined(OS_MACOS) #elif defined(OS_MACOS)
system(hex::format("open {0}", url.data()).c_str()); system(hex::format("open {0}", command).c_str());
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
system(hex::format("xdg-open {0}", url.data()).c_str()); system(hex::format("xdg-open {0}", command).c_str());
#else
#warning "Unknown OS, can't open webpages"
#endif
}
void openWebpage(std::string url) {
if (!url.starts_with("http://") && !url.starts_with("https://"))
url = "https://" + url;
#if defined(OS_WINDOWS)
system(hex::format("start {0}", url).c_str());
#elif defined(OS_MACOS)
system(hex::format("open {0}", url).c_str());
#elif defined(OS_LINUX)
system(hex::format("xdg-open {0}", url).c_str());
#else #else
#warning "Unknown OS, can't open webpages" #warning "Unknown OS, can't open webpages"
#endif #endif

View File

@ -22,7 +22,7 @@ namespace hex {
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
ImGui::PushItemWidth(-1); ImGui::PushItemWidth(-1);
if (ImGui::InputText("##nolabel", this->m_commandBuffer.data(), this->m_commandBuffer.size(), ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_EnterReturnsTrue, if (ImGui::InputText("##command_input", this->m_commandBuffer.data(), this->m_commandBuffer.size(), ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_EnterReturnsTrue,
[](ImGuiInputTextCallbackData *callbackData) -> int { [](ImGuiInputTextCallbackData *callbackData) -> int {
auto _this = static_cast<ViewCommandPalette*>(callbackData->UserData); auto _this = static_cast<ViewCommandPalette*>(callbackData->UserData);
_this->m_lastResults = _this->getCommandResults(callbackData->Buf); _this->m_lastResults = _this->getCommandResults(callbackData->Buf);