summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-12-08 22:35:14 +0800
committerruki <[email protected]>2017-12-08 14:10:23 +0800
commit8df3cf8fcdbfb3e169c45880eef5e11cc1f8c075 (patch)
tree71285685abc2712e3ce51102dbb378e97c0cdfae
parent325c9ab3706736f3e5469b50325864514d2e03b1 (diff)
impl some canvas interfaces
-rw-r--r--xmake/core/sandbox/modules/import/core/ui/test.lua10
-rw-r--r--xmake/core/ui/canvas.lua24
-rw-r--r--xmake/core/ui/curses.lua6
3 files changed, 27 insertions, 13 deletions
diff --git a/xmake/core/sandbox/modules/import/core/ui/test.lua b/xmake/core/sandbox/modules/import/core/ui/test.lua
index 6985c0ba1..832a32586 100644
--- a/xmake/core/sandbox/modules/import/core/ui/test.lua
+++ b/xmake/core/sandbox/modules/import/core/ui/test.lua
@@ -34,7 +34,15 @@ function test()
log:flush()
curses.init()
- print(curses.color_pair("yellow", "red"))
+ curses.echo(false)
+ curses.cbreak(true)
+ curses.nl(false)
+ curses.map_output(true)
+ curses.map_keyboard(true)
+ if (curses.has_colors()) then curses.start_color() end
+ local attr = curses.calc_attr{ curses.color_pair("yellow", "green"), 'bold' }
+ log:printv(attr)
+ log:flush()
--[[
curses.init()
diff --git a/xmake/core/ui/canvas.lua b/xmake/core/ui/canvas.lua
index 3b538308f..6511fe127 100644
--- a/xmake/core/ui/canvas.lua
+++ b/xmake/core/ui/canvas.lua
@@ -45,8 +45,10 @@ function canvas:new(view, window)
self._window = window
assert(view and window, "cannot new canvas instance without view and window!")
- -- TODO
+ -- set the default attributes
self:attr()
+
+ -- done
return self
end
@@ -89,21 +91,23 @@ function canvas:write(str, len)
return self
end
+-- set canvas attributes
+--
+-- set attr: canvas:attr("bold")
+-- add attr: canvas:attr("bold", true)
+-- remove attr: canvas:attr("bold", false)
+--
function canvas:attr(attrs, modify)
- local w = self._window
- local apply = w.attron
- local attr = curses.calc_attr(attrs)
+ -- calculate the attributes
+ local attr = curses.calc_attr(attrs)
if modify == nil then
- w:attrset(attr)
+ self._window:attrset(attr)
elseif modify == false then
- w:attroff(attr)
+ self._window:attroff(attr)
else
- w:attron(attr)
+ self._window:attron(attr)
end
-
- apply(w, attr)
-
return self
end
diff --git a/xmake/core/ui/curses.lua b/xmake/core/ui/curses.lua
index dc3ea0d06..124797ec6 100644
--- a/xmake/core/ui/curses.lua
+++ b/xmake/core/ui/curses.lua
@@ -123,7 +123,7 @@ function curses.calc_attr(attrs)
elseif atype == 'table' then
local v = 0
local set = {}
- for _, a in pairs(attrs) do --TODO ipairs?
+ for _, a in ipairs(attrs) do
if not set[a] and a then
set[a] = true
if type(a) == 'number' then
@@ -140,6 +140,7 @@ function curses.calc_attr(attrs)
end
-- get attr from the color pair
+curses._color_pair = curses._color_pair or curses.color_pair
function curses.color_pair(fg, bg)
-- get foreground and backround color
@@ -166,8 +167,9 @@ function curses.color_pair(fg, bg)
os.raise("failed to initialize color pair (%d, %s, %s)", curses._NCOLORS, fg, bg)
end
+ -- TODO rename
-- get the color attr
- local attr = curses.color_pair(curses._NCOLORS)
+ local attr = curses._color_pair(curses._NCOLORS)
-- save to cache
colors[key] = attr