From a6e7cb553f9cc136cb7358385ca266d40a33523d Mon Sep 17 00:00:00 2001
From: Přemysl Eric Janouch
Date: Fri, 3 Jan 2025 09:13:24 +0100
Subject: WIP
---
tools/wdye/wdye.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/tools/wdye/wdye.c b/tools/wdye/wdye.c
index 47e485b..31652c6 100644
--- a/tools/wdye/wdye.c
+++ b/tools/wdye/wdye.c
@@ -31,6 +31,7 @@
#include
#endif
+#include
#include
// --- Pseudoterminal ----------------------------------------------------------
@@ -316,6 +317,31 @@ environ_map_serialize (struct str_map *env, struct strv *envv)
xstrdup_printf ("%s=%s", iter.link->key, value));
}
+static bool
+xlua_load_terminal (lua_State *L, const char *term)
+{
+ // TODO(p): See if we can get away with using a bogus FD.
+ int err = 0;
+ TERMINAL *saved_term = set_curterm (NULL);
+ if (setupterm ((char *) term, STDOUT_FILENO, &err) != OK)
+ {
+ set_curterm (saved_term);
+ return false;
+ }
+
+ for (size_t i = 0; strfnames[i]; i++)
+ {
+ const char *name = strfnames[i];
+ const char *value = tigetstr (strnames[i]);
+ if (value && value != (char *) -1)
+ continue;
+ }
+
+ del_curterm (set_curterm (saved_term));
+
+ return true;
+}
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static int
@@ -323,12 +349,18 @@ xlua_spawn_protected (lua_State *L)
{
struct xlua_spawn_context *ctx = lua_touserdata (L, 1);
+ // TODO(p): Consider taking the TERM from the passed environ,
+ // or defaulting to inherited TERM. These should match anyway.
+
// Step 1: Prepare a terminal object.
(void) xlua_getfield (L, 1, "term", LUA_TSTRING, true);
const char *term = lua_tostring (L, -1);
+
+
// TODO(p): Process the terminal name,
// possibly by creating another indexable Lua object/table.
// - Remember to use a default when `term == NULL`.
+
lua_pop (L, 1);
// Step 2: Prepare process environment.
--
cgit v1.2.3-70-g09d2