Skip to content

LTUI v2.4 released, A cross platform terminal ui library based on Lua

ruki edited this page Dec 1, 2020 · 1 revision

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 complete set of cross- The character terminal ui library of the platform. And the style style basically refers to kconfig-frontends, of course, users can also customize different ui styles.

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.

Changelog

In the new version, we have improved the mouse support and realized click response to mouse events of all controls. Here we are very grateful for the contribution of @laelnasan.

In addition, we have added a scrollbar component for scrolling support, and we have also added scrolling support to choicebox and menuconf components.

choicebox scrolling support

menuconf scrolling support

Installation and usage

`console $ luarocks install ltui `

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

$ 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 compilation

Usually as long as luarocks is installed, it can be used. 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, then we can directly load related test programs through xmake run:

$ 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

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

Widgets

Views Dialogs Other
view dialog event
panel boxdialog action
label textdialog canvas
button inputdialog curses
border mconfdialog program
window choicedialog application
menubar point
menuconf rect
textedit object
textarea
statusbar
choicebox
scrollbar
desktop

Menu configuration

Input

Textarea

Windows

Termux