diff --git a/src/core/lcurses/lcurses.c b/src/core/lcurses/lcurses.c index 1e8f7e1..1dbf340 100644 --- a/src/core/lcurses/lcurses.c +++ b/src/core/lcurses/lcurses.c @@ -2313,7 +2313,7 @@ static const luaL_Reg curseslib[] = {NULL, NULL} }; -__export int luaopen_ltui_curses (lua_State *L) +__export int luaopen_ltui_lcurses (lua_State *L) { /* ** create new metatable for window objects diff --git a/src/ltui/base/os.lua b/src/ltui/base/os.lua index 9f958ff..51800c8 100644 --- a/src/ltui/base/os.lua +++ b/src/ltui/base/os.lua @@ -26,7 +26,16 @@ local os = os or {} -- 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 -- diff --git a/src/ltui/base/string.lua b/src/ltui/base/string.lua index abf92e9..12691ad 100644 --- a/src/ltui/base/string.lua +++ b/src/ltui/base/string.lua @@ -25,6 +25,11 @@ -- define module: string 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 function string:find_last(pattern, plain) diff --git a/src/ltui/curses.lua b/src/ltui/curses.lua index 6885471..28b9425 100644 --- a/src/ltui/curses.lua +++ b/src/ltui/curses.lua @@ -28,7 +28,7 @@ $Id: core.lua 18 2007-06-21 20:43:52Z tngd $ --------------------------------------------------------------------------]] -- load modules -local curses = require("ltui.curses") +local curses = require("ltui.lcurses") local os = require("ltui/base/os") local log = require("ltui/base/log") diff --git a/tests/load.lua b/tests/load.lua index 29bbb73..d860d81 100755 --- a/tests/load.lua +++ b/tests/load.lua @@ -6,4 +6,58 @@ local os = require("ltui/base/os") local ltui = require("ltui.curses") 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()