diff options
author | Soumith Chintala <soumith@gmail.com> | 2015-11-03 09:05:31 +0300 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2015-11-03 09:07:18 +0300 |
commit | dbd6f741df40cb765f176693e28f3aecb41745d4 (patch) | |
tree | deacb3c5108582560fe979c282bdbded264e66a7 | |
parent | 80c261e383e6a30dbc6deebcc4f0010d40e4f281 (diff) |
disabling colors if terminal doesn't support colors
-rw-r--r-- | init.lua | 15 | ||||
-rw-r--r-- | readline.c | 1 | ||||
-rw-r--r-- | trepl-scm-1.rockspec | 3 | ||||
-rw-r--r-- | utils.c | 41 |
4 files changed, 60 insertions, 0 deletions
@@ -37,6 +37,21 @@ function noColors() end end +local cutils = require 'treplutils' + +-- best effort isWindows. Not robust +local function isWindows() + return type(package) == 'table' and + type(package.config) == 'string' and + package.config:sub(1,1) == '\\' +end + +if isWindows() + or (not cutils.isatty()) +or (os.execute('tput colors >/dev/null') ~= 0) then + noColors() +end + -- Help string: local selfhelp = [[ ______ __ @@ -6,6 +6,7 @@ #include "lualib.h" #include <readline/readline.h> #include <readline/history.h> +#include <ctype.h> #if LUA_VERSION_NUM == 501 # define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX) diff --git a/trepl-scm-1.rockspec b/trepl-scm-1.rockspec index 81c85a6..54269b0 100644 --- a/trepl-scm-1.rockspec +++ b/trepl-scm-1.rockspec @@ -29,6 +29,9 @@ build = { ['readline'] = { sources = {'readline.c'}, libraries = {'readline'} + }, + ['treplutils'] = { + sources = {'utils.c'}, } }, platforms = { @@ -0,0 +1,41 @@ +#include "lua.h" +#include "lauxlib.h" +#include "lualib.h" + +#if LUA_VERSION_NUM == 501 +# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX) +# define luaL_setfuncs(L, libs, _) luaL_register(L, NULL, libs) +#else +# define lua_strlen lua_rawlen +#endif + +#if defined(_WIN32) || defined(LUA_WIN) + +int treplutils_isatty(lua_State *L) +{ + lua_pushboolean(L, 0); + return 1; +} + +#else + +#include <unistd.h> + +int treplutils_isatty(lua_State *L) +{ + lua_pushboolean(L, isatty(1)); + return 1; +} + +#endif + +static const struct luaL_Reg utils[] = { + {"isatty", treplutils_isatty}, + {NULL, NULL} +}; + +int luaopen_treplutils(lua_State *L) { + lua_newtable(L); + luaL_setfuncs(L, utils, 0); + return 1; +} |