diff options
| author | ruki <[email protected]> | 2017-12-05 00:28:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-08 14:10:23 +0800 |
| commit | 19f8192150b7be4322e77e54f201c580d3e9869d (patch) | |
| tree | 6e7d6cf9ff3133ac21e5eceb4632d4b37897fe3b | |
| parent | d4498bf11ec07012bc33475c9b700aca64c45c2f (diff) | |
register curses
| -rw-r--r-- | core/detect/curses.c | 6 | ||||
| -rw-r--r-- | core/makefile | 7 | ||||
| -rw-r--r-- | core/src/demo/makefile | 6 | ||||
| -rw-r--r-- | core/src/lcurses/lcurses.c | 5 | ||||
| -rw-r--r-- | core/src/lcurses/makefile | 7 | ||||
| -rw-r--r-- | core/src/lcurses/xmake.lua | 5 | ||||
| -rw-r--r-- | core/src/xmake/config.h | 4 | ||||
| -rw-r--r-- | core/src/xmake/machine.c | 11 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 1 | ||||
| -rw-r--r-- | core/src/xmake/xmake.lua | 8 | ||||
| -rw-r--r-- | core/xmake.lua | 16 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/ui/test.lua | 53 |
12 files changed, 111 insertions, 18 deletions
diff --git a/core/detect/curses.c b/core/detect/curses.c new file mode 100644 index 000000000..492277e3b --- /dev/null +++ b/core/detect/curses.c @@ -0,0 +1,6 @@ +#include <curses.h> + +int main() +{ + if (initscr()) return endwin(); +} diff --git a/core/makefile b/core/makefile index 4551ae0b1..478fca71f 100644 --- a/core/makefile +++ b/core/makefile @@ -250,7 +250,7 @@ endif # config base ifeq ($(PLAT),macosx) base_LIBPATH := /usr/local/lib -base_LIBNAMES := readline m dl pthread +base_LIBNAMES := curses readline m dl pthread endif ifeq ($(PLAT),windows) @@ -260,7 +260,10 @@ endif ifeq ($(PLAT),linux) base_LIBPATH := -base_LIBNAMES := $(shell if { cat detect/readline.c | $(CC) -xc - -lreadline -o /dev/null 2>/dev/null; }; then echo readline; fi ) m dl pthread +base_LIBNAMES := +base_LIBNAMES += $(shell if { cat detect/curses.c | $(CC) -xc - -lcurses -o /dev/null 2>/dev/null; }; then echo curses; fi ) +base_LIBNAMES += $(shell if { cat detect/readline.c | $(CC) -xc - -lreadline -o /dev/null 2>/dev/null; }; then echo readline; fi ) +base_LIBNAMES += m dl pthread endif # check jit compiler diff --git a/core/src/demo/makefile b/core/src/demo/makefile index 6c573677b..5b79e8d4c 100644 --- a/core/src/demo/makefile +++ b/core/src/demo/makefile @@ -14,9 +14,9 @@ demo_C_FILES += xmake demo_PKGS-$(BASE) += base # others -demo_LIBS += xmake$(DTYPE) tbox$(DTYPE) luajit$(DTYPE) sv$(DTYPE) -demo_INC_DIRS += ../ ../tbox/src ../tbox/inc/$(PLAT) ../luajit/src ../sv/include -demo_LIB_DIRS += ../xmake ../tbox ../luajit ../sv +demo_LIBS += xmake$(DTYPE) lcurses$(DTYPE) tbox$(DTYPE) luajit$(DTYPE) sv$(DTYPE) +demo_INC_DIRS += ../ ../tbox/src ../tbox/inc/$(PLAT) ../luajit/src ../sv/include +demo_LIB_DIRS += ../xmake ../tbox ../luajit ../sv ../lcurses demo_CXFLAGS += -D__tb_prefix__=\"xmake\" # suffix diff --git a/core/src/lcurses/lcurses.c b/core/src/lcurses/lcurses.c index 8f791c18a..026d737e7 100644 --- a/core/src/lcurses/lcurses.c +++ b/core/src/lcurses/lcurses.c @@ -59,6 +59,8 @@ Notes: mostly for cui usage. ************************************************************************/ +#ifdef XM_CONFIG_API_HAVE_CURSES + #include <ctype.h> #include <stdlib.h> #include <string.h> @@ -2305,7 +2307,7 @@ static const luaL_reg curseslib[] = }; -int luaopen_cui_curses (lua_State *L) +int xm_curses_register (lua_State *L) { /* ** create new metatable for window objects @@ -2415,3 +2417,4 @@ static void init_ascii_map() ascii_map[252] = 110; ascii_map[253] = 50; ascii_map[254] = ACS_BULLET; ascii_map[255] = 32; } +#endif diff --git a/core/src/lcurses/makefile b/core/src/lcurses/makefile index a7be7933c..3fcd7e19e 100644 --- a/core/src/lcurses/makefile +++ b/core/src/lcurses/makefile @@ -10,9 +10,12 @@ lcurses_TYPE = LIB # config lcurses_CONFIG = n -# core files +# curses files lcurses_C_FILES += lcurses - + +# curses flags +lcurses_CXFLAGS += $(if $(findstring curses,$(base_LIBNAMES)),-DXM_CONFIG_API_HAVE_CURSES,) + # includes lcurses_INC_DIRS += ../luajit/src diff --git a/core/src/lcurses/xmake.lua b/core/src/lcurses/xmake.lua index a63f2aa7e..24dd528aa 100644 --- a/core/src/lcurses/xmake.lua +++ b/core/src/lcurses/xmake.lua @@ -15,5 +15,6 @@ target("lcurses") -- add the common source files add_files("*.c") - - + + -- add options + add_options("curses") diff --git a/core/src/xmake/config.h b/core/src/xmake/config.h index 978456b18..5150880e6 100644 --- a/core/src/xmake/config.h +++ b/core/src/xmake/config.h @@ -22,8 +22,8 @@ * @file config.h * */ -#ifndef XM_GBOX_CONFIG_H -#define XM_GBOX_CONFIG_H +#ifndef XM_CORE_CONFIG_H +#define XM_CORE_CONFIG_H /* ////////////////////////////////////////////////////////////////////////////////////// * includes diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index 6d26c445d..c98bf1be1 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -132,6 +132,11 @@ tb_int_t xm_semver_parse(lua_State* lua); tb_int_t xm_semver_satisfies(lua_State* lua); tb_int_t xm_semver_select(lua_State* lua); +#ifdef XM_CONFIG_API_HAVE_CURSES +// register curses +tb_int_t xm_curses_register(lua_State* lua); +#endif + /* ////////////////////////////////////////////////////////////////////////////////////// * globals */ @@ -486,6 +491,12 @@ xm_machine_ref_t xm_machine_init() // bind semver functions luaL_register(impl->lua, "semver", g_semver_functions); +#ifdef XM_CONFIG_API_HAVE_CURSES + // bind curses + xm_curses_register(impl->lua); + lua_setglobal(impl->lua, "curses"); +#endif + // init host #if defined(TB_CONFIG_OS_WINDOWS) lua_pushstring(impl->lua, "windows"); diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index ee3062634..a8afcd30d 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -69,6 +69,7 @@ xmake_C_FILES += \ # flags xmake_CXFLAGS += -D__tb_prefix__=\"xmake\" xmake_CXFLAGS += $(if $(findstring readline,$(base_LIBNAMES)),-DXM_CONFIG_API_HAVE_READLINE,) +xmake_CXFLAGS += $(if $(findstring curses,$(base_LIBNAMES)),-DXM_CONFIG_API_HAVE_CURSES,) # includes xmake_INC_DIRS += \ diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua index 176409194..bfe67e79d 100644 --- a/core/src/xmake/xmake.lua +++ b/core/src/xmake/xmake.lua @@ -5,7 +5,7 @@ target("xmake") set_kind("static") -- add deps - add_deps("sv", "luajit", "tbox") + add_deps("lcurses", "sv", "luajit", "tbox") -- add defines add_defines("__tb_prefix__=\"xmake\"") @@ -24,7 +24,7 @@ target("xmake") -- add the common source files add_files("**.c") - - -- add cfunc - add_cfunc("API", "readline", "readline", {"readline/readline.h"}, "readline") + + -- add options + add_options("curses", "readline") diff --git a/core/xmake.lua b/core/xmake.lua index 00b537119..f71659bf2 100644 --- a/core/xmake.lua +++ b/core/xmake.lua @@ -46,5 +46,21 @@ if is_mode("coverage") then add_ldflags("-coverage", "-fprofile-arcs", "-ftest-coverage") end +-- the readline option +option("readline") + add_links("readline") + add_cincludes("readline/readline.h") + add_cfuncs("readline") + add_defines("XM_CONFIG_API_HAVE_READLINE") +option_end() + +-- the curses option +option("curses") + add_links("curses") + add_cincludes("curses.h") + add_cfuncs("initscr") + add_defines("XM_CONFIG_API_HAVE_CURSES") +option_end() + -- add projects includes("src/lcurses", "src/sv","src/luajit", "src/tbox", "src/xmake", "src/demo") diff --git a/xmake/core/sandbox/modules/import/core/ui/test.lua b/xmake/core/sandbox/modules/import/core/ui/test.lua index 2988903f1..e4680a67f 100644 --- a/xmake/core/sandbox/modules/import/core/ui/test.lua +++ b/xmake/core/sandbox/modules/import/core/ui/test.lua @@ -28,9 +28,58 @@ local sandbox_core_ui_test = sandbox_core_ui_test or {} -- load modules local raise = require("sandbox/modules/raise") +function test() + + curses.init() + local blines = 5 + local olines = 10 + local lines, columns = curses.lines(), curses.columns() + local stdscr = curses.main_window() + -- create windows + w_out = stdscr:sub(lines - blines - olines, columns, olines, 0) + w_in = stdscr:sub(blines, columns, lines - blines, 0) + + -- auto refresh + w_out:immedok(true) + w_in:immedok(true) + + -- scroll region + w_in:scrollok(true) + w_out:scrollok(true) + + -- decoration + w_out:mvhline(lines - blines - olines - 1, 0, curses.ACS_HLINE, columns) + w_out:mvhline(0, 0, curses.ACS_HLINE, columns) + w_out:move(1, 0) + assert(w_out:wsetscrreg(1, lines - blines - olines - 2), "wsetscrreg") + + --w_out:wgetch() + printx = function(...) + for _, a in ipairs({...}) do + w_out:addstr(tostring(a)..'\t') + end + w_out:addstr('\n') + end + + + local y, x, cmd, ok, msg + while (1) do + y, x = w_in:getyx() w_in:move(y, x) w_in:refresh() + cmd = w_in:getstr() + printx('> '..cmd) + if (cmd == 'exit' or string.byte(cmd, 1, 1) == 4) then + break + end + end +end + function sandbox_core_ui_test.main() - - print("test") + + local ok, msg = pcall(test) + curses.done() + if not ok then + print(msg) + end end -- return module |
