Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to run command line interaction together with UI. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions src/jalv_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# include <unistd.h>
#endif

#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -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);
}

Expand Down