From a19bdd78e8cfcbc16a3867a7b00ea59fda97266d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Sun, 14 Feb 2021 11:53:52 +0100 Subject: [PATCH] Added monarch.is_popup() (#70) --- monarch/monarch.lua | 11 +++++++++++ test/test_monarch.lua | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/monarch/monarch.lua b/monarch/monarch.lua index d6714e7..4641443 100644 --- a/monarch/monarch.lua +++ b/monarch/monarch.lua @@ -188,6 +188,17 @@ function M.is_visible(id) end +--- Check if a screen is a popup +-- @param id Screen id +-- @return true if the screen is a popup +function M.is_popup(id) + assert(id, "You must provide a screen id") + id = tohash(id) + assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id))) + return screens[id].popup +end + + local function register(id, settings) assert(id, "You must provide a screen id") id = tohash(id) diff --git a/test/test_monarch.lua b/test/test_monarch.lua index b53ad26..ec0bdb5 100644 --- a/test/test_monarch.lua +++ b/test/test_monarch.lua @@ -572,5 +572,11 @@ return function() local ok, err = monarch.post(POPUP1, "foobar") assert(not ok and err, "Expected monarch.post() to return false plus an error message") end) + + + it("should be able to check if a screen is is a popup", function() + assert(not monarch.is_popup(SCREEN1)) + assert(monarch.is_popup(POPUP1)) + end) end) end