From ade354660faefb78ffa0ec89c97953a8ae0e7197 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Tue, 26 Mar 2019 02:10:10 -0400 Subject: [PATCH] notifications anchor option --- sys/apis/ui.lua | 5 ++++- sys/apis/ui/components/Notification.lua | 24 +++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/sys/apis/ui.lua b/sys/apis/ui.lua index 2646a34..5a3b257 100644 --- a/sys/apis/ui.lua +++ b/sys/apis/ui.lua @@ -374,8 +374,11 @@ function Manager:mergeProperties(obj, args) end function Manager:pullEvents(...) - Event.pullEvents(...) + local s, m = pcall(Event.pullEvents, ...) self.term:reset() + if not s and m then + error(m, -1) + end end function Manager:exitPullEvents() diff --git a/sys/apis/ui/components/Notification.lua b/sys/apis/ui/components/Notification.lua index ada09cb..19d0e86 100644 --- a/sys/apis/ui/components/Notification.lua +++ b/sys/apis/ui/components/Notification.lua @@ -13,6 +13,7 @@ UI.Notification.defaults = { closeInd = '\215', height = 3, timeout = 3, + anchor = 'bottom', } function UI.Notification:draw() end @@ -27,7 +28,7 @@ function UI.Notification:error(value, timeout) end function UI.Notification:info(value, timeout) - self.backgroundColor = colors.gray + self.backgroundColor = colors.lightGray self:display(value, timeout) end @@ -50,29 +51,34 @@ function UI.Notification:cancel() end function UI.Notification:display(value, timeout) + self:cancel() self.enabled = true local lines = Util.wordWrap(value, self.width - 3) self.height = #lines - self.y = self.parent.height - self.height + 1 - if self.canvas then - self.canvas:removeLayer() - end - self.canvas = self:addLayer(self.backgroundColor, self.textColor) - self:addTransition('expandUp', { ticks = self.height }) + if self.anchor == 'bottom' then + self.y = self.parent.height - self.height + 1 + self.canvas = self:addLayer(self.backgroundColor, self.textColor) + self:addTransition('expandUp', { ticks = self.height }) + else + self.canvas = self:addLayer(self.backgroundColor, self.textColor) + self.y = 1 + end self.canvas:setVisible(true) self:clear() for k,v in pairs(lines) do self:write(2, k, v) end - self:write(self.width, 1, self.closeInd) timeout = timeout or self.timeout if timeout > 0 then - self.timer = Event.onTimeout(timeout or self.timeout, function() + self.timer = Event.onTimeout(timeout, function() self:cancel() self:sync() end) + else + self:write(self.width, 1, self.closeInd) + self:sync() end end