LTUI v2.2 released, a lua-based cross-platform character terminal UI interface library

LTUI is a lua-based cross-platform character terminal UI interface library.

This framework is derived from the requirement of graphical menu configuration in xmake , similar to the menuconf of linux kernel to configure compilation parameters, so based on curses and lua, a set of cross-platform character terminal ui library is implemented.
And the style style basically refers to kconfig-frontends completely, of course, users can also customize different ui styles by themselves.

In addition, LTUI is completely cross-platform, and the terminal terminal on windows is also fully supported. On windows, ltui will use pdcurses to draw windows.

update content

In the new version, we mainly added support for mouse events. In addition to curses/ncurses, we also support pdcurses on windows. Here we are very grateful for the contribution of @laelnasan .

In addition, we add a new tests/events.luatest, designed to test a variety of input events.

$ xmake run test events

We can get and display all mouse input events of the user through this test example.

We can rewrite on the custom view on_eventto get all event input, including all mouse input events:

local demo = application()

function demo:init()
    application.init(self, "demo")
    self:background_set("black")
end

function demo:on_event(e)
    if e.type == "btn_code" then
        print(e.btn_name, e.x, e.y)
    end
    application.on_event(self, e)
end

demo:run()

Install and use

$ luarocks install ltui

If you want to run the built-in test, you need to install the lua or luajit program to load and run the test program in the ltui source code repository:

$ lua tests/dialog.lua
$ lua tests/window.lua
$ lua tests/desktop.lua
$ lua tests/inputdialog.lua
$ lua tests/mconfdialog.lua

or

$ luajit tests/dialog.lua
$ luajit tests/window.lua
$ luajit tests/desktop.lua
$ luajit tests/inputdialog.lua
$ luajit tests/mconfdialog.lua

Source code compilation

Usually luarocks can be used as long as it is installed. If you want to debug locally, you can also run the test directly after the source code is compiled. First, we need to install the cross-platform build tool: xmake

$ xmake

xmake will automatically download lua, ncurses and other related dependencies, and then we can directly xmake runload the related test programs:

$ xmake run test dialog
$ xmake run test window
$ xmake run test desktop
$ xmake run test inputdialog
$ xmake run test mconfdialog

application

local ltui        = require("ltui")
local application = ltui.application
local event       = ltui.event
local rect        = ltui.rect
local window      = ltui.window
local demo        = application()

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

demo:run()

label

local lab = label:new("title", rect {
    
    0, 0, 12, 1}, "hello ltui!"):textattr_set("white")

Button

local btn = button:new("yes", rect {
    
    0, 1, 7, 2}, "< Yes >"):textattr_set("white")

Input box

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", "< No >", function (v) dialog_input:quit() end)
    dialog_input:button_add("yes", "< Yes >", function (v) dialog_input:quit() end)
    self:insert(dialog_input, {
    
    centerx = true, centery = true})
end

Component

view Dialog box other
view dialog event
panel boxdialog action
label textdialog canvas
button inputdialog races
border mconfdialog program
window choicedialog application
menubar point
menuconf rect
textedit object
textarea
statusbar
choicebox
desktop

Menu configuration

Input box

Text area

Windows

Termux

https://tboox.org/cn/2020/10/19/ltui-v2.2/

Guess you like

Origin blog.csdn.net/waruqi/article/details/109155453
Recommended