From 59aa52e7443ae464eea486d2c1d6f9ebe0650cc5 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 5 Jun 2023 09:45:25 +0200 Subject: [PATCH] patterns: Allow console log to be printed immediately and from format functions --- lib/external/pattern_language | 2 +- .../include/content/views/view_pattern_editor.hpp | 3 ++- .../source/content/views/view_pattern_editor.cpp | 12 ++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 9fe6b2bd4..86e4a8d4c 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 9fe6b2bd4b428f6e31473cbd83e66a5e04d4a045 +Subproject commit 86e4a8d4c0934412cf69713516a96f268f1d7e6d diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index f58ef39a6..44e8429a2 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -155,8 +155,9 @@ namespace hex::plugin::builtin { PerProvider>> m_console; PerProvider m_executionDone = true; + std::mutex m_logMutex; + PerProvider> m_lastEvaluationError; - PerProvider>> m_lastEvaluationLog; PerProvider> m_lastEvaluationOutVars; PerProvider> m_patternVariables; PerProvider> m_sections; diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 762fcdd51..6d8685125 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -220,6 +220,7 @@ namespace hex::plugin::builtin { if (ImGui::BeginChild("##console", size, true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_HorizontalScrollbar)) { ImGuiListClipper clipper; + std::scoped_lock lock(this->m_logMutex); clipper.Begin(console.size()); while (clipper.Step()) @@ -512,8 +513,6 @@ namespace hex::plugin::builtin { } if (!this->m_lastEvaluationProcessed) { - *this->m_console = this->m_lastEvaluationLog; - if (!this->m_lastEvaluationResult) { if (this->m_lastEvaluationError->has_value()) { TextEditor::ErrorMarkers errorMarkers = { @@ -689,8 +688,12 @@ namespace hex::plugin::builtin { return this->m_dangerousFunctionsAllowed == DangerousFunctionPerms::Allow; }); + runtime.setLogCallback([this](auto level, auto message) { + std::scoped_lock lock(this->m_logMutex); + this->m_console->emplace_back(level, message); + }); + ON_SCOPE_EXIT { - *this->m_lastEvaluationLog = runtime.getConsoleLog(); *this->m_lastEvaluationOutVars = runtime.getOutVariables(); *this->m_sections = runtime.getSections(); @@ -698,7 +701,8 @@ namespace hex::plugin::builtin { this->m_lastEvaluationProcessed = false; - this->m_lastEvaluationLog->emplace_back( + std::scoped_lock lock(this->m_logMutex); + this->m_console->emplace_back( pl::core::LogConsole::Level::Info, hex::format("Evaluation took {}", runtime.getLastRunningTime()) );