patch some api

This commit is contained in:
ruki
2018-11-19 22:53:03 +08:00
parent 0e52ff2e3e
commit 9c75a63372
5 changed files with 72 additions and 4 deletions

View File

@@ -2313,7 +2313,7 @@ static const luaL_Reg curseslib[] =
{NULL, NULL} {NULL, NULL}
}; };
__export int luaopen_ltui_curses (lua_State *L) __export int luaopen_ltui_lcurses (lua_State *L)
{ {
/* /*
** create new metatable for window objects ** create new metatable for window objects

View File

@@ -26,7 +26,16 @@
local os = os or {} local os = os or {}
-- load modules -- load modules
local string = require("ltui/base/string") local string = require("ltui/base/string")
-- is file?
function os.isfile(filepath)
local file = filepath and io.open(filepath, 'r') or nil
if file then
file:close()
end
return file ~= nil
end
-- raise an exception and abort the current script -- raise an exception and abort the current script
-- --

View File

@@ -25,6 +25,11 @@
-- define module: string -- define module: string
local string = string or {} local string = string or {}
-- match the start string
function string:startswith(str)
return self:find('^' .. str) ~= nil
end
-- find the last substring with the given pattern -- find the last substring with the given pattern
function string:find_last(pattern, plain) function string:find_last(pattern, plain)

View File

@@ -28,7 +28,7 @@ $Id: core.lua 18 2007-06-21 20:43:52Z tngd $
--------------------------------------------------------------------------]] --------------------------------------------------------------------------]]
-- load modules -- load modules
local curses = require("ltui.curses") local curses = require("ltui.lcurses")
local os = require("ltui/base/os") local os = require("ltui/base/os")
local log = require("ltui/base/log") local log = require("ltui/base/log")

View File

@@ -6,4 +6,58 @@ local os = require("ltui/base/os")
local ltui = require("ltui.curses") local ltui = require("ltui.curses")
print(ltui) print(ltui)
print(os.host()) -- requires
local log = require("ltui/base/log")
local rect = require("ltui/rect")
local view = require("ltui/view")
local label = require("ltui/label")
local event = require("ltui/event")
local button = require("ltui/button")
local application = require("ltui/application")
-- the demo application
local demo = application()
-- init demo
function demo:init()
-- init name
application.init(self, "demo")
-- show desktop, menubar and statusbar
self:insert(self:desktop())
self:insert(self:menubar())
self:insert(self:statusbar())
-- init title
self:menubar():title():text_set("Menu Bar (Hello)")
-- add title label
self:desktop():insert(label:new("title", rect {0, 0, 12, 1}, "hello xmake!"):textattr_set("white"), {centerx = true})
-- add yes button
self:desktop():insert(button:new("yes", rect {0, 1, 7, 2}, "< Yes >"):textattr_set("white"), {centerx = true})
-- add no button
self:desktop():insert(button:new("no", rect {0, 2, 6, 3}, "< No >"):textattr_set("white"), {centerx = true})
end
-- on event
function demo:event_on(e)
if application.event_on(self, e) then
return true
end
if e.type == event.ev_keyboard then
self:statusbar():info():text_set(e.key_name)
if e.key_name == "s" then
self:statusbar():show(not self:statusbar():state("visible"))
elseif e.key_name == "m" then
self:menubar():show(not self:menubar():state("visible"))
elseif e.key_name == "d" then
self:desktop():show(not self:desktop():state("visible"))
end
end
end
-- main entry
demo:run()