From 438d6eaff0b4280492c8a0a161a33daec5de3707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 1 Nov 2019 21:10:47 +0100 Subject: [PATCH] client/server: add -t,--term to footclient --- client.c | 20 ++++++++++++++++++-- completions/zsh/_footclient | 7 +++++++ server.c | 16 +++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/client.c b/client.c index 25dcbd27..bac72838 100644 --- a/client.c +++ b/client.c @@ -30,7 +30,8 @@ print_usage(const char *prog_name) printf("Usage: %s [OPTIONS]...\n", prog_name); printf("\n"); printf("Options:\n"); - printf(" -v,--version show the version number and quit\n"); + printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n" + " -v,--version show the version number and quit\n"); } int @@ -41,17 +42,24 @@ main(int argc, char *const *argv) const char *const prog_name = argv[0]; static const struct option longopts[] = { + {"term", required_argument, 0, 't'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {NULL, no_argument, 0, 0}, }; + const char *term = ""; + while (true) { - int c = getopt_long(argc, argv, ":hv", longopts, NULL); + int c = getopt_long(argc, argv, ":t:hv", longopts, NULL); if (c == -1) break; switch (c) { + case 't': + term = optarg; + break; + case 'v': printf("footclient version %s\n", FOOT_VERSION); return EXIT_SUCCESS; @@ -98,6 +106,14 @@ main(int argc, char *const *argv) } } + uint16_t term_len = strlen(term); + if (send(fd, &term_len, sizeof(term_len), 0) != sizeof(term_len) || + send(fd, term, term_len, 0) != term_len) + { + LOG_ERRNO("failed to send TERM to server"); + goto err; + } + if (send(fd, &argc, sizeof(argc), 0) != sizeof(argc)) { LOG_ERRNO("failed to send argc/argv to server"); goto err; diff --git a/completions/zsh/_footclient b/completions/zsh/_footclient index 6ab98fd0..47a050cb 100644 --- a/completions/zsh/_footclient +++ b/completions/zsh/_footclient @@ -2,5 +2,12 @@ _arguments \ -s \ + '(-t,--term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \ '(-v --version)'{-v,--version}'[show the version number and quit]' \ '(-h --help)'{-h,--help}'[show help message and quit]' + +case ${state} in + terms) + _values 'terminal definitions' $(find /usr/share/terminfo -type f -printf "%f\n") + ;; +esac diff --git a/server.c b/server.c index f48ed262..6307b1bf 100644 --- a/server.c +++ b/server.c @@ -94,12 +94,22 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) { struct client *client = data; struct server *server = client->server; + char *term_env = NULL; if (events & EPOLLHUP) goto shutdown; assert(events & EPOLLIN); + uint16_t term_env_len; + if (recv(fd, &term_env_len, sizeof(term_env_len), 0) != sizeof(term_env_len)) + goto shutdown; + + term_env = malloc(term_env_len + 1); + term_env[term_env_len] = '\0'; + if (recv(fd, term_env, term_env_len, 0) != term_env_len) + goto shutdown; + if (recv(fd, &client->argc, sizeof(client->argc), 0) != sizeof(client->argc)) goto shutdown; @@ -117,7 +127,8 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) assert(client->term == NULL); client->term = term_init( - server->conf, server->fdm, server->wayl, server->conf->term, + server->conf, server->fdm, server->wayl, + term_env_len > 0 ? term_env : server->conf->term, client->argc, client->argv, &term_shutdown_handler, client); if (client->term == NULL) { @@ -125,11 +136,14 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data) goto shutdown; } + free(term_env); return true; shutdown: LOG_DBG("client FD=%d: disconnected", client->fd); + free(term_env); + fdm_del(fdm, fd); client->fd = -1;