From 6fdeddc9abef26b4343d0cf1afe3bd51fe23e7b7 Mon Sep 17 00:00:00 2001 From: Kristian Amlie Date: Thu, 12 Dec 2024 21:14:37 +0000 Subject: [PATCH] Make it possible to run command line interaction together with UI. This is just a port of what has already been done for GTK and Qt. Signed-off-by: Kristian Amlie --- src/jalv_console.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/jalv_console.c b/src/jalv_console.c index ea110ac..2e061a1 100644 --- a/src/jalv_console.c +++ b/src/jalv_console.c @@ -26,6 +26,7 @@ # include #endif +#include #include #include #include @@ -322,21 +323,39 @@ jalv_frontend_select_plugin(Jalv* jalv) return NULL; } +void * cli_thread(void *arg) { + while (1) { + char line[1024]; + printf("> "); + if (fgets(line, sizeof(line), stdin)) { + jalv_process_command((Jalv*) arg, line); + } else { + break; + } + } + return NULL; +} + +pthread_t init_cli_thread(Jalv* jalv) { + pthread_t tid; + int err=pthread_create(&tid, NULL, &cli_thread, jalv); + if (err != 0) { + printf("Can't create CLI thread :[%s]", strerror(err)); + return 0; + } else { + printf("CLI thread created successfully\n"); + return tid; + } +} + int jalv_frontend_open(Jalv* jalv) { - if (!jalv_run_custom_ui(jalv) && !jalv->opts.non_interactive) { - // Primitive command prompt for setting control values - while (zix_sem_try_wait(&jalv->done)) { - char line[1024]; - printf("> "); - if (fgets(line, sizeof(line), stdin)) { - jalv_process_command(jalv, line); - } else { - break; - } - } - } else { + if (!jalv->opts.non_interactive) { + init_cli_thread(jalv); + } + + if (!jalv_run_custom_ui(jalv)) { zix_sem_wait(&jalv->done); }