aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-07-29 17:42:12 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-07-29 17:42:12 +0000
commitb3d0215c388c51a7e9838d16fe06023844af5c8b (patch)
treea9a2e0033ce38cc0b23d9306365ef81abc0ad584
parentchangelog: update scrollback indicator entry to reflect moved options (diff)
term: add capability to print warnings *inside* the terminal
This is intended to be used to print e.g. deprecation warnings inside the terminal, *before* the shell is started.
-rw-r--r--config.c6
-rw-r--r--config.h2
-rw-r--r--slave.c34
-rw-r--r--slave.h5
-rw-r--r--terminal.c3
-rw-r--r--terminal.h6
6 files changed, 51 insertions, 5 deletions
diff --git a/config.c b/config.c
index fc029884..a7c93ad9 100644
--- a/config.c
+++ b/config.c
@@ -1170,6 +1170,8 @@ config_load(struct config *conf, const char *conf_path)
.delayed_render_upper_ns = 16666666 / 2, /* half a frame period (60Hz) */
.max_shm_pool_size = 512 * 1024 * 1024,
},
+
+ .warnings = tll_init(),
};
struct config_key_binding_normal scrollback_up = {BIND_ACTION_SCROLLBACK_UP, strdup("Shift+Page_Up")};
@@ -1284,6 +1286,10 @@ config_free(struct config conf)
tll_free(conf.bindings.key);
tll_free(conf.bindings.mouse);
tll_free(conf.bindings.search);
+
+ tll_foreach(conf.warnings, it)
+ free(it->item.text);
+ tll_free(conf.warnings);
}
struct config_font
diff --git a/config.h b/config.h
index 9de282a0..aaaa3591 100644
--- a/config.h
+++ b/config.h
@@ -119,6 +119,8 @@ struct config {
uint64_t delayed_render_upper_ns;
off_t max_shm_pool_size;
} tweak;
+
+ user_warning_list_t warnings;
};
bool config_load(struct config *conf, const char *path);
diff --git a/slave.c b/slave.c
index 30b5c4d9..6b14dd61 100644
--- a/slave.c
+++ b/slave.c
@@ -18,6 +18,7 @@
#define LOG_ENABLE_DBG 0
#include "log.h"
+#include "terminal.h"
#include "tokenize.h"
static bool
@@ -67,7 +68,8 @@ err:
}
static void
-slave_exec(int ptmx, char *argv[], int err_fd, bool login_shell)
+slave_exec(int ptmx, char *argv[], int err_fd, bool login_shell,
+ size_t warning_count, struct user_warning warnings[static warning_count])
{
int pts = -1;
const char *pts_name = ptsname(ptmx);
@@ -122,6 +124,18 @@ slave_exec(int ptmx, char *argv[], int err_fd, bool login_shell)
goto err;
}
+ for (size_t i = 0; i < warning_count; i++) {
+ switch (warnings[i].kind) {
+ case USER_WARNING_DEPRECATION:
+ write(pts, "\e[33;1;5mdeprecated:\e[39;21;25m ", 32);
+ }
+
+ write(pts, warnings[i].text, strlen(warnings[i].text));
+ write(pts, "\e[m\n", 4);
+ free(warnings[i].text);
+ }
+ free(warnings);
+
close(pts);
pts = -1;
@@ -152,7 +166,8 @@ err:
pid_t
slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
- const char *term_env, const char *conf_shell, bool login_shell)
+ const char *term_env, const char *conf_shell, bool login_shell,
+ const user_warning_list_t *warnings)
{
int fork_pipe[2];
if (pipe2(fork_pipe, O_CLOEXEC) < 0) {
@@ -220,7 +235,20 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
if (is_valid_shell(shell_argv[0]))
setenv("SHELL", shell_argv[0], 1);
- slave_exec(ptmx, shell_argv, fork_pipe[1], login_shell);
+ struct user_warning *warnings_copy = malloc(
+ tll_length(*warnings) * sizeof(warnings_copy[0]));
+ {
+ size_t i = 0;
+ tll_foreach(*warnings, it){
+ warnings_copy[i] = (struct user_warning){
+ .kind = it->item.kind,
+ .text = strdup(it->item.text),
+ };
+ }
+ }
+
+ slave_exec(ptmx, shell_argv, fork_pipe[1], login_shell,
+ tll_length(*warnings), warnings_copy);
assert(false);
break;
diff --git a/slave.h b/slave.h
index 83891590..f7324704 100644
--- a/slave.h
+++ b/slave.h
@@ -3,6 +3,9 @@
#include <sys/types.h>
+#include "terminal.h"
+
pid_t slave_spawn(
int ptmx, int argc, const char *cwd, char *const *argv, const char *term_env,
- const char *conf_shell, bool login_shell);
+ const char *conf_shell, bool login_shell,
+ const user_warning_list_t *warnings);
diff --git a/terminal.c b/terminal.c
index 81592710..6b8ed69d 100644
--- a/terminal.c
+++ b/terminal.c
@@ -943,7 +943,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
/* Start the slave/client */
if ((term->slave = slave_spawn(
term->ptmx, argc, term->cwd, argv,
- conf->term, conf->shell, conf->login_shell)) == -1)
+ conf->term, conf->shell, conf->login_shell,
+ &conf->warnings)) == -1)
{
goto err;
}
diff --git a/terminal.h b/terminal.h
index 31316e37..db3ec555 100644
--- a/terminal.h
+++ b/terminal.h
@@ -206,6 +206,12 @@ enum term_surface {
TERM_SURF_BUTTON_CLOSE,
};
+struct user_warning {
+ enum { USER_WARNING_DEPRECATION } kind;
+ char *text;
+};
+typedef tll(struct user_warning) user_warning_list_t;
+
struct terminal {
struct fdm *fdm;
struct reaper *reaper;