update copyright

This commit is contained in:
ruki
2020-05-06 23:04:38 +08:00
parent d910995e50
commit 2d95bff3ea
41 changed files with 188 additions and 46 deletions

View File

@@ -13,7 +13,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file ltui.lua -- @file ltui.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file action.lua -- @file action.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file application.lua -- @file application.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file dlist.lua -- @file dlist.lua

136
src/ltui/base/hashset.lua Normal file
View File

@@ -0,0 +1,136 @@
--!A cross-platform terminal ui library based on Lua
--
-- Licensed 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-2020, TBOOX Open Source Group.
--
--
-- @author OpportunityLiu
-- @file hashset.lua
--
-- define module
local hashset = hashset or {}
local hashset_impl = hashset.__index or {}
-- load modules
local table = require("base/table")
-- representaion for nil key
hashset._NIL = setmetatable({}, {__tostring = function() return "symbol(nil)" end })
function hashset._to_key(key)
if key == nil then
key = hashset._NIL
end
return key
end
-- make a new hashset
function hashset.new()
return setmetatable({ _DATA = {}, _SIZE = 0 }, hashset)
end
-- construct from list of items
function hashset.of(...)
local result = hashset.new()
local data = table.pack(...)
for i = 1, data.n do
result:insert(data[i])
end
return result
end
-- construct from an array
function hashset.from(array)
assert(array)
return hashset.of(table.unpack(array))
end
-- check value is in hashset
function hashset_impl:has(value)
value = hashset._to_key(value)
return self._DATA[value] or false
end
-- insert value to hashset, returns false if value has already in the hashset
function hashset_impl:insert(value)
value = hashset._to_key(value)
local result = not (self._DATA[value] or false)
if result then
self._DATA[value] = true
self._SIZE = self._SIZE + 1
end
return result
end
-- remove value from hashset, returns false if value is not in the hashset
function hashset_impl:remove(value)
value = hashset._to_key(value)
local result = self._DATA[value] or false
if result then
self._DATA[value] = nil
self._SIZE = self._SIZE - 1
end
return result
end
-- convert hashset to an array, nil in the set will be ignored
function hashset_impl:to_array()
local result = {}
for k, _ in pairs(self._DATA) do
if k ~= hashset._NIL then
table.insert(result, k)
end
end
return result
end
-- iterate keys of hashtable
-- for _, key in instance:keys() do ... end
function hashset_impl:keys()
return function (table, key)
local k, _ = next(table._DATA, key)
if k == hashset._NIL then
return k, nil
else
return k, k
end
end, self, nil
end
-- get size of hashset
function hashset_impl:size()
return self._SIZE
end
-- is empty?
function hashset_impl:empty()
return self:size() == 0
end
-- get data of hashset
function hashset_impl:data()
return self._DATA
end
-- clear hashset
function hashset_impl:clear()
self._DATA = {}
self._SIZE = 0
end
-- return module
hashset.__index = hashset_impl
return hashset

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
--o --o
-- @author ruki -- @author ruki
-- @file log.lua -- @file log.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file os.lua -- @file os.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file path.lua -- @file path.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file string.lua -- @file string.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file table.lua -- @file table.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file border.lua -- @file border.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file boxdialog.lua -- @file boxdialog.lua
@@ -35,24 +35,29 @@ function boxdialog:init(name, bounds, title)
-- init window -- init window
textdialog.init(self, name, bounds, title) textdialog.init(self, name, bounds, title)
-- insert box
self:panel():insert(self:box())
-- resize text -- resize text
self:text():bounds().ey = 3 self._TEXT_EY = 3
self:text():bounds().ey = self._TEXT_EY
self:text():invalidate(true) self:text():invalidate(true)
self:text():option_set("selectable", false) self:text():option_set("selectable", false)
self:text():option_set("progress", false) self:text():option_set("progress", false)
-- insert box
self:panel():insert(self:box())
-- text changed -- text changed
self:text():action_set(action.ac_on_text_changed, function (v) self:text():action_set(action.ac_on_text_changed, function (v)
if v:text() then if v:text() then
local lines = #self:text():splitext(v:text()) local lines = #self:text():splitext(v:text())
if lines > 0 and lines < self:height() then if lines > 0 and lines < self:height() then
self._TEXT_EY = lines
self:invalidate(true)
--[[
self:box():bounds().sy = lines self:box():bounds().sy = lines
self:text():bounds().ey = lines self:text():bounds().ey = lines
self:box():invalidate(true) self:box():invalidate(true)
self:text():invalidate(true) self:text():invalidate(true)
]]
end end
end end
end) end)
@@ -62,14 +67,15 @@ function boxdialog:init(name, bounds, title)
-- on resize for panel -- on resize for panel
self:panel():action_add(action.ac_on_resized, function (v) self:panel():action_add(action.ac_on_resized, function (v)
self:box():bounds_set(rect{0, 3, v:width(), v:height() - 1}) self:text():bounds().ey = self._TEXT_EY
self:box():bounds_set(rect{0, self._TEXT_EY, v:width(), v:height() - 1})
end) end)
end end
-- get box -- get box
function boxdialog:box() function boxdialog:box()
if not self._BOX then if not self._BOX then
self._BOX = window:new("boxdialog.box", rect{0, 3, self:panel():width(), self:panel():height() - 1}) self._BOX = window:new("boxdialog.box", rect{0, self._TEXT_EY, self:panel():width(), self:panel():height() - 1})
self._BOX:border():cornerattr_set("black", "white") self._BOX:border():cornerattr_set("black", "white")
end end
return self._BOX return self._BOX

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file button.lua -- @file button.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file canvas.lua -- @file canvas.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file choicebox.lua -- @file choicebox.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file choicedialog.lua -- @file choicedialog.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file curses.lua -- @file curses.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file desktop.lua -- @file desktop.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file dialog.lua -- @file dialog.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file event.lua -- @file event.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file inputdialog.lua -- @file inputdialog.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file label.lua -- @file label.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file mconfdialog.lua -- @file mconfdialog.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file menubar.lua -- @file menubar.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file menuconf.lua -- @file menuconf.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file object.lua -- @file object.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file panel.lua -- @file panel.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file point.lua -- @file point.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file program.lua -- @file program.lua

View File

@@ -13,7 +13,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file rect.lua -- @file rect.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file statusbar.lua -- @file statusbar.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file textarea.lua -- @file textarea.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file textdialog.lua -- @file textdialog.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file textedit.lua -- @file textedit.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file view.lua -- @file view.lua

View File

@@ -12,7 +12,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file window.lua -- @file window.lua

View File

@@ -16,7 +16,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file desktop.lua -- @file desktop.lua

View File

@@ -16,7 +16,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file dialog.lua -- @file dialog.lua

View File

@@ -16,7 +16,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file inputdialog.lua -- @file inputdialog.lua

View File

@@ -16,7 +16,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file mconfdialog.lua -- @file mconfdialog.lua

View File

@@ -16,7 +16,7 @@
-- See the License for the specific language governing permissions and -- See the License for the specific language governing permissions and
-- limitations under the License. -- limitations under the License.
-- --
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group. -- Copyright (C) 2015-2020, TBOOX Open Source Group.
-- --
-- @author ruki -- @author ruki
-- @file window.lua -- @file window.lua