diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-12-03 16:49:07 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-12-03 16:55:30 +0000 |
commit | 9e1d92559fcea7243a197726575474d6a49ad927 (patch) | |
tree | 7eedda417a4d24947a55e938a4ef69e3115b919c /src/lua/lua_util.c | |
parent | f5e2a84b6981cc12f06c908f9af277d13e64e7e8 (diff) | |
download | rspamd-9e1d92559fcea7243a197726575474d6a49ad927.tar.gz rspamd-9e1d92559fcea7243a197726575474d6a49ad927.zip |
[Minor] Disable colors if not a tty
Diffstat (limited to 'src/lua/lua_util.c')
-rw-r--r-- | src/lua/lua_util.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 29c24f0a0..480269b73 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -411,6 +411,12 @@ LUA_FUNCTION_DEF (util, mkdir); */ LUA_FUNCTION_DEF (util, umask); +/*** + * @function util.isatty() + * Returns if stdout is a tty + * @return {boolean} true in case of output being tty + */ +LUA_FUNCTION_DEF (util, isatty); /*** * @function util.pack(fmt, ...) @@ -559,6 +565,7 @@ static const struct luaL_reg utillib_f[] = { LUA_INTERFACE_DEF (util, file_exists), LUA_INTERFACE_DEF (util, mkdir), LUA_INTERFACE_DEF (util, umask), + LUA_INTERFACE_DEF (util, isatty), LUA_INTERFACE_DEF (util, get_hostname), LUA_INTERFACE_DEF (util, pack), LUA_INTERFACE_DEF (util, unpack), @@ -2253,6 +2260,19 @@ lua_util_umask (lua_State *L) return 1; } +static gint +lua_util_isatty (lua_State *L) +{ + if (isatty (STDOUT_FILENO)) { + lua_pushboolean (L, true); + } + else { + lua_pushboolean (L, false); + } + + return 1; +} + /* Backport from Lua 5.3 */ /****************************************************************************** |