summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-12-26 22:29:04 +0800
committerruki <[email protected]>2017-12-26 08:54:29 +0800
commit603f29d146a735671c90d7430e7e5a200b749f74 (patch)
treef22615505397dc7bec9fa1b105e71a9a88cc098b
parent6d5b0370398a581f14569ea7b63d31217d4252fc (diff)
improve label
-rw-r--r--xmake/core/ui/curses.lua15
-rw-r--r--xmake/core/ui/desktop.lua2
-rw-r--r--xmake/core/ui/label.lua9
3 files changed, 15 insertions, 11 deletions
diff --git a/xmake/core/ui/curses.lua b/xmake/core/ui/curses.lua
index 37b25fae8..b856bdc40 100644
--- a/xmake/core/ui/curses.lua
+++ b/xmake/core/ui/curses.lua
@@ -107,26 +107,27 @@ end
-- calculate attr from the attributes list
--
--- local attr = curses.calc_attr("yellow")
--- local attr = curses.calc_attr{ curses.color_pair("yellow", "green"), 'bold' }
+-- local attr = curses.calc_attr("bold")
+-- local attr = curses.calc_attr{ curses.color_pair("yellow", "green"), "bold" }
--
function curses.calc_attr(attrs)
-- curses.calc_attr(curses.A_BOLD)
+ -- curses.calc_attr(curses.color_pair("yellow", "green"))
local atype = type(attrs)
- if atype == 'number' then
+ if atype == "number" then
return attrs
-- curses.calc_attr("bold")
- elseif atype == 'string' then
+ elseif atype == "string" then
return curses.attr(attrs)
- -- curses.calc_attr{ curses.color_pair("yellow", "green"), 'bold' }
- elseif atype == 'table' then
+ -- curses.calc_attr{ curses.color_pair("yellow", "green"), "bold" }
+ elseif atype == "table" then
local v = 0
local set = {}
for _, a in ipairs(attrs) do
if not set[a] and a then
set[a] = true
- if type(a) == 'number' then
+ if type(a) == "number" then
v = v + a
else
v = v + curses.attr(a)
diff --git a/xmake/core/ui/desktop.lua b/xmake/core/ui/desktop.lua
index 1de91c6a8..85b0053eb 100644
--- a/xmake/core/ui/desktop.lua
+++ b/xmake/core/ui/desktop.lua
@@ -51,7 +51,7 @@ end
function desktop:draw()
-- draw background
- view.draw(self)
+ group.draw(self)
end
-- return module
diff --git a/xmake/core/ui/label.lua b/xmake/core/ui/label.lua
index 0d25cc156..3c443ed91 100644
--- a/xmake/core/ui/label.lua
+++ b/xmake/core/ui/label.lua
@@ -54,9 +54,12 @@ function label:draw()
-- draw background
view.draw(self)
- -- draw it
- local s = string.sub(self:text(), 1, self:width()) .. string.rep(' ', self:width() - #self:text())
- self:canvas():move(0, 0):write(s)
+ -- strip text string
+ local str = self:text()
+ if str and #str > 0 then
+ str = string.sub(str, 1, self:width())
+ self:canvas():move(0, 0):write(str)
+ end
end
-- get text