update list
This commit is contained in:
@@ -37,9 +37,9 @@
|
|||||||
|
|
||||||
## Introduction ([中文](/README_zh.md))
|
## Introduction ([中文](/README_zh.md))
|
||||||
|
|
||||||
LTUI is a cross-platform terminal ui library based on Lua.
|
LTUI is a cross-platform terminal ui library based on Lua.
|
||||||
|
|
||||||
This framework originated from the requirements of graphical menu configuration in [xmake](https://github.com/xmake-io/xmake).
|
This framework originated from the requirements of graphical menu configuration in [xmake](https://github.com/xmake-io/xmake).
|
||||||
Similar to the linux kernel's menuconf to configure the compilation parameters, so using curses and lua to implement a cross-platform character terminal ui library.
|
Similar to the linux kernel's menuconf to configure the compilation parameters, so using curses and lua to implement a cross-platform character terminal ui library.
|
||||||
|
|
||||||
Refer to kconfig-frontends for style rendering. Of course, users can customize different ui styles.
|
Refer to kconfig-frontends for style rendering. Of course, users can customize different ui styles.
|
||||||
@@ -113,13 +113,13 @@ end
|
|||||||
demo:run()
|
demo:run()
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Label
|
#### Label
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local lab = label:new("title", rect {0, 0, 12, 1}, "hello ltui!"):textattr_set("white")
|
local lab = label:new("title", rect {0, 0, 12, 1}, "hello ltui!"):textattr_set("white")
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Button
|
#### Button
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local btn = button:new("yes", rect {0, 1, 7, 2}, "< Yes >"):textattr_set("white")
|
local btn = button:new("yes", rect {0, 1, 7, 2}, "< Yes >"):textattr_set("white")
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package = "ltui"
|
package = "ltui"
|
||||||
version = "2.7-1"
|
version = "2.8-1"
|
||||||
source = {
|
source = {
|
||||||
url = "git://github.com/tboox/ltui",
|
url = "git://github.com/tboox/ltui",
|
||||||
tag = "v2.7"
|
tag = "v8.7"
|
||||||
}
|
}
|
||||||
description = {
|
description = {
|
||||||
detailed = [[
|
detailed = [[
|
||||||
@@ -34,7 +34,7 @@ build = {
|
|||||||
["ltui.action"] = "src/ltui/action.lua",
|
["ltui.action"] = "src/ltui/action.lua",
|
||||||
["ltui.application"] = "src/ltui/application.lua",
|
["ltui.application"] = "src/ltui/application.lua",
|
||||||
["ltui.base.bit"] = "src/ltui/base/bit.lua",
|
["ltui.base.bit"] = "src/ltui/base/bit.lua",
|
||||||
["ltui.base.dlist"] = "src/ltui/base/dlist.lua",
|
["ltui.base.list"] = "src/ltui/base/list.lua",
|
||||||
["ltui.base.log"] = "src/ltui/base/log.lua",
|
["ltui.base.log"] = "src/ltui/base/log.lua",
|
||||||
["ltui.base.os"] = "src/ltui/base/os.lua",
|
["ltui.base.os"] = "src/ltui/base/os.lua",
|
||||||
["ltui.base.path"] = "src/ltui/base/path.lua",
|
["ltui.base.path"] = "src/ltui/base/path.lua",
|
@@ -15,41 +15,26 @@
|
|||||||
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
-- Copyright (C) 2015-2020, TBOOX Open Source Group.
|
||||||
--
|
--
|
||||||
-- @author ruki
|
-- @author ruki
|
||||||
-- @file dlist.lua
|
-- @file list.lua
|
||||||
--
|
--
|
||||||
|
|
||||||
-- load modules
|
-- load modules
|
||||||
local object = require("ltui/object")
|
local object = require("ltui/object")
|
||||||
|
|
||||||
-- define module
|
-- define module
|
||||||
local dlist = dlist or object { _init = {"_length"} } {0}
|
local list = list or object { _init = {"_length"} } {0}
|
||||||
|
|
||||||
-- clear list
|
-- clear list
|
||||||
function dlist:clear()
|
function list:clear()
|
||||||
self._length = 0
|
self._length = 0
|
||||||
self._first = nil
|
self._first = nil
|
||||||
self._last = nil
|
self._last = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- push item to tail
|
|
||||||
function dlist:push(t)
|
|
||||||
assert(t)
|
|
||||||
if self._last then
|
|
||||||
self._last._next = t
|
|
||||||
t._prev = self._last
|
|
||||||
self._last = t
|
|
||||||
else
|
|
||||||
self._first = t
|
|
||||||
self._last = t
|
|
||||||
end
|
|
||||||
self._length = self._length + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
-- insert item after the given item
|
-- insert item after the given item
|
||||||
function dlist:insert(t, after)
|
function list:insert(t, after)
|
||||||
assert(t)
|
|
||||||
if not after then
|
if not after then
|
||||||
return self:push(t)
|
return self:insert_last(t)
|
||||||
end
|
end
|
||||||
assert(t ~= after)
|
assert(t ~= after)
|
||||||
if after._next then
|
if after._next then
|
||||||
@@ -63,41 +48,8 @@ function dlist:insert(t, after)
|
|||||||
self._length = self._length + 1
|
self._length = self._length + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- pop item from tail
|
-- insert the first item in head
|
||||||
function dlist:pop()
|
function list:insert_first(t)
|
||||||
if not self._last then return end
|
|
||||||
local t = self._last
|
|
||||||
if t._prev then
|
|
||||||
t._prev._next = nil
|
|
||||||
self._last = t._prev
|
|
||||||
t._prev = nil
|
|
||||||
else
|
|
||||||
self._first = nil
|
|
||||||
self._last = nil
|
|
||||||
end
|
|
||||||
self._length = self._length - 1
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
|
|
||||||
-- shift item: 1 2 3 <- 2 3
|
|
||||||
function dlist:shift()
|
|
||||||
if not self._first then return end
|
|
||||||
local t = self._first
|
|
||||||
if t._next then
|
|
||||||
t._next._prev = nil
|
|
||||||
self._first = t._next
|
|
||||||
t._next = nil
|
|
||||||
else
|
|
||||||
self._first = nil
|
|
||||||
self._last = nil
|
|
||||||
end
|
|
||||||
self._length = self._length - 1
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
|
|
||||||
-- unshift item: 1 2 -> t 1 2
|
|
||||||
function dlist:unshift(t)
|
|
||||||
assert(t)
|
|
||||||
if self._first then
|
if self._first then
|
||||||
self._first._prev = t
|
self._first._prev = t
|
||||||
t._next = self._first
|
t._next = self._first
|
||||||
@@ -109,9 +61,21 @@ function dlist:unshift(t)
|
|||||||
self._length = self._length + 1
|
self._length = self._length + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- insert the last item in tail
|
||||||
|
function list:insert_last(t)
|
||||||
|
if self._last then
|
||||||
|
self._last._next = t
|
||||||
|
t._prev = self._last
|
||||||
|
self._last = t
|
||||||
|
else
|
||||||
|
self._first = t
|
||||||
|
self._last = t
|
||||||
|
end
|
||||||
|
self._length = self._length + 1
|
||||||
|
end
|
||||||
|
|
||||||
-- remove item
|
-- remove item
|
||||||
function dlist:remove(t)
|
function list:remove(t)
|
||||||
assert(t)
|
|
||||||
if t._next then
|
if t._next then
|
||||||
if t._prev then
|
if t._prev then
|
||||||
t._next._prev = t._prev
|
t._next._prev = t._prev
|
||||||
@@ -136,18 +100,74 @@ function dlist:remove(t)
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- remove the first item
|
||||||
|
function list:remove_first()
|
||||||
|
if not self._first then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local t = self._first
|
||||||
|
if t._next then
|
||||||
|
t._next._prev = nil
|
||||||
|
self._first = t._next
|
||||||
|
t._next = nil
|
||||||
|
else
|
||||||
|
self._first = nil
|
||||||
|
self._last = nil
|
||||||
|
end
|
||||||
|
self._length = self._length - 1
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
-- remove last item
|
||||||
|
function list:remove_last()
|
||||||
|
if not self._last then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local t = self._last
|
||||||
|
if t._prev then
|
||||||
|
t._prev._next = nil
|
||||||
|
self._last = t._prev
|
||||||
|
t._prev = nil
|
||||||
|
else
|
||||||
|
self._first = nil
|
||||||
|
self._last = nil
|
||||||
|
end
|
||||||
|
self._length = self._length - 1
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
-- push item to tail
|
||||||
|
function list:push(t)
|
||||||
|
self:insert_last(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- pop item from tail
|
||||||
|
function list:pop()
|
||||||
|
self:remove_last()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- shift item: 1 2 3 <- 2 3
|
||||||
|
function list:shift()
|
||||||
|
self:remove_first()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- unshift item: 1 2 -> t 1 2
|
||||||
|
function list:unshift(t)
|
||||||
|
self:insert_first(t)
|
||||||
|
end
|
||||||
|
|
||||||
-- get first item
|
-- get first item
|
||||||
function dlist:first()
|
function list:first()
|
||||||
return self._first
|
return self._first
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get last item
|
-- get last item
|
||||||
function dlist:last()
|
function list:last()
|
||||||
return self._last
|
return self._last
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get next item
|
-- get next item
|
||||||
function dlist:next(last)
|
function list:next(last)
|
||||||
if last then
|
if last then
|
||||||
return last._next
|
return last._next
|
||||||
else
|
else
|
||||||
@@ -156,7 +176,7 @@ function dlist:next(last)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- get the previous item
|
-- get the previous item
|
||||||
function dlist:prev(last)
|
function list:prev(last)
|
||||||
if last then
|
if last then
|
||||||
return last._prev
|
return last._prev
|
||||||
else
|
else
|
||||||
@@ -165,45 +185,42 @@ function dlist:prev(last)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- get list size
|
-- get list size
|
||||||
function dlist:size()
|
function list:size()
|
||||||
return self._length
|
return self._length
|
||||||
end
|
end
|
||||||
|
|
||||||
-- is empty?
|
-- is empty?
|
||||||
function dlist:empty()
|
function list:empty()
|
||||||
return self:size() == 0
|
return self:size() == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get items
|
-- get items
|
||||||
--
|
--
|
||||||
-- .e.g
|
-- e.g.
|
||||||
--
|
--
|
||||||
-- for item in dlist:items() do
|
-- for item in list:items() do
|
||||||
-- print(item)
|
-- print(item)
|
||||||
-- end
|
-- end
|
||||||
--
|
--
|
||||||
function dlist:items()
|
function list:items()
|
||||||
|
|
||||||
-- init iterator
|
|
||||||
local iter = function (list, item)
|
local iter = function (list, item)
|
||||||
return list:next(item)
|
return list:next(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- return iterator and initialized state
|
|
||||||
return iter, self, nil
|
return iter, self, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get reverse items
|
-- get reverse items
|
||||||
function dlist:ritems()
|
function list:ritems()
|
||||||
|
|
||||||
-- init iterator
|
|
||||||
local iter = function (list, item)
|
local iter = function (list, item)
|
||||||
return list:prev(item)
|
return list:prev(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- return iterator and initialized state
|
|
||||||
return iter, self, nil
|
return iter, self, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- return module: dlist
|
-- new list
|
||||||
return dlist
|
function list.new()
|
||||||
|
return list()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- return module: list
|
||||||
|
return list
|
@@ -25,7 +25,7 @@ local rect = require("ltui/rect")
|
|||||||
local event = require("ltui/event")
|
local event = require("ltui/event")
|
||||||
local point = require("ltui/point")
|
local point = require("ltui/point")
|
||||||
local curses = require("ltui/curses")
|
local curses = require("ltui/curses")
|
||||||
local dlist = require("ltui/base/dlist")
|
local list = require("ltui/base/list")
|
||||||
local action = require("ltui/action")
|
local action = require("ltui/action")
|
||||||
|
|
||||||
-- define module
|
-- define module
|
||||||
@@ -44,7 +44,7 @@ function panel:init(name, bounds)
|
|||||||
self:option_set("selectable", true)
|
self:option_set("selectable", true)
|
||||||
|
|
||||||
-- init child views
|
-- init child views
|
||||||
self._VIEWS = dlist()
|
self._VIEWS = list()
|
||||||
|
|
||||||
-- init views cache
|
-- init views cache
|
||||||
self._VIEWS_CACHE = {}
|
self._VIEWS_CACHE = {}
|
||||||
|
Reference in New Issue
Block a user