diff options
| author | ruki <[email protected]> | 2017-12-12 22:48:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-12 10:50:35 +0800 |
| commit | fccce25811e0a02bca4ac81a9ecadea85b2f855f (patch) | |
| tree | 9688090cb2aaf82699559d3c8d02df5eebea5bfe | |
| parent | a4729d44c64cd85e4c981e87ee3cf01bab6f16ac (diff) | |
init ui program
| -rw-r--r-- | tests/ui/hello.lua | 31 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/application.lua | 27 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/canvas.lua | 26 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/curses.lua | 26 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/group.lua | 26 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/log.lua | 26 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/object.lua | 26 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/point.lua | 26 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/program.lua | 26 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/rect.lua | 26 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/test.lua | 101 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/view.lua | 26 | ||||
| -rw-r--r-- | xmake/core/ui/application.lua | 80 | ||||
| -rw-r--r-- | xmake/core/ui/group.lua | 53 | ||||
| -rw-r--r-- | xmake/core/ui/point.lua | 104 | ||||
| -rw-r--r-- | xmake/core/ui/program.lua | 139 | ||||
| -rw-r--r-- | xmake/core/ui/rect.lua | 142 | ||||
| -rw-r--r-- | xmake/core/ui/view.lua | 97 |
18 files changed, 907 insertions, 101 deletions
diff --git a/tests/ui/hello.lua b/tests/ui/hello.lua new file mode 100644 index 000000000..e2330ddb0 --- /dev/null +++ b/tests/ui/hello.lua @@ -0,0 +1,31 @@ +--!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 hello.lua +-- + +-- imports +import("core.ui.application") + +-- main entry +function main(...) + application.run(...) +end diff --git a/xmake/core/sandbox/modules/import/core/ui/application.lua b/xmake/core/sandbox/modules/import/core/ui/application.lua new file mode 100644 index 000000000..3a2f02444 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/application.lua @@ -0,0 +1,27 @@ +--!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 application. +-- +-- @author ruki +-- @file application.lua +-- + +-- load module: application +return require("ui/application") + diff --git a/xmake/core/sandbox/modules/import/core/ui/canvas.lua b/xmake/core/sandbox/modules/import/core/ui/canvas.lua new file mode 100644 index 000000000..ea4e67300 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/canvas.lua @@ -0,0 +1,26 @@ +--!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 canvas.lua +-- + +-- load modules +return require("ui/canvas") diff --git a/xmake/core/sandbox/modules/import/core/ui/curses.lua b/xmake/core/sandbox/modules/import/core/ui/curses.lua new file mode 100644 index 000000000..8442c2361 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/curses.lua @@ -0,0 +1,26 @@ +--!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 curses.lua +-- + +-- return module: curses +return require("ui/curses") diff --git a/xmake/core/sandbox/modules/import/core/ui/group.lua b/xmake/core/sandbox/modules/import/core/ui/group.lua new file mode 100644 index 000000000..952a9c17b --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/group.lua @@ -0,0 +1,26 @@ +--!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 group.lua +-- + +-- return module: group +return require("ui/group") diff --git a/xmake/core/sandbox/modules/import/core/ui/log.lua b/xmake/core/sandbox/modules/import/core/ui/log.lua new file mode 100644 index 000000000..f0401008c --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/log.lua @@ -0,0 +1,26 @@ +--!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 log.lua +-- + +-- return module: log +return require("ui/log") diff --git a/xmake/core/sandbox/modules/import/core/ui/object.lua b/xmake/core/sandbox/modules/import/core/ui/object.lua new file mode 100644 index 000000000..8a270708a --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/object.lua @@ -0,0 +1,26 @@ +--!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 object.lua +-- + +-- return module: object +return require("ui/object") diff --git a/xmake/core/sandbox/modules/import/core/ui/point.lua b/xmake/core/sandbox/modules/import/core/ui/point.lua new file mode 100644 index 000000000..2dd6998a2 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/point.lua @@ -0,0 +1,26 @@ +--!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 point.lua +-- + +-- return module: point +return require("ui/point") diff --git a/xmake/core/sandbox/modules/import/core/ui/program.lua b/xmake/core/sandbox/modules/import/core/ui/program.lua new file mode 100644 index 000000000..9b073105f --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/program.lua @@ -0,0 +1,26 @@ +--!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 program. +-- +-- @author ruki +-- @file program.lua +-- + +-- return module: program +return require("ui/program") diff --git a/xmake/core/sandbox/modules/import/core/ui/rect.lua b/xmake/core/sandbox/modules/import/core/ui/rect.lua new file mode 100644 index 000000000..4acb7a6c5 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/rect.lua @@ -0,0 +1,26 @@ +--!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 rect.lua +-- + +-- return module: rect +return require("ui/rect") diff --git a/xmake/core/sandbox/modules/import/core/ui/test.lua b/xmake/core/sandbox/modules/import/core/ui/test.lua deleted file mode 100644 index 832a32586..000000000 --- a/xmake/core/sandbox/modules/import/core/ui/test.lua +++ /dev/null @@ -1,101 +0,0 @@ ---!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 linker.lua --- - --- define module -local sandbox_core_ui_test = sandbox_core_ui_test or {} - --- load modules -local log = require("ui/log") -local curses = require("ui/curses") -local raise = require("sandbox/modules/raise") - -function test() - - log:flush() - curses.init() - 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() - local blines = 5 - local olines = 10 - local lines, columns = curses.lines(), curses.columns() - local stdscr = curses.main_window() - -- create windows - w_out = stdscr:sub(lines - blines - olines, columns, olines, 0) - w_in = stdscr:sub(blines, columns, lines - blines, 0) - - -- auto refresh - w_out:immedok(true) - w_in:immedok(true) - - -- scroll region - w_in:scrollok(true) - w_out:scrollok(true) - - -- decoration - w_out:mvhline(lines - blines - olines - 1, 0, curses.ACS_HLINE, columns) - w_out:mvhline(0, 0, curses.ACS_HLINE, columns) - w_out:move(1, 0) - assert(w_out:wsetscrreg(1, lines - blines - olines - 2), "wsetscrreg") - - --w_out:wgetch() - printx = function(...) - for _, a in ipairs({...}) do - w_out:addstr(tostring(a)..'\t') - end - w_out:addstr('\n') - end - - - local y, x, cmd, ok, msg - while (1) do - y, x = w_in:getyx() w_in:move(y, x) w_in:refresh() - cmd = w_in:getstr() - printx('> '..cmd) - if (cmd == 'exit' or string.byte(cmd, 1, 1) == 4) then - break - end - end]] -end - -function sandbox_core_ui_test.main() - - local ok, msg = pcall(test) - curses.done() - if not ok then - print(msg) - end -end - --- return module -return sandbox_core_ui_test diff --git a/xmake/core/sandbox/modules/import/core/ui/view.lua b/xmake/core/sandbox/modules/import/core/ui/view.lua new file mode 100644 index 000000000..4739c5df2 --- /dev/null +++ b/xmake/core/sandbox/modules/import/core/ui/view.lua @@ -0,0 +1,26 @@ +--!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 view.lua +-- + +-- return module: view +return require("ui/view") diff --git a/xmake/core/ui/application.lua b/xmake/core/ui/application.lua new file mode 100644 index 000000000..2c993456c --- /dev/null +++ b/xmake/core/ui/application.lua @@ -0,0 +1,80 @@ +--!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 application.lua +-- + +--[[ Console User Interface (cui) ]----------------------------------------- +Author: Tiago Dionizio (tiago.dionizio AT gmail.com) +$Id: application.lua 18 2007-06-21 20:43:52Z tngd $ +--------------------------------------------------------------------------]] + +-- load modules +local os = require("base/os") +local curses = require("ui/curses") +local program = require("ui/program") + +-- define module +local application = application or program() + +-- init application +function application:init() + + -- init program + program.init(self) +end + +-- exit application +function application:exit() + + -- exit program + program.exit(self) +end + +-- run application +function application.run(...) + + -- init runner + local argv = {...} + local runner = function () + + -- new an application + local app = application:new() + if app then + app:run(argv) + app:exit() + end + end + + -- run application + local ok, errors = xpcall(runner, debug.traceback) + + -- exit curses + if not ok then + if not curses.isdone() then + curses.done() + end + os.raise(errors) + end +end + +-- return module +return application diff --git a/xmake/core/ui/group.lua b/xmake/core/ui/group.lua new file mode 100644 index 000000000..064ccfd76 --- /dev/null +++ b/xmake/core/ui/group.lua @@ -0,0 +1,53 @@ +--!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 group.lua +-- + +--[[ Console User Interface (cui) ]----------------------------------------- +Author: Tiago Dionizio (tiago.dionizio AT gmail.com) +$Id: group.lua 18 2007-06-21 20:43:52Z tngd $ +--------------------------------------------------------------------------]] + +-- load modules +local view = require("ui/view") +local curses = require("ui/curses") + +-- define module +local group = group or view() + +-- init group +function group:init(bounds) + view.init(self, bounds) +end + +-- exit group +function group:exit() + view.exit(self) +end + +-- execute group +function group:execute() +end + + +-- return module +return group diff --git a/xmake/core/ui/point.lua b/xmake/core/ui/point.lua new file mode 100644 index 000000000..56c586436 --- /dev/null +++ b/xmake/core/ui/point.lua @@ -0,0 +1,104 @@ +--!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 point.lua +-- + +--[[ Console User Interface (cui) ]----------------------------------------- +Author: Tiago Dionizio (tiago.dionizio AT gmail.com) +$Id: point.lua 18 2007-06-21 20:43:52Z tngd $ +--------------------------------------------------------------------------]] + +-- load modules +local object = require("ui/object") + +-- define module +local point = point or object { _init = {"x", "y"} } + +-- add delta x and y +function point:addxy(dx, dy) + self.x = self.x + dx + self.y = self.y + dy + return self +end + +-- add point +function point:add(p) + return self:addxy(p.x, p.y) +end + +-- sub delta x and y +function point:subxy(dx, dy) + return self:addxy(-dx, -dy) +end + +-- sub point +function point:sub(p) + return self:addxy(-p.x, -p.y) +end + +-- p1 + p2 +function point:__add(p) + local np = self() + np.x = np.x + p.x + np.y = np.y + p.y + return np +end + +-- p1 - p2 +function point:__sub(p) + local np = self() + np.x = np.x - p.x + np.y = np.y - p.y + return np +end + +-- -p +function point:__unm() + local p = self() + p.x = -p.x + p.y = -p.y + return p +end + +-- p1 == p2? +function point:__eq(p) + return self.x == p.x and self.y == p.y +end + +-- tostring(p) +function point:__tostring() + return '(' .. self.x .. ',' .. self.y .. ')' +end + +-- p1 .. p2 +function point.__concat(op1, op2) + if type(op1) == 'string' then + return op1 .. op2:__tostring() + elseif type(op2) == 'string' then + return op1:__tostring() .. op2 + else + return op1:__tostring() .. op2:__tostring() + end +end + +-- return module +return point diff --git a/xmake/core/ui/program.lua b/xmake/core/ui/program.lua new file mode 100644 index 000000000..a1ec01edf --- /dev/null +++ b/xmake/core/ui/program.lua @@ -0,0 +1,139 @@ +--!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 program.lua +-- + +--[[ Console User Interface (cui) ]----------------------------------------- +Author: Tiago Dionizio (tiago.dionizio AT gmail.com) +$Id: program.lua 18 2007-06-21 20:43:52Z tngd $ +--------------------------------------------------------------------------]] + +-- load modules +local rect = require("ui/rect") +local group = require("ui/group") +local curses = require("ui/curses") + +-- define module +local program = program or group() + +-- init program +function program:init() + + -- init main window + local main_window = self:main_window() + + -- disable echo + curses.echo(false) + + -- disable input cache + curses.cbreak(true) + + -- disable newline + curses.nl(false) + + -- to filter characters being output to the screen + -- this will filter all characters where a chtype or chstr is used + curses.map_output(true) + + -- on WIN32 ALT keys need to be mapped, so to make sure you get the wanted keys, + -- only makes sense when using keypad(true) and echo(false) + curses.map_keyboard(true) + + -- init colors + if (curses.has_colors()) then + curses.start_color() + end + +-- init_keymap() + + -- disable main window cursor + main_window:leaveok(false) + + -- enable special key map + main_window:keypad(true) + + -- non-block for getch() + main_window:nodelay(true) + + -- get 8-bits character for getch() + main_window:meta(true) + + -- init group + group.init(self, rect {0, 0, curses.columns(), curses.lines()}) + + --[[ + self:set_state('selected', true) + self:set_state('focused', true) + ]] +end + +-- exit program +function program:exit() + + -- exit group + group.exit(self) + + -- (attempt to) make sure the screen will be cleared + -- if not restored by the curses driver + self:main_window():clear() + self:main_window():noutrefresh() + curses.doupdate() + + -- exit curses + assert(not curses.isdone()) + curses.done() +end + +-- get the main window +function program:main_window() + + -- init main window if not exists + local main_window = self._MAIN_WINDOW + if not main_window then + + -- init main window + main_window = curses.init() + assert(main_window, "cannot init main window!") + + -- save main window + self._MAIN_WINDOW = main_window + end + return main_window +end + +-- get the command arguments +function program:argv() + return self._ARGV +end + +-- run program +function program:run(argv) + + -- save the current arguments + self._ARGV = argv + + -- execute group + self:execute() +end + +-- return module +return program diff --git a/xmake/core/ui/rect.lua b/xmake/core/ui/rect.lua new file mode 100644 index 000000000..6264ad67c --- /dev/null +++ b/xmake/core/ui/rect.lua @@ -0,0 +1,142 @@ + +--!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 rect.lua +-- + +--[[ Console User Interface (cui) ]----------------------------------------- +Author: Tiago Dionizio (tiago.dionizio AT gmail.com) +$Id: rect.lua 18 2007-06-21 20:43:52Z tngd $ +--------------------------------------------------------------------------]] + +-- load modules +local point = require("ui/point") +local object = require("ui/object") + +-- define module +local rect = rect or object { _init = {"sx", "sy", "ex", "ey"} } + +-- get rect size +function rect:size() + return point { self.ex - self.sx, self.ey - self.sy } +end + +-- move rect +function rect:move(dx, dy) + self.sx = self.sx + dx + self.sy = self.sy + dy + self.ex = self.ex + dx + self.ey = self.ey + dy + return self +end + +-- move top right corner of the rect +function rect:moves(dx, dy) + self.sx = self.sx + dx + self.sy = self.sy + dy + return self +end + +-- move bottom left corner of the rect +function rect:movee(dx, dy) + self.ex = self.ex + dx + self.ey = self.ey + dy + return self +end + +-- expand rect area +function rect:grow(dx, dy) + self.sx = self.sx - dx + self.sy = self.sy - dy + self.ex = self.ex + dx + self.ey = self.ey + dy + return self +end + +-- set rect with shared area between this rect and a given rect +function rect:intersect(r) + self.sx = math.max(self.sx, r.sx) + self.sy = math.max(self.sy, r.sy) + self.ex = math.min(self.ex, r.ex) + self.ey = math.min(self.ey, r.ey) + return self +end + +-- get rect with shared area between two rects: local rect_new = r1 / r2 +function rect:__div(r) + return self():intersect(r) +end + +-- set union rect +function rect:union(r) + self.sx = math.min(self.sx, r.sx) + self.sy = math.min(self.sy, r.sy) + self.ex = math.max(self.ex, r.ex) + self.ey = math.max(self.ey, r.ey) + return self +end + +-- get union rect: local rect_new = r1 + r2 +function rect:__add(r) + return self():union(r) +end + +-- r1 == r1? +function rect:__eq(r) + return + self.sx == r.sx and + self.sy == r.sy and + self.ex == r.ex and + self.ey == r.ey +end + +-- contains the given point in rect? +function rect:contains(x, y) + return x >= self.sx and x < self.ex and y >= self.sy and y < self.ey +end + +-- empty rect? +function rect:empty() + return self.sx >= self.ex or self.sy >= self.ey +end + +-- tostring(r) +function rect:__tostring() + if self:empty() then + return '[empty]' + end + return '[(' .. self.sx .. ',' .. self.sy .. '),(' .. self.ex .. ',' .. self.ey .. ')]' +end + +-- r1 .. r2 +function rect.__concat(op1, op2) + if type(op1) == 'string' then + return op1 .. op2:__tostring() + elseif type(op2) == 'string' then + return op1:__tostring() .. op2 + else + return op1:__tostring() .. op2:__tostring() + end +end + +-- return module +return rect diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua new file mode 100644 index 000000000..e8e38a9f3 --- /dev/null +++ b/xmake/core/ui/view.lua @@ -0,0 +1,97 @@ +--!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 view.lua +-- + +--[[ Console User Interface (cui) ]----------------------------------------- +Author: Tiago Dionizio (tiago.dionizio AT gmail.com) +$Id: view.lua 18 2007-06-21 20:43:52Z tngd $ +--------------------------------------------------------------------------]] + +-- load modules +local object = require("ui/object") +local curses = require("ui/curses") + +-- define module +local view = view or object() + +-- new view instance +function view:new(bounds) + + -- create instance + self = self() + + -- init view + self:init(bounds) + + -- done + return self +end + +-- init view +function view:init(bounds) + + -- check + assert(type(bounds) == 'table') + + -- init bounds + self:bounds_set(bounds) +end + +-- exit view +function view:exit() + + -- close window + if self._window then + self._window:close() + self._window = nil + end +end + +-- set window bounds +function view:bounds_set(bounds) + + -- close the previous windows first + if self._window then + self._window:close() + end + + -- init bounds + 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!") + + -- disable cursor + self._window:leaveok(true) +end + +-- get window bounds +function view:bounds() + return self._bounds() +end + + +-- return module +return view |
