diff options
Diffstat (limited to 'src/config/lua/ConfigManager.cpp')
| -rw-r--r-- | src/config/lua/ConfigManager.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/config/lua/ConfigManager.cpp b/src/config/lua/ConfigManager.cpp index fad187db..7819ff2e 100644 --- a/src/config/lua/ConfigManager.cpp +++ b/src/config/lua/ConfigManager.cpp @@ -631,11 +631,20 @@ void CConfigManager::addError(std::string&& str) { Notification::overlay()->addNotification(std::format("Runtime error in lua:\n{}", std::move(str)), 0, 5000, ICON_WARNING); } +void CConfigManager::addEvalIssue(const Config::SConfigError& err) { + if (!m_isEvaluating) + return; + + if (err.level == eConfigErrorLevel::WARNING || err.level == eConfigErrorLevel::INFO) + m_evalIssues.emplace_back(err); +} + std::optional<std::string> CConfigManager::eval(const std::string& code) { if (!m_lua) - return "lua state not initialized"; + return "error: lua state not initialized"; m_errors.clear(); + m_evalIssues.clear(); m_isEvaluating = true; Hyprutils::Utils::CScopeGuard x([this] { m_isEvaluating = false; }); @@ -643,30 +652,37 @@ std::optional<std::string> CConfigManager::eval(const std::string& code) { if (luaL_loadstring(m_lua, code.c_str()) != LUA_OK) { std::string err = lua_tostring(m_lua, -1); lua_pop(m_lua, 1); - return err; + return std::format("error: {}", err); } if (guardedPCall(0, 0, 0, LUA_TIMEOUT_EVAL_MS, "hyprctl eval") != LUA_OK) { std::string err = lua_tostring(m_lua, -1); lua_pop(m_lua, 1); - return err; + return std::format("error: {}", err); } - if (!m_errors.empty()) { + if (!m_errors.empty() || !m_evalIssues.empty()) { std::string out; out.reserve(256); for (size_t i = 0; i < m_errors.size(); ++i) { + out += "error: "; out += m_errors.at(i); out += "\n"; } + for (const auto& issue : m_evalIssues) { + out += std::format("{}: {}", Config::toString(issue.level), issue.message); + out += "\n"; + } + out.pop_back(); return out; } m_errors.clear(); + m_evalIssues.clear(); return std::nullopt; } |
