Software /
code /
prosody
Changeset
11656:c368b4f6ee04
util.pposix: Bind isatty(3)
Useful for disabling certain behavior, ANSI colors etc when not
connected to a terminal.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 04 Jul 2021 15:11:07 +0200 |
parents | 11655:bbf50525faa5 |
children | 11657:46fa1b939e88 |
files | teal-src/util/pposix.d.tl util-src/pposix.c |
diffstat | 2 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 } };