# HG changeset patch # User Kim Alvefur # Date 1625404267 -7200 # Node ID c368b4f6ee04bdac8cac7754fec5823a25e030e7 # Parent bbf50525faa5cce205f889b75288f85078eb8632 util.pposix: Bind isatty(3) Useful for disabling certain behavior, ANSI colors etc when not connected to a terminal. diff -r bbf50525faa5 -r c368b4f6ee04 teal-src/util/pposix.d.tl --- a/teal-src/util/pposix.d.tl Sun Jul 04 02:33:15 2021 +0200 +++ b/teal-src/util/pposix.d.tl Sun Jul 04 15:11:07 2021 +0200 @@ -98,6 +98,8 @@ atomic_append : function (f : FILE, s : string) : boolean, string, integer + isatty : function(FILE) : boolean + ENOENT : integer _NAME : string _VESRION : string diff -r bbf50525faa5 -r c368b4f6ee04 util-src/pposix.c --- a/util-src/pposix.c Sun Jul 04 02:33:15 2021 +0200 +++ b/util-src/pposix.c Sun Jul 04 15:11:07 2021 +0200 @@ -812,6 +812,13 @@ 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 @@ { "atomic_append", lc_atomic_append }, + { "isatty", lc_isatty }, + { NULL, NULL } };