ltui是一个基于lua的跨平台字符终端ui界面库。
该框架最初源于xmake中图形化菜单配置的需求,类似于Linux内核的menuconfig,用于配置编译参数。因此,我们基于curses和Lua实现了一整套跨平台的字符终端UI库。其样式风格基本完全参照了kconfig-frontends,当然用户也可以自行定制不同的UI风格。
此外,LTUI是完全跨平台的,Windows上的Terminal终端也完全支持。在Windows上,LTUI会采用PDCurses进行窗口绘制。
在GitHub上的新版本更新中,我们改进了对鼠标的支持,实现了对所有控件的鼠标事件点击响应,这里我们非常感谢@laelnasan的贡献。
此外,我们还新增了一个scrollbar组件,用于支持滚动,并且我们还对choicebox和menuconf组件增加了滚动支持。
choicebox滚动支持
menuconf滚动支持 
安装和使用 要安装LTUI,可以使用以下命令:
$ luarocks install ltui
如果要运行自带的测试程序,你需要先安装Lua或LuaJIT来加载运行LTUI源码仓库中的测试程序:
$ lua tests/dialog.lua $ lua tests/window.lua $ lua tests/desktop.lua $ lua tests/inputdialog.lua $ lua tests/mconfdialog.lua
或者使用LuaJIT:
$ luajit tests/dialog.lua $ luajit tests/window.lua $ luajit tests/desktop.lua $ luajit tests/inputdialog.lua $ luajit tests/mconfdialog.lua
源码编译 通常情况下,安装好luarocks后即可使用。如果需要本地调试,可以通过源码编译后直接运行测试。首先需要安装跨平台构建工具xmake:
$ xmake
xmake会自动下载Lua、ncurses等相关依赖,然后通过
xmake run
$ xmake run test dialog $ xmake run test window $ xmake run test desktop $ xmake run test inputdialog $ xmake run test mconfdialog
应用程序示例 以下是一个简单的LTUI应用程序示例:
local ltui = require("ltui")
local application = ltui.application
local event = ltui.event
local rect = ltui.rect
local window = ltui.window
<p>local demo = application()</p><p>function demo:init()
application.init(self, "demo")
self:background_set("blue")
self:insert(window:new("window.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main window", true))
end</p><p>demo:run()标签示例 以下是一个标签的示例代码:
local lab = label:new("title", rect {0, 0, 12, 1}, "hello ltui!"):textattr_set("white")按钮示例 以下是一个按钮的示例代码:
local btn = button:new("yes", rect {0, 1, 7, 2}, ""):textattr_set("white")输入框示例 以下是一个输入框的示例代码:
function demo:init()
-- ...
local dialog_input = inputdialog:new("dialog.input", rect {0, 0, 50, 8})
dialog_input:text():text_set("please input text:")
dialog_input:button_add("no", "", function (v) dialog_input:quit() end)
dialog_input:button_add("yes", "", function (v) dialog_input:quit() end)
self:insert(dialog_input, {centerx = true, centery = true})
end以上就是LTUI v2.4 发布, 一个基于lua的跨平台字符终端UI界面库的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号