Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/trepl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoumith Chintala <soumith@gmail.com>2015-11-03 09:11:29 +0300
committerSoumith Chintala <soumith@gmail.com>2015-11-03 09:11:29 +0300
commit39d3b4b99397dbb57c817f87747d09e5f445e3b5 (patch)
treedeacb3c5108582560fe979c282bdbded264e66a7
parent80c261e383e6a30dbc6deebcc4f0010d40e4f281 (diff)
parentdbd6f741df40cb765f176693e28f3aecb41745d4 (diff)
Merge pull request #39 from torch/nocolors
disabling colors if terminal doesn't support colors
-rw-r--r--init.lua15
-rw-r--r--readline.c1
-rw-r--r--trepl-scm-1.rockspec3
-rw-r--r--utils.c41
4 files changed, 60 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index c117c57..b56987c 100644
--- a/init.lua
+++ b/init.lua
@@ -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 = [[
______ __
diff --git a/readline.c b/readline.c
index 6a3c260..e14c867 100644
--- a/readline.c
+++ b/readline.c
@@ -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 = {
diff --git a/utils.c b/utils.c
new file mode 100644
index 0000000..62a3e4e
--- /dev/null
+++ b/utils.c
@@ -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;
+}