add examples
This commit is contained in:
46
README.md
46
README.md
@@ -31,8 +31,18 @@
|
|||||||
|
|
||||||
LTUI is a cross-platform terminal ui library based on Lua.
|
LTUI is a cross-platform terminal ui library based on Lua.
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
We need install the cross-platform build utility [xmake](https://github.com/tboox/xmake) first.
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ xmake
|
||||||
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
#### Window
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- requires
|
-- requires
|
||||||
local ltui = require("ltui")
|
local ltui = require("ltui")
|
||||||
@@ -61,6 +71,42 @@ end
|
|||||||
demo:run()
|
demo:run()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Input dialog
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- requires
|
||||||
|
local ltui = require("ltui")
|
||||||
|
local label = ltui.label
|
||||||
|
local button = ltui.button
|
||||||
|
local application = ltui.application
|
||||||
|
local event = ltui.event
|
||||||
|
local rect = ltui.rect
|
||||||
|
local inputdialog = ltui.inputdialog
|
||||||
|
|
||||||
|
-- the demo application
|
||||||
|
local demo = application()
|
||||||
|
|
||||||
|
-- init demo
|
||||||
|
function demo:init()
|
||||||
|
|
||||||
|
-- init name
|
||||||
|
application.init(self, "demo")
|
||||||
|
|
||||||
|
-- init background
|
||||||
|
self:background_set("blue")
|
||||||
|
|
||||||
|
-- init input dialog
|
||||||
|
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
|
||||||
|
|
||||||
|
-- run demo
|
||||||
|
demo:run()
|
||||||
|
```
|
||||||
|
|
||||||
## Snapshot
|
## Snapshot
|
||||||
|
|
||||||
#### Menu configuation
|
#### Menu configuation
|
||||||
|
46
README_zh.md
46
README_zh.md
@@ -32,8 +32,18 @@
|
|||||||
|
|
||||||
LTUI是一个基于lua的跨平台字符终端UI界面库。
|
LTUI是一个基于lua的跨平台字符终端UI界面库。
|
||||||
|
|
||||||
|
## 编译
|
||||||
|
|
||||||
|
我们需要先安装跨平台构建工具:[xmake](https://github.com/tboox/xmake)
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ xmake
|
||||||
|
```
|
||||||
|
|
||||||
## 例子
|
## 例子
|
||||||
|
|
||||||
|
#### 窗口
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- requires
|
-- requires
|
||||||
local ltui = require("ltui")
|
local ltui = require("ltui")
|
||||||
@@ -62,6 +72,42 @@ end
|
|||||||
demo:run()
|
demo:run()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### 输入框
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- requires
|
||||||
|
local ltui = require("ltui")
|
||||||
|
local label = ltui.label
|
||||||
|
local button = ltui.button
|
||||||
|
local application = ltui.application
|
||||||
|
local event = ltui.event
|
||||||
|
local rect = ltui.rect
|
||||||
|
local inputdialog = ltui.inputdialog
|
||||||
|
|
||||||
|
-- the demo application
|
||||||
|
local demo = application()
|
||||||
|
|
||||||
|
-- init demo
|
||||||
|
function demo:init()
|
||||||
|
|
||||||
|
-- init name
|
||||||
|
application.init(self, "demo")
|
||||||
|
|
||||||
|
-- init background
|
||||||
|
self:background_set("blue")
|
||||||
|
|
||||||
|
-- init input dialog
|
||||||
|
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
|
||||||
|
|
||||||
|
-- run demo
|
||||||
|
demo:run()
|
||||||
|
```
|
||||||
|
|
||||||
## 快照
|
## 快照
|
||||||
|
|
||||||
#### 菜单配置
|
#### 菜单配置
|
||||||
|
Reference in New Issue
Block a user