summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-12-07 22:46:25 +0800
committerruki <[email protected]>2017-12-08 14:10:23 +0800
commitcb44535305f596bd757ffb58e5ae3cde6d3589fa (patch)
tree343f0ff9287b90204a6a000e0af1a7a1ed6c640b
parentabe87994168053e4f420a8b7ab286c65b546eaae (diff)
improve log and add color attrs for curses
-rw-r--r--core/makefile2
-rw-r--r--core/plat/linux/prefix.mak132
-rw-r--r--core/plat/macosx/prefix.mak168
-rw-r--r--core/src/lcurses/lcurses.c4
-rw-r--r--core/xmake.lua3
-rw-r--r--xmake/core/base/log.lua42
-rw-r--r--xmake/core/base/object.lua18
-rw-r--r--xmake/core/base/os.lua2
-rw-r--r--xmake/core/base/utils.lua18
-rw-r--r--xmake/core/main.lua2
-rw-r--r--xmake/core/sandbox/modules/import/core/base/object.lua26
-rw-r--r--xmake/core/sandbox/modules/import/core/ui/test.lua9
-rw-r--r--xmake/core/sandbox/modules/utils.lua14
-rw-r--r--xmake/core/ui/canvas.lua143
-rw-r--r--xmake/core/ui/curses.lua181
-rw-r--r--xmake/core/ui/log.lua48
-rw-r--r--xmake/core/ui/object.lua26
17 files changed, 630 insertions, 208 deletions
diff --git a/core/makefile b/core/makefile
index 478fca71f..236e6a028 100644
--- a/core/makefile
+++ b/core/makefile
@@ -261,7 +261,7 @@ endif
ifeq ($(PLAT),linux)
base_LIBPATH :=
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/curses.c | $(CC) -xc - -lcurses -o /dev/null 2>/dev/null; }; then echo curses tinfo; 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
diff --git a/core/plat/linux/prefix.mak b/core/plat/linux/prefix.mak
index 0319a8333..1dc7f0a33 100644
--- a/core/plat/linux/prefix.mak
+++ b/core/plat/linux/prefix.mak
@@ -1,129 +1,129 @@
# architecture makefile configure
# prefix & suffix
-BIN_PREFIX =
-BIN_SUFFIX = .b
+BIN_PREFIX =
+BIN_SUFFIX = .b
-OBJ_PREFIX =
-OBJ_SUFFIX = .o
+OBJ_PREFIX =
+OBJ_SUFFIX = .o
-LIB_PREFIX = lib
-LIB_SUFFIX = .a
+LIB_PREFIX = lib
+LIB_SUFFIX = .a
-DLL_PREFIX = lib
-DLL_SUFFIX = .so
+DLL_PREFIX = lib
+DLL_SUFFIX = .so
-ASM_SUFFIX = .s
+ASM_SUFFIX = .s
# prefix
-PRE_ := $(if $(BIN),$(BIN)/$(PRE),)
+PRE_ := $(if $(BIN),$(BIN)/$(PRE),)
# tool
-CC = $(PRE_)gcc
-LD = $(PRE_)gcc
-AR = $(PRE_)ar
-STRIP = $(PRE_)strip
-RANLIB = $(PRE_)ranlib
+CC = $(PRE_)gcc
+LD = $(PRE_)gcc
+AR = $(PRE_)ar
+STRIP = $(PRE_)strip
+RANLIB = $(PRE_)ranlib
AS = $(CC)
-RM = rm -f
-RMDIR = rm -rf
-CP = cp
-CPDIR = cp -r
-MKDIR = mkdir -p
-MAKE = make -r
+RM = rm -f
+RMDIR = rm -rf
+CP = cp
+CPDIR = cp -r
+MKDIR = mkdir -p
+MAKE = make -r
# architecture flags
-AHFLAGS := $(if $(AHFLAGS),$(AHFLAGS),$(if $(findstring x86_64,$(ARCH)),-m64,))
-AHFLAGS := $(if $(AHFLAGS),$(AHFLAGS),$(if $(findstring i386,$(ARCH)),-m32,))
+AHFLAGS := $(if $(AHFLAGS),$(AHFLAGS),$(if $(findstring x86_64,$(ARCH)),-m64,))
+AHFLAGS := $(if $(AHFLAGS),$(AHFLAGS),$(if $(findstring i386,$(ARCH)),-m32,))
# check flags for x64 or x86
ifneq ($(AHFLAGS),)
ifeq ($(CXFLAGS_CHECK),)
-CC_CHECK = ${shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi }
-CXFLAGS_CHECK :=
+CC_CHECK = ${shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi }
+CXFLAGS_CHECK :=
export CXFLAGS_CHECK
endif
ifeq ($(LDFLAGS_CHECK),)
-LD_CHECK = ${shell if $(LD) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi }
-LDFLAGS_CHECK := $(call LD_CHECK,-no-pie,)
+LD_CHECK = ${shell if $(LD) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi }
+LDFLAGS_CHECK := $(call LD_CHECK,-no-pie,)
export LDFLAGS_CHECK
endif
endif
# cxflags: .c/.cc/.cpp files
-CXFLAGS_RELEASE =
-CXFLAGS_DEBUG = -g -D__tb_debug__
-CXFLAGS = $(AHFLAGS) $(CXFLAGS_CHECK) -c -Wall
-CXFLAGS-I = -I
-CXFLAGS-o = -o
+CXFLAGS_RELEASE =
+CXFLAGS_DEBUG = -g -D__tb_debug__
+CXFLAGS = $(AHFLAGS) $(CXFLAGS_CHECK) -c -Wall
+CXFLAGS-I = -I
+CXFLAGS-o = -o
# suppress warning for ccache + clang bug
-CXFLAGS += $(if $(findstring clang,$(CC)),-Qunused-arguments,)
+CXFLAGS += $(if $(findstring clang,$(CC)),-Qunused-arguments,)
# optimization
ifeq ($(SMALL),y)
-CXFLAGS_RELEASE += -Os
+CXFLAGS_RELEASE += -Os
else
-CXFLAGS_RELEASE += -O3
+CXFLAGS_RELEASE += -O3
endif
# profile
ifeq ($(PROF),y)
-CXFLAGS += -g -pg -fno-omit-frame-pointer
+CXFLAGS += -g -pg -fno-omit-frame-pointer
else
-CXFLAGS_RELEASE += -fomit-frame-pointer
-CXFLAGS_DEBUG += -fno-omit-frame-pointer
+CXFLAGS_RELEASE += -fomit-frame-pointer
+CXFLAGS_DEBUG += -fno-omit-frame-pointer
endif
# cflags: .c files
-CFLAGS_RELEASE =
-CFLAGS_DEBUG =
-CFLAGS = \
+CFLAGS_RELEASE =
+CFLAGS_DEBUG =
+CFLAGS = \
-std=gnu99 \
-D_GNU_SOURCE=1 -D_REENTRANT \
-fno-math-errno
# ccflags: .cc/.cpp files
-CCFLAGS_RELEASE = -fno-rtti
-CCFLAGS_DEBUG =
-CCFLAGS = -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
+CCFLAGS_RELEASE = -fno-rtti
+CCFLAGS_DEBUG =
+CCFLAGS = -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
# ldflags
-LDFLAGS_RELEASE =
-LDFLAGS_DEBUG = -rdynamic
-LDFLAGS = $(AHFLAGS) $(LDFLAGS_CHECK)
-LDFLAGS-L = -L
-LDFLAGS-l = -l
-LDFLAGS-f =
-LDFLAGS-o = -o
+LDFLAGS_RELEASE =
+LDFLAGS_DEBUG = -rdynamic
+LDFLAGS = $(AHFLAGS) $(LDFLAGS_CHECK)
+LDFLAGS-L = -L
+LDFLAGS-l = -l
+LDFLAGS-f =
+LDFLAGS-o = -o
# prof
ifeq ($(PROF),y)
-LDFLAGS += -pg
+LDFLAGS += -pg
else
-LDFLAGS_RELEASE += -s
-LDFLAGS_DEBUG +=
+LDFLAGS_RELEASE += -s
+LDFLAGS_DEBUG +=
endif
# asflags
-ASFLAGS_RELEASE =
-ASFLAGS_DEBUG =
-ASFLAGS = -c -fPIC $(AHFLAGS)
-ASFLAGS-I = -I
-ASFLAGS-o = -o
+ASFLAGS_RELEASE =
+ASFLAGS_DEBUG =
+ASFLAGS = -c -fPIC $(AHFLAGS)
+ASFLAGS-I = -I
+ASFLAGS-o = -o
# arflags
-ARFLAGS_RELEASE =
-ARFLAGS_DEBUG =
-ARFLAGS = -cr
-ARFLAGS-o =
+ARFLAGS_RELEASE =
+ARFLAGS_DEBUG =
+ARFLAGS = -cr
+ARFLAGS-o =
# shflags
-SHFLAGS_RELEASE = -s
-SHFLAGS = $(AHFLAGS) -shared -Wl,-soname
+SHFLAGS_RELEASE = -s
+SHFLAGS = $(AHFLAGS) -shared -Wl,-soname
# include sub-config
-include $(PLAT_DIR)/config.mak
+include $(PLAT_DIR)/config.mak
diff --git a/core/plat/macosx/prefix.mak b/core/plat/macosx/prefix.mak
index 62e73beae..bb0bf2624 100644
--- a/core/plat/macosx/prefix.mak
+++ b/core/plat/macosx/prefix.mak
@@ -1,171 +1,171 @@
# architecture makefile configure
# prefix & suffix
-BIN_PREFIX =
-BIN_SUFFIX = .b
+BIN_PREFIX =
+BIN_SUFFIX = .b
-OBJ_PREFIX =
-OBJ_SUFFIX = .o
+OBJ_PREFIX =
+OBJ_SUFFIX = .o
-LIB_PREFIX = lib
-LIB_SUFFIX = .a
+LIB_PREFIX = lib
+LIB_SUFFIX = .a
-DLL_PREFIX =
-DLL_SUFFIX = .dylib
+DLL_PREFIX =
+DLL_SUFFIX = .dylib
-ASM_SUFFIX = .s
+ASM_SUFFIX = .s
# cpu bits
-BITS := $(if $(findstring x86_64,$(ARCH)),64,)
-BITS := $(if $(findstring i386,$(ARCH)),32,)
-BITS := $(if $(BITS),$(BITS),$(shell getconf LONG_BIT))
+BITS := $(if $(findstring x86_64,$(ARCH)),64,)
+BITS := $(if $(findstring i386,$(ARCH)),32,)
+BITS := $(if $(BITS),$(BITS),$(shell getconf LONG_BIT))
# prefix
-PRE_ := $(if $(BIN),$(BIN)/$(PRE),xcrun -sdk macosx )
+PRE_ := $(if $(BIN),$(BIN)/$(PRE),xcrun -sdk macosx )
# cc
-CC = $(PRE_)clang
+CC = $(PRE_)clang
ifeq ($(CXFLAGS_CHECK),)
-CC_CHECK = ${shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi }
-CXFLAGS_CHECK := $(call CC_CHECK,-ftrapv,) $(call CC_CHECK,-fsanitize=address,)
+CC_CHECK = ${shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi }
+CXFLAGS_CHECK := $(call CC_CHECK,-ftrapv,) $(call CC_CHECK,-fsanitize=address,)
export CXFLAGS_CHECK
endif
# ld
-LD = $(PRE_)clang
+LD = $(PRE_)clang
ifeq ($(LDFLAGS_CHECK),)
-LD_CHECK = ${shell if $(LD) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi }
-LDFLAGS_CHECK := $(call LD_CHECK,-ftrapv,) $(call LD_CHECK,-fsanitize=address,)
+LD_CHECK = ${shell if $(LD) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi }
+LDFLAGS_CHECK := $(call LD_CHECK,-ftrapv,) $(call LD_CHECK,-fsanitize=address,)
export LDFLAGS_CHECK
endif
# tool
-MM = $(PRE_)clang
-AR = $(PRE_)ar
-STRIP = $(PRE_)strip
-RANLIB = $(PRE_)ranlib
+MM = $(PRE_)clang
+AR = $(PRE_)ar
+STRIP = $(PRE_)strip
+RANLIB = $(PRE_)ranlib
AS = $(PRE_)clang
-RM = rm -f
-RMDIR = rm -rf
-CP = cp
-CPDIR = cp -r
-MKDIR = mkdir -p
-MAKE = make -r
+RM = rm -f
+RMDIR = rm -rf
+CP = cp
+CPDIR = cp -r
+MKDIR = mkdir -p
+MAKE = make -r
# cxflags: .c/.cc/.cpp files
-CXFLAGS_RELEASE = -fvisibility=hidden
-CXFLAGS_DEBUG = -g -D__tb_debug__
-CXFLAGS = -m$(BITS) -c -Wall -Werror -Wno-error=deprecated-declarations -Qunused-arguments -mssse3
-CXFLAGS-I = -I
-CXFLAGS-o = -o
+CXFLAGS_RELEASE = -fvisibility=hidden
+CXFLAGS_DEBUG = -g -D__tb_debug__
+CXFLAGS = -m$(BITS) -c -Wall -Werror -Wno-error=deprecated-declarations -Qunused-arguments -mssse3
+CXFLAGS-I = -I
+CXFLAGS-o = -o
# opti
ifeq ($(SMALL),y)
-CXFLAGS_RELEASE += -Os
+CXFLAGS_RELEASE += -Os
else
-CXFLAGS_RELEASE += -O3
+CXFLAGS_RELEASE += -O3
endif
# prof
ifeq ($(PROF),y)
-CXFLAGS += -g -fno-omit-frame-pointer
+CXFLAGS += -g -fno-omit-frame-pointer
else
-CXFLAGS_RELEASE += -fomit-frame-pointer
-CXFLAGS_DEBUG += -fno-omit-frame-pointer $(CXFLAGS_CHECK)
+CXFLAGS_RELEASE += -fomit-frame-pointer
+CXFLAGS_DEBUG += -fno-omit-frame-pointer $(CXFLAGS_CHECK)
endif
# cflags: .c files
-CFLAGS_RELEASE =
-CFLAGS_DEBUG =
-CFLAGS = \
+CFLAGS_RELEASE =
+CFLAGS_DEBUG =
+CFLAGS = \
-std=c99 \
-D_GNU_SOURCE=1 -D_REENTRANT \
-fno-math-errno -fno-tree-vectorize
# ccflags: .cc/.cpp files
-CCFLAGS_RELEASE =
-CCFLAGS_DEBUG =
-CCFLAGS = \
+CCFLAGS_RELEASE =
+CCFLAGS_DEBUG =
+CCFLAGS = \
-D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
-D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
# mxflags: .m/.mm files
-MXFLAGS_RELEASE = -fvisibility=hidden
-MXFLAGS_DEBUG = -g -D__tb_debug__
-MXFLAGS = \
+MXFLAGS_RELEASE = -fvisibility=hidden
+MXFLAGS_DEBUG = -g -D__tb_debug__
+MXFLAGS = \
-m$(BITS) -c -Wall -Werror -Wno-error=deprecated-declarations -Qunused-arguments \
-mssse3 $(ARCH_CXFLAGS) -fmessage-length=0 -pipe -fpascal-strings \
"-DIBOutlet=__attribute__((iboutlet))" \
"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" \
"-DIBAction=void)__attribute__((ibaction)"
-MXFLAGS-I = -I
-MXFLAGS-o = -o
+MXFLAGS-I = -I
+MXFLAGS-o = -o
# opti
ifeq ($(SMALL),y)
-MXFLAGS_RELEASE += -Os
+MXFLAGS_RELEASE += -Os
else
-MXFLAGS_RELEASE += -O3
+MXFLAGS_RELEASE += -O3
endif
# prof
ifeq ($(PROF),y)
-MXFLAGS += -g -fno-omit-frame-pointer
+MXFLAGS += -g -fno-omit-frame-pointer
else
-MXFLAGS_RELEASE += -fomit-frame-pointer
-MXFLAGS_DEBUG += -fno-omit-frame-pointer $(LDFLAGS_CHECK)
+MXFLAGS_RELEASE += -fomit-frame-pointer
+MXFLAGS_DEBUG += -fno-omit-frame-pointer $(LDFLAGS_CHECK)
endif
# mflags: .m files
-MFLAGS_RELEASE =
-MFLAGS_DEBUG =
-MFLAGS = -std=c99
+MFLAGS_RELEASE =
+MFLAGS_DEBUG =
+MFLAGS = -std=c99
# mmflags: .mm files
-MMFLAGS_RELEASE =
-MMFLAGS_DEBUG =
-MMFLAGS =
+MMFLAGS_RELEASE =
+MMFLAGS_DEBUG =
+MMFLAGS =
# ldflags
-LDFLAGS_RELEASE =
-LDFLAGS_DEBUG =
-LDFLAGS = -m$(BITS) -all_load -pagezero_size 10000 -image_base 100000000 -mmacosx-version-min=10.7
-LDFLAGS-L = -L
-LDFLAGS-l = -l
-LDFLAGS-f =
-LDFLAGS-o = -o
+LDFLAGS_RELEASE =
+LDFLAGS_DEBUG =
+LDFLAGS = -m$(BITS) -all_load -pagezero_size 10000 -image_base 100000000 -mmacosx-version-min=10.7
+LDFLAGS-L = -L
+LDFLAGS-l = -l
+LDFLAGS-f =
+LDFLAGS-o = -o
# prof
ifeq ($(PROF),y)
else
-LDFLAGS_RELEASE += -s
-LDFLAGS_DEBUG += -ftrapv
+LDFLAGS_RELEASE += -s
+LDFLAGS_DEBUG += -ftrapv
endif
# asflags
-ASFLAGS_RELEASE =
-ASFLAGS_DEBUG =
-ASFLAGS = -m$(BITS) -c -Wall
-ASFLAGS-I = -I
-ASFLAGS-o = -o
+ASFLAGS_RELEASE =
+ASFLAGS_DEBUG =
+ASFLAGS = -m$(BITS) -c -Wall
+ASFLAGS-I = -I
+ASFLAGS-o = -o
# arflags
-ARFLAGS_RELEASE =
-ARFLAGS_DEBUG =
-ARFLAGS = -cr
-ARFLAGS-o =
+ARFLAGS_RELEASE =
+ARFLAGS_DEBUG =
+ARFLAGS = -cr
+ARFLAGS-o =
# shflags
-SHFLAGS_RELEASE = -s
-SHFLAGS = $(ARCH_LDFLAGS) -dynamiclib -mmacosx-version-min=10.7
+SHFLAGS_RELEASE = -s
+SHFLAGS = $(ARCH_LDFLAGS) -dynamiclib -mmacosx-version-min=10.7
# include directory
-INC_DIR += /usr/include /usr/local/include
+INC_DIR += /usr/include /usr/local/include
# library directory
-LIB_DIR += /usr/lib /usr/local/lib
+LIB_DIR += /usr/lib /usr/local/lib
# config
-include $(PLAT_DIR)/config.mak
+include $(PLAT_DIR)/config.mak
diff --git a/core/src/lcurses/lcurses.c b/core/src/lcurses/lcurses.c
index f379824a5..704c8fab3 100644
--- a/core/src/lcurses/lcurses.c
+++ b/core/src/lcurses/lcurses.c
@@ -1436,14 +1436,12 @@ static int lc_raw(lua_State *L)
return 1;
}
-#if 0 // disable it because need link libtinfo.so on linux
static int lc_halfdelay(lua_State *L)
{
int tenths = luaL_checkint(L, 1);
lua_pushboolean(L, B(halfdelay(tenths)));
return 1;
}
-#endif
static int lcw_intrflush(lua_State *L)
{
@@ -2265,7 +2263,7 @@ static const luaL_reg curseslib[] =
{ "cbreak", lc_cbreak },
{ "echo", lc_echo },
{ "raw", lc_raw },
-// { "halfdelay", lc_halfdelay },
+ { "halfdelay", lc_halfdelay },
/* util */
{ "unctrl", lc_unctrl },
diff --git a/core/xmake.lua b/core/xmake.lua
index edf65dbe7..f3f69f6ed 100644
--- a/core/xmake.lua
+++ b/core/xmake.lua
@@ -51,6 +51,9 @@ option_end()
-- the curses option
option("curses")
add_links("curses")
+ if is_plat("linux") then
+ add_links("tinfo")
+ end
add_cincludes("curses.h")
add_defines("XM_CONFIG_API_HAVE_CURSES")
option_end()
diff --git a/xmake/core/base/log.lua b/xmake/core/base/log.lua
index e9b05f8c1..3ba6589a0 100644
--- a/xmake/core/base/log.lua
+++ b/xmake/core/base/log.lua
@@ -26,11 +26,11 @@
local log = log or {}
-- get the log file
-function log.file()
+function log:file()
-- get the output file
- if log._FILE == nil then
- local outputfile = log.outputfile()
+ if self._FILE == nil then
+ local outputfile = self:outputfile()
if outputfile then
-- get directory
@@ -48,48 +48,48 @@ function log.file()
end
-- open the log file
- log._FILE = io.open(outputfile, 'w+')
+ self._FILE = io.open(outputfile, 'w+')
end
- log._FILE = log._FILE or false
+ self._FILE = self._FILE or false
end
- return log._FILE
+ return self._FILE
end
-- get the output file
-function log.outputfile()
- if log._LOGFILE == nil then
- log._LOGFILE = os.getenv("XMAKE_LOGFILE") or false
+function log:outputfile()
+ if self._LOGFILE == nil then
+ self._LOGFILE = os.getenv("XMAKE_LOGFILE") or false
end
- return log._LOGFILE
+ return self._LOGFILE
end
-- flush log to file
-function log.flush()
- local file = log.file()
+function log:flush()
+ local file = log:file()
if file then
io.flush(file)
end
end
-- close the log file
-function log.close()
- local file = log.file()
+function log:close()
+ local file = log:file()
if file then
file:close()
end
end
-- print log to the log file
-function log.print(...)
- local file = log.file()
+function log:print(...)
+ local file = log:file()
if file then
file:write(string.format(...) .. "\n")
end
end
-- print variables to the log file
-function log.printv(...)
- local file = log.file()
+function log:printv(...)
+ local file = log:file()
if file then
local values = {...}
for i, v in ipairs(values) do
@@ -108,8 +108,8 @@ function log.printv(...)
end
-- printf log to the log file
-function log.printf(...)
- local file = log.file()
+function log:printf(...)
+ local file = self:file()
if file then
file:write(string.format(...))
end
@@ -117,7 +117,7 @@ end
-- write log the log file
function log:write(...)
- local file = log.file()
+ local file = self:file()
if file then
file:write(...)
end
diff --git a/xmake/core/base/object.lua b/xmake/core/base/object.lua
index 1922b0b4d..ab4bf468f 100644
--- a/xmake/core/base/object.lua
+++ b/xmake/core/base/object.lua
@@ -28,20 +28,10 @@ local object = object or {}
-- taken from 'std' library: http://luaforge.net/projects/stdlib/
-- and http://lua-cui.sourceforge.net/
--
--- create an object/class:
--- > object/class = parent {value, ...; field = value ...}
--- > An object's metatable is itself.
--- > In the initialiser, unnamed values are assigned to the fields
--- > given by _init (assuming the default _clone).
--- > Private fields and methods start with "_"
--- >
---
--- Access an object field: object.field
--- > Call an object method: object:method (...)
--- > Call a class method: class.method (self, ...)
--- >
--- > Add a field: object.field = x
--- > Add a method: function object:method (...) ... end
+-- local point = object { _init = {"x", "y"} }
+--
+-- local p1 = point {1, 2}
+-- > p1 {x = 1, y = 2}
--
-- permute some indices of a table
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index e311af3a3..00b38f60a 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -653,7 +653,7 @@ end
function os.raise(msg, ...)
-- flush log
- log.flush()
+ log:flush()
-- flush io buffer
io.flush()
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua
index e28938648..8a31330e7 100644
--- a/xmake/core/base/utils.lua
+++ b/xmake/core/base/utils.lua
@@ -78,7 +78,7 @@ function utils.print(format, ...)
utils._print(message)
-- write to the log file
- log.printv(message)
+ log:printv(message)
end
-- print format string without newline
@@ -94,7 +94,7 @@ function utils.printf(format, ...)
utils._iowrite(message)
-- write to the log file
- log.write(message)
+ log:write(message)
end
-- print format string and colors with newline
@@ -110,8 +110,8 @@ function utils.cprint(format, ...)
utils._print(colors.translate(message))
-- write to the log file
- if log.file() then
- log.printv(colors.ignore(message))
+ if log:file() then
+ log:printv(colors.ignore(message))
end
end
@@ -128,8 +128,8 @@ function utils.cprintf(format, ...)
utils._iowrite(colors.translate(message))
-- write to the log file
- if log.file() then
- log.write(colors.ignore(message))
+ if log:file() then
+ log:write(colors.ignore(message))
end
end
@@ -148,7 +148,7 @@ function utils.verror(format, ...)
-- enable verbose?
if option.get("verbose") and format ~= nil then
utils.cprint("${bright red}error: ${clear}" .. string.tryformat(format, ...))
- log.flush()
+ log:flush()
end
end
@@ -158,7 +158,7 @@ function utils.error(format, ...)
-- trace
if format ~= nil then
utils.cprint("${bright red}error: ${clear}" .. string.tryformat(format, ...))
- log.flush()
+ log:flush()
end
end
@@ -182,7 +182,7 @@ function utils.warning(format, ...)
end
-- flush
- log.flush()
+ log:flush()
end
-- ifelse, a? b : c
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index 6706b448d..6e76342ab 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -271,7 +271,7 @@ Or you can add `--root` option to allow run as root temporarily.
end
-- close log
- log.close()
+ log:close()
-- ok
return 0
diff --git a/xmake/core/sandbox/modules/import/core/base/object.lua b/xmake/core/sandbox/modules/import/core/base/object.lua
new file mode 100644
index 000000000..77e724611
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/base/object.lua
@@ -0,0 +1,26 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file object.lua
+--
+
+-- return module
+return require("base/object")
diff --git a/xmake/core/sandbox/modules/import/core/ui/test.lua b/xmake/core/sandbox/modules/import/core/ui/test.lua
index e4680a67f..6985c0ba1 100644
--- a/xmake/core/sandbox/modules/import/core/ui/test.lua
+++ b/xmake/core/sandbox/modules/import/core/ui/test.lua
@@ -26,10 +26,17 @@
local sandbox_core_ui_test = sandbox_core_ui_test or {}
-- load modules
+local log = require("ui/log")
+local curses = require("ui/curses")
local raise = require("sandbox/modules/raise")
function test()
+ log:flush()
+ curses.init()
+ print(curses.color_pair("yellow", "red"))
+
+ --[[
curses.init()
local blines = 5
local olines = 10
@@ -70,7 +77,7 @@ function test()
if (cmd == 'exit' or string.byte(cmd, 1, 1) == 4) then
break
end
- end
+ end]]
end
function sandbox_core_ui_test.main()
diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua
index e86eb2c08..bbd4c74c8 100644
--- a/xmake/core/sandbox/modules/utils.lua
+++ b/xmake/core/sandbox/modules/utils.lua
@@ -60,7 +60,7 @@ function sandbox_utils._print(...)
utils._print(unpack(args))
-- write to the log file
- log.printv(unpack(args))
+ log:printv(unpack(args))
end
-- print format string with newline
@@ -83,7 +83,7 @@ function sandbox_utils.print(format, ...)
utils._print(message)
-- write to the log file
- log.printv(message)
+ log:printv(message)
end,
catch
{
@@ -110,7 +110,7 @@ function sandbox_utils.printf(format, ...)
utils._iowrite(message)
-- write log to the log file
- log.write(message)
+ log:write(message)
end
-- print format string, the builtin variables and colors with newline
@@ -123,8 +123,8 @@ function sandbox_utils.cprint(format, ...)
utils._print(colors.translate(message))
-- write log to the log file
- if log.file() then
- log.printv(colors.ignore(message))
+ if log:file() then
+ log:printv(colors.ignore(message))
end
end
@@ -138,8 +138,8 @@ function sandbox_utils.cprintf(format, ...)
utils._iowrite(colors.translate(message))
-- write log to the log file
- if log.file() then
- log.write(colors.ignore(message))
+ if log:file() then
+ log:write(colors.ignore(message))
end
end
diff --git a/xmake/core/ui/canvas.lua b/xmake/core/ui/canvas.lua
new file mode 100644
index 000000000..3b538308f
--- /dev/null
+++ b/xmake/core/ui/canvas.lua
@@ -0,0 +1,143 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file canvas.lua
+--
+
+--[[ Console User Interface (cui) ]-----------------------------------------
+Author: Tiago Dionizio (tiago.dionizio AT gmail.com)
+$Id: canvas.lua 18 2007-06-21 20:43:52Z tngd $
+--------------------------------------------------------------------------]]
+
+-- load modules
+local object = require("ui/object")
+local curses = require("ui/curses")
+
+-- define module
+local canvas = canvas or object()
+
+-- new canvas instance
+function canvas:new(view, window)
+
+ -- create instance
+ self = self()
+
+ -- save view and window
+ self._view = view
+ self._window = window
+ assert(view and window, "cannot new canvas instance without view and window!")
+
+ -- TODO
+ self:attr()
+ return self
+end
+
+-- clear canvas
+function canvas:clear()
+ self._window:clear()
+ return self
+end
+
+-- move canvas to the given position
+function canvas:move(x, y)
+ self._window:move(y, x)
+ return self
+end
+
+-- get canvas border
+function canvas:border()
+ self._window:border()
+ return self
+end
+
+-- write a character to canvas
+function canvas:write_ch(ch)
+ self._window:addch(ch)
+ return self
+end
+
+-- write an acs character
+function canvas:write_acs(ch)
+ return self:write_ch(curses.acs(ch))
+end
+
+-- write a string to canvas
+function canvas:write(str, len)
+ if type(str) == 'string' then
+ self._window:addstr(str, len)
+ else
+ self._window:addchstr(str._line, len)
+ end
+ return self
+end
+
+function canvas:attr(attrs, modify)
+ local w = self._window
+ local apply = w.attron
+ local attr = curses.calc_attr(attrs)
+
+ if modify == nil then
+ w:attrset(attr)
+ elseif modify == false then
+ w:attroff(attr)
+ else
+ w:attron(attr)
+ end
+
+ apply(w, attr)
+
+ return self
+end
+
+--[[
+function canvas:line(length)
+ return Line:create(length)
+end
+
+
+function Line:create(length)
+ self = self()
+ self._length = length
+ self._line = curses.new_chstr(length)
+ return self
+end
+
+function Line:__len()
+ return self._length
+end
+
+function Line:ch(offset, char, attrs, length)
+ self._line:set_ch(offset, char, attrs and calc_attr(attrs), length)
+ return self
+end
+
+function Line:acs(offset, char, attrs, length)
+ return self:ch(offset, acs(char), attrs, length)
+end
+
+function Line:str(offset, str, attrs, rep)
+ self._line:set_str(offset, str, calc_attr(attrs), rep)
+ return self
+end
+]]
+
+-- return module
+return canvas
diff --git a/xmake/core/ui/curses.lua b/xmake/core/ui/curses.lua
new file mode 100644
index 000000000..dc3ea0d06
--- /dev/null
+++ b/xmake/core/ui/curses.lua
@@ -0,0 +1,181 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file curses.lua
+--
+
+--[[ Console User Interface (cui) ]-----------------------------------------
+Author: Tiago Dionizio ([email protected])
+$Id: core.lua 18 2007-06-21 20:43:52Z tngd $
+--------------------------------------------------------------------------]]
+
+-- define module: curses
+local curses = curses or {}
+
+-- load modules
+local os = require("base/os")
+local log = require("ui/log")
+
+-- get color from the given name
+function curses.color(name)
+ if name == 'black' then return curses.COLOR_BLACK
+ elseif name == 'red' then return curses.COLOR_RED
+ elseif name == 'green' then return curses.COLOR_GREEN
+ elseif name == 'yellow' then return curses.COLOR_YELLOW
+ elseif name == 'blue' then return curses.COLOR_BLUE
+ elseif name == 'magenta' then return curses.COLOR_MAGENTA
+ elseif name == 'cyan' then return curses.COLOR_CYAN
+ elseif name == 'white' then return curses.COLOR_WHITE
+ else return curses.COLOR_BLACK
+ end
+end
+
+-- get attr from the given name
+function curses.attr(name)
+ if name == 'normal' then return curses.A_NORMAL
+ elseif name == 'standout' then return curses.A_STANDOUT
+ elseif name == 'underline' then return curses.A_UNDERLINE
+ elseif name == 'reverse' then return curses.A_REVERSE
+ elseif name == 'blink' then return curses.A_BLINK
+ elseif name == 'dim' then return curses.A_DIM
+ elseif name == 'bold' then return curses.A_BOLD
+ elseif name == 'protect' then return curses.A_PROTECT
+ elseif name == 'invis' then return curses.A_INVIS
+ elseif name == 'alt' then return curses.A_ALTCHARSET
+ else return curses.A_NORMAL
+ end
+end
+
+-- get acs character from the given name
+function curses.acs(name)
+ if char == 'block' then return curses.ACS_BLOCK
+ elseif char == 'board' then return curses.ACS_BOARD
+ elseif char == 'btee' then return curses.ACS_BTEE
+ elseif char == 'bullet' then return curses.ACS_BULLET
+ elseif char == 'ckboard' then return curses.ACS_CKBOARD
+ elseif char == 'darrow' then return curses.ACS_DARROW
+ elseif char == 'degree' then return curses.ACS_DEGREE
+ elseif char == 'diamond' then return curses.ACS_DIAMOND
+ elseif char == 'gequal' then return curses.ACS_GEQUAL
+ elseif char == 'hline' then return curses.ACS_HLINE
+ elseif char == 'lantern' then return curses.ACS_LANTERN
+ elseif char == 'larrow' then return curses.ACS_LARROW
+ elseif char == 'lequal' then return curses.ACS_LEQUAL
+ elseif char == 'llcorner' then return curses.ACS_LLCORNER
+ elseif char == 'lrcorner' then return curses.ACS_LRCORNER
+ elseif char == 'ltee' then return curses.ACS_LTEE
+ elseif char == 'nequal' then return curses.ACS_NEQUAL
+ elseif char == 'pi' then return curses.ACS_PI
+ elseif char == 'plminus' then return curses.ACS_PLMINUS
+ elseif char == 'plus' then return curses.ACS_PLUS
+ elseif char == 'rarrow' then return curses.ACS_RARROW
+ elseif char == 'rtee' then return curses.ACS_RTEE
+ elseif char == 's1' then return curses.ACS_S1
+ elseif char == 's3' then return curses.ACS_S3
+ elseif char == 's7' then return curses.ACS_S7
+ elseif char == 's9' then return curses.ACS_S9
+ elseif char == 'sterling' then return curses.ACS_STERLING
+ elseif char == 'ttee' then return curses.ACS_TTEE
+ elseif char == 'uarrow' then return curses.ACS_UARROW
+ elseif char == 'ulcorner' then return curses.ACS_ULCORNER
+ elseif char == 'urcorner' then return curses.ACS_URCORNER
+ elseif char == 'vline' then return curses.ACS_VLINE
+ elseif type(char) == 'string' and #char == 1 then
+ return char
+ else
+ return ' '
+ end
+end
+
+-- calculate attr from the attributes list
+--
+-- local attr = curses.calc_attr("yellow")
+-- local attr = curses.calc_attr{ curses.color_pair("yellow", "green"), 'bold' }
+--
+function curses.calc_attr(attrs)
+
+ -- curses.calc_attr(curses.A_BOLD)
+ local atype = type(attrs)
+ if atype == 'number' then
+ return attrs
+ -- curses.calc_attr("bold")
+ elseif atype == 'string' then
+ return curses.attr(attrs)
+ -- curses.calc_attr{ curses.color_pair("yellow", "green"), 'bold' }
+ elseif atype == 'table' then
+ local v = 0
+ local set = {}
+ for _, a in pairs(attrs) do --TODO ipairs?
+ if not set[a] and a then
+ set[a] = true
+ if type(a) == 'number' then
+ v = v + a
+ else
+ v = v + curses.attr(a)
+ end
+ end
+ end
+ return v
+ else
+ return 0
+ end
+end
+
+-- get attr from the color pair
+function curses.color_pair(fg, bg)
+
+ -- get foreground and backround color
+ fg = curses.color(fg)
+ bg = curses.color(bg)
+
+ -- attempt to get color from the cache first
+ local key = fg .. ':' .. bg
+ local colors = curses._COLORS or {}
+ if colors[key] then
+ return colors[key]
+ end
+
+ -- no colors?
+ if not curses.has_colors() then
+ return 0
+ end
+
+ -- update the colors count
+ curses._NCOLORS = (curses._NCOLORS or 0) + 1
+
+ -- init the color pair
+ if not curses.init_pair(curses._NCOLORS, fg, bg) then
+ os.raise("failed to initialize color pair (%d, %s, %s)", curses._NCOLORS, fg, bg)
+ end
+
+ -- get the color attr
+ local attr = curses.color_pair(curses._NCOLORS)
+
+ -- save to cache
+ colors[key] = attr
+ curses._COLORS = colors
+
+ -- ok
+ return attr
+end
+
+-- return module: curses
+return curses
diff --git a/xmake/core/ui/log.lua b/xmake/core/ui/log.lua
new file mode 100644
index 000000000..25cbfd7be
--- /dev/null
+++ b/xmake/core/ui/log.lua
@@ -0,0 +1,48 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file log.lua
+--
+
+-- get log
+local log = log or (function ()
+
+ -- load modules
+ local os = require("base/os")
+ local path = require("base/path")
+
+ -- get log directory
+ local logdir = nil
+ if os.isfile(os.projectfile()) then
+ logdir = path.join(os.projectdir(), ".xmake")
+ else
+ logdir = os.tmpdir()
+ end
+
+ -- return module: log
+ local instance = require("base/log")
+ if instance then
+ instance._FILE = nil
+ instance._LOGFILE = path.join(logdir, "ui.log")
+ end
+ return instance
+end)()
+return log
diff --git a/xmake/core/ui/object.lua b/xmake/core/ui/object.lua
new file mode 100644
index 000000000..3e8aee7ab
--- /dev/null
+++ b/xmake/core/ui/object.lua
@@ -0,0 +1,26 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file object.lua
+--
+
+-- return module: object
+return require("base/object")