Diff

util-src/pposix.c @ 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
parent 10921:6eb5d2bb11af
child 12154:760dd1fc3dc1
line wrap: on
line diff
--- 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 }
 	};