summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-12-14 21:00:56 +0800
committerruki <[email protected]>2017-12-14 00:05:36 +0800
commit54a0bf3c8688589708af4cc22bd7bbe8a83365d1 (patch)
treebb020ca9a376b07682282edec1051d205cb99462
parent42cc615918ee1e4cc3ce435172e9f91dc1df1086 (diff)
impl view and group tostring
-rw-r--r--xmake/core/ui/application.lua33
-rw-r--r--xmake/core/ui/desktop.lua47
-rw-r--r--xmake/core/ui/group.lua25
-rw-r--r--xmake/core/ui/menubar.lua47
-rw-r--r--xmake/core/ui/statusbar.lua47
-rw-r--r--xmake/core/ui/view.lua50
6 files changed, 234 insertions, 15 deletions
diff --git a/xmake/core/ui/application.lua b/xmake/core/ui/application.lua
index fb7063667..c2b7069a6 100644
--- a/xmake/core/ui/application.lua
+++ b/xmake/core/ui/application.lua
@@ -30,8 +30,12 @@ $Id: application.lua 18 2007-06-21 20:43:52Z tngd $
-- load modules
local os = require("base/os")
local log = require("ui/log")
+local rect = require("ui/rect")
local curses = require("ui/curses")
local program = require("ui/program")
+local desktop = require("ui/desktop")
+local menubar = require("ui/menubar")
+local statusbar = require("ui/statusbar")
-- define module
local application = application or program()
@@ -49,6 +53,11 @@ function application:init(name)
-- init program
program.init(self, name)
+ -- add menubar, statusbar and desktop
+ self:insert(self:statusbar())
+ self:insert(self:menubar())
+ self:insert(self:desktop())
+
-- trace
log:print("<application: %s>: init ok", name)
end
@@ -63,6 +72,30 @@ function application:exit()
log:flush()
end
+-- get menubar
+function application:menubar()
+ if not self._MENUBAR then
+ self._MENUBAR = menubar:new("menubar", rect{0, 0, self:width(), 1})
+ end
+ return self._MENUBAR
+end
+
+-- get desktop
+function application:desktop()
+ if not self._DESKTOP then
+ self._DESKTOP = desktop:new("desktop", rect{0, 1, self:width(), self:height() - 1})
+ end
+ return self._DESKTOP
+end
+
+-- get statusbar
+function application:statusbar()
+ if not self._STATUSBAR then
+ return statusbar:new("statusbar", rect{0, self:height() - 1, self:width(), self:height()})
+ end
+ return self._STATUSBAR
+end
+
-- run application
function application.run(name, ...)
diff --git a/xmake/core/ui/desktop.lua b/xmake/core/ui/desktop.lua
new file mode 100644
index 000000000..899053d48
--- /dev/null
+++ b/xmake/core/ui/desktop.lua
@@ -0,0 +1,47 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file desktop.lua
+--
+
+--[[ Console User Interface (cui) ]-----------------------------------------
+Author: Tiago Dionizio (tiago.dionizio AT gmail.com)
+$Id: desktop.lua 18 2007-06-21 20:43:52Z tngd $
+--------------------------------------------------------------------------]]
+
+-- load modules
+local group = require("ui/group")
+
+-- define module
+local desktop = desktop or group()
+
+-- init desktop
+function desktop:init(name, bounds)
+ group.init(self, name, bounds)
+end
+
+-- exit desktop
+function desktop:exit()
+ group.exit(self)
+end
+
+-- return module
+return desktop
diff --git a/xmake/core/ui/group.lua b/xmake/core/ui/group.lua
index a1f6d3bc7..9588eb3a4 100644
--- a/xmake/core/ui/group.lua
+++ b/xmake/core/ui/group.lua
@@ -71,6 +71,31 @@ end
function group:execute()
end
+-- tostring(group, level)
+function group:_tostring(level)
+ local str = ""
+ if self.views then
+ str = str .. string.format("<%s %s>", self:name(), tostring(self:bounds()))
+ if not self:views():empty() then
+ str = str .. "\n"
+ end
+ for v in self:views():items() do
+ for l = 1, level do
+ str = str .. " "
+ end
+ str = str .. group._tostring(v, level + 1) .. "\n"
+ end
+ else
+ str = tostring(self)
+ end
+ return str
+end
+
+-- tostring(group)
+function group:__tostring()
+ return self:_tostring(1)
+end
+
-- return module
return group
diff --git a/xmake/core/ui/menubar.lua b/xmake/core/ui/menubar.lua
new file mode 100644
index 000000000..1bc7e9eb6
--- /dev/null
+++ b/xmake/core/ui/menubar.lua
@@ -0,0 +1,47 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file menubar.lua
+--
+
+--[[ Console User Interface (cui) ]-----------------------------------------
+Author: Tiago Dionizio (tiago.dionizio AT gmail.com)
+$Id: menubar.lua 18 2007-06-21 20:43:52Z tngd $
+--------------------------------------------------------------------------]]
+
+-- load modules
+local view = require("ui/view")
+
+-- define module
+local menubar = menubar or view()
+
+-- init menubar
+function menubar:init(name, bounds)
+ view.init(self, name, bounds)
+end
+
+-- exit menubar
+function menubar:exit()
+ view.exit(self)
+end
+
+-- return module
+return menubar
diff --git a/xmake/core/ui/statusbar.lua b/xmake/core/ui/statusbar.lua
new file mode 100644
index 000000000..bd61c2f91
--- /dev/null
+++ b/xmake/core/ui/statusbar.lua
@@ -0,0 +1,47 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file statusbar.lua
+--
+
+--[[ Console User Interface (cui) ]-----------------------------------------
+Author: Tiago Dionizio (tiago.dionizio AT gmail.com)
+$Id: statusbar.lua 18 2007-06-21 20:43:52Z tngd $
+--------------------------------------------------------------------------]]
+
+-- load modules
+local view = require("ui/view")
+
+-- define module
+local statusbar = statusbar or view()
+
+-- init statusbar
+function statusbar:init(name, bounds)
+ view.init(self, name, bounds)
+end
+
+-- exit statusbar
+function statusbar:exit()
+ view.exit(self)
+end
+
+-- return module
+return statusbar
diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua
index bf7bd8f45..1e7ef2a71 100644
--- a/xmake/core/ui/view.lua
+++ b/xmake/core/ui/view.lua
@@ -76,9 +76,9 @@ end
function view:exit()
-- close window
- if self._window then
- self._window:close()
- self._window = nil
+ if self:window() then
+ self:window():close()
+ self._WINDOW = nil
end
end
@@ -91,25 +91,40 @@ end
function view:bounds_set(bounds)
-- close the previous windows first
- if self._window then
- self._window:close()
+ if self:window() then
+ self:window():close()
end
- -- init bounds
- self._bounds = bounds()
+ -- init size and bounds
+ self._SIZE = bounds:size()
+ self._BOUNDS = bounds()
-- create a new window
- local size = bounds:size()
- self._window = curses.new_pad(size.y > 0 and size.y or 1, size.x > 0 and size.x or 1)
- assert(self._window, "cannot create window!")
+ self._WINDOW = curses.new_pad(self:height() > 0 and self:height() or 1, self:width() > 0 and self:width() or 1)
+ assert(self._WINDOW, "cannot create window!")
-- disable cursor
- self._window:leaveok(true)
+ self:window():leaveok(true)
end
--- get window bounds
+-- get view width
+function view:width()
+ return self._SIZE.x
+end
+
+-- get view height
+function view:height()
+ return self._SIZE.y
+end
+
+-- get view size
+function view:size()
+ return self._SIZE
+end
+
+-- get view bounds
function view:bounds()
- return self._bounds()
+ return self._BOUNDS
end
-- get the parent view
@@ -117,10 +132,15 @@ function view:parent()
return self._PARENT
end
+-- get the view window
+function view:window()
+ return self._WINDOW
+end
+
-- get the view canvas
function view:canvas()
if not self._CANVAS then
- self._CANVAS = canvas:new(self, self._window)
+ self._CANVAS = canvas:new(self, self:window())
end
return self._CANVAS
end
@@ -191,7 +211,7 @@ end
-- tostring(view)
function view:__tostring()
- return string.format("<view: %s %s>", self:name(), tostring(self:bounds()))
+ return string.format("<%s %s>", self:name(), tostring(self:bounds()))
end
-- return module