From 6b5fd0d009a313c8da95957da2743881263b1be5 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 2 Jul 2020 00:08:40 -0400 Subject: [PATCH] ncdirect_render_image(): handle newlines properly in ncdirect_render_image(), we want to emit newlines if and only if we did not hit the right border. we want to emit cuds (cursor downs) if and only if we've hit the bottom border. this resolves all mysteries of blank lines, eliminating a FIXME. it also fixes ncneofetch's image display on very wide terminals. closes #756. also removes the display semaphore in ncneofetch, using a more natural pthread_join(). --- src/fetch/main.c | 13 ++++--------- src/lib/direct.cpp | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/fetch/main.c b/src/fetch/main.c index ad3c7b0e1..0b3a54385 100644 --- a/src/fetch/main.c +++ b/src/fetch/main.c @@ -397,7 +397,6 @@ infoplane(struct ncdirect* ncd, const fetched_info* fi){ struct marshal { struct ncdirect* nc; const distro_info* dinfo; - sem_t sem; }; static void* @@ -408,13 +407,10 @@ display_thread(void* vmarshal){ if(m->dinfo->logofile){ if(ncdirect_render_image(m->nc, m->dinfo->logofile, NCBLIT_2x2, NCSCALE_SCALE) != NCERR_SUCCESS){ - sem_post(&m->sem); return NULL; } } } - sem_post(&m->sem); - pthread_detach(pthread_self()); return NULL; } @@ -438,17 +434,16 @@ ncneofetch(struct ncdirect* nc){ .nc = nc, .dinfo = fi.distro, }; - sem_init(&display_marshal.sem, 0, 0); pthread_t tid; - if(pthread_create(&tid, NULL, display_thread, &display_marshal)){ - sem_post(&display_marshal.sem); - } + const bool launched = !pthread_create(&tid, NULL, display_thread, &display_marshal); unix_gethostname(&fi); unix_getusername(&fi); fetch_env_vars(&fi); fetch_x_props(&fi); fetch_cpu_info(&fi); - sem_wait(&display_marshal.sem); + if(launched){ + pthread_join(tid, NULL); + } if(infoplane(nc, &fi)){ return -1; } diff --git a/src/lib/direct.cpp b/src/lib/direct.cpp index 4c809207a..cb813cd66 100644 --- a/src/lib/direct.cpp +++ b/src/lib/direct.cpp @@ -254,6 +254,8 @@ int ncdirect_cursor_pop(ncdirect* n){ static int ncdirect_dump_plane(ncdirect* n, const ncplane* np){ + const int totx = ncdirect_dim_x(n); + const int toty = ncdirect_dim_y(n); int dimy, dimx; ncplane_dim_yx(np, &dimy, &dimx); for(int y = 0 ; y < dimy ; ++y){ @@ -266,7 +268,7 @@ ncdirect_dump_plane(ncdirect* n, const ncplane* np){ } ncdirect_fg(n, channels_fg(channels)); ncdirect_bg(n, channels_bg(channels)); -//fprintf(stdout, "%03d/%03d [%s] (%03dx%03d)\n", y, x, egc, dimy, dimx); +//fprintf(stderr, "%03d/%03d [%s] (%03dx%03d)\n", y, x, egc, dimy, dimx); if(printf("%s", strlen(egc) == 0 ? " " : egc) < 0){ return -1; } @@ -274,8 +276,16 @@ ncdirect_dump_plane(ncdirect* n, const ncplane* np){ // FIXME mystifyingly, we require this cursor_left() when using 2x2, but must // not have it when using 2x1 (we insert blank lines otherwise). don't paper // over it with a conditional, but instead get to the bottom of this FIXME. + if(dimx < totx){ + ncdirect_bg_default(n); + if(putchar('\n') == EOF){ + return -1; + } + } ncdirect_cursor_left(n, dimx); - //ncdirect_cursor_down(n, 1); + if(y == toty){ + ncdirect_cursor_down(n, 1); + } } return 0; } @@ -332,7 +342,9 @@ nc_err_e ncdirect_render_image(ncdirect* n, const char* file, ncblitter_e blitte return NCERR_SYSTEM; } ncvisual_destroy(ncv); - ncdirect_dump_plane(n, faken); + if(ncdirect_dump_plane(n, faken)){ + return NCERR_SYSTEM; + } free_plane(faken); return NCERR_SUCCESS; }