update copyright
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file ltui.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file action.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file application.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file dlist.lua
|
||||
|
136
src/ltui/base/hashset.lua
Normal file
136
src/ltui/base/hashset.lua
Normal 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
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--o
|
||||
-- @author ruki
|
||||
-- @file log.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file os.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file path.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file string.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file table.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file border.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file boxdialog.lua
|
||||
@@ -35,24 +35,29 @@ function boxdialog:init(name, bounds, title)
|
||||
-- init window
|
||||
textdialog.init(self, name, bounds, title)
|
||||
|
||||
-- insert box
|
||||
self:panel():insert(self:box())
|
||||
|
||||
-- resize text
|
||||
self:text():bounds().ey = 3
|
||||
self._TEXT_EY = 3
|
||||
self:text():bounds().ey = self._TEXT_EY
|
||||
self:text():invalidate(true)
|
||||
self:text():option_set("selectable", false)
|
||||
self:text():option_set("progress", false)
|
||||
|
||||
-- insert box
|
||||
self:panel():insert(self:box())
|
||||
|
||||
-- text changed
|
||||
self:text():action_set(action.ac_on_text_changed, function (v)
|
||||
if v:text() then
|
||||
local lines = #self:text():splitext(v:text())
|
||||
if lines > 0 and lines < self:height() then
|
||||
self._TEXT_EY = lines
|
||||
self:invalidate(true)
|
||||
--[[
|
||||
self:box():bounds().sy = lines
|
||||
self:text():bounds().ey = lines
|
||||
self:box():invalidate(true)
|
||||
self:text():invalidate(true)
|
||||
]]
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -62,14 +67,15 @@ function boxdialog:init(name, bounds, title)
|
||||
|
||||
-- on resize for panel
|
||||
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
|
||||
|
||||
-- get box
|
||||
function boxdialog:box()
|
||||
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")
|
||||
end
|
||||
return self._BOX
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file button.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file canvas.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file choicebox.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file choicedialog.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file curses.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file desktop.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file dialog.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file event.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file inputdialog.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file label.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file mconfdialog.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file menubar.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file menuconf.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file object.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file panel.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file point.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file program.lua
|
||||
|
@@ -13,7 +13,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file rect.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file statusbar.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file textarea.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file textdialog.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file textedit.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file view.lua
|
||||
|
@@ -12,7 +12,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file window.lua
|
||||
|
@@ -16,7 +16,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file desktop.lua
|
||||
|
@@ -16,7 +16,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file dialog.lua
|
||||
|
@@ -16,7 +16,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file inputdialog.lua
|
||||
|
@@ -16,7 +16,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file mconfdialog.lua
|
||||
|
@@ -16,7 +16,7 @@
|
||||
-- See the License for the specific language governing permissions and
|
||||
-- limitations under the License.
|
||||
--
|
||||
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
|
||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||
--
|
||||
-- @author ruki
|
||||
-- @file window.lua
|
||||
|
Reference in New Issue
Block a user