Use libedit for monitor when available
This commit is contained in:
@@ -708,6 +708,14 @@ bool process_media_commands_3(uint8_t* id, char* fn, uint8_t* wp, int cmdargc)
|
|||||||
|| fn[strlen(fn) - 1] == '"') fn[strlen(fn) - 1] = '\0';
|
|| fn[strlen(fn) - 1] == '"') fn[strlen(fn) - 1] = '\0';
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
char* (*f_readline)(const char*) = NULL;
|
||||||
|
int (*f_add_history)(const char *) = NULL;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#define LIBEDIT_LIBRARY "libedit.dylib"
|
||||||
|
#else
|
||||||
|
#define LIBEDIT_LIBRARY "libedit.so"
|
||||||
|
#endif
|
||||||
|
|
||||||
void monitor_thread(void* param)
|
void monitor_thread(void* param)
|
||||||
{
|
{
|
||||||
@@ -715,12 +723,28 @@ void monitor_thread(void* param)
|
|||||||
{
|
{
|
||||||
char* line = NULL;
|
char* line = NULL;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
void* libedithandle = dlopen(LIBEDIT_LIBRARY, RTLD_LOCAL | RTLD_LAZY);
|
||||||
|
if (libedithandle)
|
||||||
|
{
|
||||||
|
f_readline = dlsym(libedithandle, "readline");
|
||||||
|
f_add_history = dlsym(libedithandle, "add_history");
|
||||||
|
if (!f_readline)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "readline in libedit not found, line editing will be limited.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else fprintf(stderr, "libedit not found, line editing will be limited.\n");
|
||||||
printf("86Box monitor console.\n");
|
printf("86Box monitor console.\n");
|
||||||
while (!exit_event)
|
while (!exit_event)
|
||||||
{
|
{
|
||||||
if (feof(stdin)) break;
|
if (feof(stdin)) break;
|
||||||
printf("(86Box) ");
|
if (f_readline)
|
||||||
getline(&line, &n, stdin);
|
line = f_readline("(86Box) ");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("(86Box) ");
|
||||||
|
getline(&line, &n, stdin);
|
||||||
|
}
|
||||||
if (line)
|
if (line)
|
||||||
{
|
{
|
||||||
int cmdargc = 0;
|
int cmdargc = 0;
|
||||||
@@ -733,6 +757,7 @@ void monitor_thread(void* param)
|
|||||||
line = NULL;
|
line = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (f_add_history) f_add_history(line);
|
||||||
memset(xargv, 0, sizeof(xargv));
|
memset(xargv, 0, sizeof(xargv));
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user