Skip to content

Commit 6fdeddc

Browse files
committed
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 <[email protected]>
1 parent 2c3ff72 commit 6fdeddc

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

src/jalv_console.c

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# include <unistd.h>
2727
#endif
2828

29+
#include <pthread.h>
2930
#include <stdbool.h>
3031
#include <stdint.h>
3132
#include <stdio.h>
@@ -322,21 +323,39 @@ jalv_frontend_select_plugin(Jalv* jalv)
322323
return NULL;
323324
}
324325

326+
void * cli_thread(void *arg) {
327+
while (1) {
328+
char line[1024];
329+
printf("> ");
330+
if (fgets(line, sizeof(line), stdin)) {
331+
jalv_process_command((Jalv*) arg, line);
332+
} else {
333+
break;
334+
}
335+
}
336+
return NULL;
337+
}
338+
339+
pthread_t init_cli_thread(Jalv* jalv) {
340+
pthread_t tid;
341+
int err=pthread_create(&tid, NULL, &cli_thread, jalv);
342+
if (err != 0) {
343+
printf("Can't create CLI thread :[%s]", strerror(err));
344+
return 0;
345+
} else {
346+
printf("CLI thread created successfully\n");
347+
return tid;
348+
}
349+
}
350+
325351
int
326352
jalv_frontend_open(Jalv* jalv)
327353
{
328-
if (!jalv_run_custom_ui(jalv) && !jalv->opts.non_interactive) {
329-
// Primitive command prompt for setting control values
330-
while (zix_sem_try_wait(&jalv->done)) {
331-
char line[1024];
332-
printf("> ");
333-
if (fgets(line, sizeof(line), stdin)) {
334-
jalv_process_command(jalv, line);
335-
} else {
336-
break;
337-
}
338-
}
339-
} else {
354+
if (!jalv->opts.non_interactive) {
355+
init_cli_thread(jalv);
356+
}
357+
358+
if (!jalv_run_custom_ui(jalv)) {
340359
zix_sem_wait(&jalv->done);
341360
}
342361

0 commit comments

Comments
 (0)