From b93398ce799df5c165163c96e91d6a8205f0a83c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 4 Jul 2021 15:11:07 +0200 Subject: util.pposix: Bind isatty(3) Useful for disabling certain behavior, ANSI colors etc when not connected to a terminal. --- teal-src/util/pposix.d.tl | 2 ++ util-src/pposix.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/teal-src/util/pposix.d.tl b/teal-src/util/pposix.d.tl index 7e5ce60e..68f49730 100644 --- a/teal-src/util/pposix.d.tl +++ b/teal-src/util/pposix.d.tl @@ -98,6 +98,8 @@ local record pposix atomic_append : function (f : FILE, s : string) : boolean, string, integer + isatty : function(FILE) : boolean + ENOENT : integer _NAME : string _VESRION : string diff --git a/util-src/pposix.c b/util-src/pposix.c index 856905b0..87be7e9a 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -812,6 +812,13 @@ static int lc_atomic_append(lua_State *L) { return 3; } +static int lc_isatty(lua_State *L) { + FILE *f = *(FILE **) luaL_checkudata(L, 1, LUA_FILEHANDLE); + const int fd = fileno(f); + lua_pushboolean(L, isatty(fd)); + return 1; +} + /* Register functions */ int luaopen_util_pposix(lua_State *L) { @@ -853,6 +860,8 @@ int luaopen_util_pposix(lua_State *L) { { "atomic_append", lc_atomic_append }, + { "isatty", lc_isatty }, + { NULL, NULL } }; -- cgit v1.2.3