2020-04-21 05:50:25 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <notcurses/notcurses.h>
|
|
|
|
|
|
|
|
static bool fddone;
|
|
|
|
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
|
|
|
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
static int
|
|
|
|
cb(struct ncfdplane* ncfd, const void* data, size_t len, void* curry){
|
|
|
|
int ret = -1;
|
|
|
|
if(ncplane_putstr(ncfdplane_plane(ncfd), data) >= 0){
|
|
|
|
if(!notcurses_render(ncplane_notcurses(ncfdplane_plane(ncfd)))){
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(void)len;
|
|
|
|
(void)curry;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
eofcb(struct ncfdplane* ncfd, int nerrno, void* curry){
|
2020-05-06 09:24:23 +00:00
|
|
|
(void)ncfd;
|
2020-04-21 05:50:25 +00:00
|
|
|
(void)nerrno;
|
|
|
|
(void)curry;
|
|
|
|
pthread_mutex_lock(&lock);
|
|
|
|
fddone = true;
|
|
|
|
pthread_mutex_unlock(&lock);
|
|
|
|
pthread_cond_signal(&cond);
|
2020-05-02 07:33:30 +00:00
|
|
|
return nerrno;
|
2020-04-21 05:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv){
|
2020-05-19 12:44:39 +00:00
|
|
|
if(argc < 2){
|
2020-05-22 13:16:41 +00:00
|
|
|
fprintf(stderr, "usage: %s binary [ args... ]\n", *argv);
|
2020-04-21 05:50:25 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2020-05-19 12:44:39 +00:00
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
notcurses_options opts = {
|
|
|
|
.inhibit_alternate_screen = true,
|
|
|
|
.flags = NCOPTION_INHIBIT_SETLOCALE,
|
|
|
|
};
|
|
|
|
struct notcurses* nc = notcurses_init(&opts, NULL);
|
2020-04-21 05:50:53 +00:00
|
|
|
if(nc == NULL){
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2020-05-22 13:16:41 +00:00
|
|
|
++argv;
|
2020-04-21 05:50:25 +00:00
|
|
|
struct ncplane* n = notcurses_stdplane(nc);
|
|
|
|
ncsubproc_options nopts = {};
|
|
|
|
struct ncsubproc* nsproc = ncsubproc_createvp(n, &nopts, *argv, argv, cb, eofcb);
|
|
|
|
pthread_mutex_lock(&lock);
|
|
|
|
while(!fddone){
|
|
|
|
pthread_cond_wait(&cond, &lock);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&lock);
|
2020-04-25 21:55:59 +00:00
|
|
|
ncsubproc_destroy(nsproc);
|
2020-05-02 07:33:30 +00:00
|
|
|
if(notcurses_stop(nc)){
|
2020-04-21 05:50:25 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|