mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
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().
This commit is contained in:
parent
31c584e2e6
commit
6b5fd0d009
@ -397,7 +397,6 @@ infoplane(struct ncdirect* ncd, const fetched_info* fi){
|
|||||||
struct marshal {
|
struct marshal {
|
||||||
struct ncdirect* nc;
|
struct ncdirect* nc;
|
||||||
const distro_info* dinfo;
|
const distro_info* dinfo;
|
||||||
sem_t sem;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void*
|
static void*
|
||||||
@ -408,13 +407,10 @@ display_thread(void* vmarshal){
|
|||||||
if(m->dinfo->logofile){
|
if(m->dinfo->logofile){
|
||||||
if(ncdirect_render_image(m->nc, m->dinfo->logofile, NCBLIT_2x2,
|
if(ncdirect_render_image(m->nc, m->dinfo->logofile, NCBLIT_2x2,
|
||||||
NCSCALE_SCALE) != NCERR_SUCCESS){
|
NCSCALE_SCALE) != NCERR_SUCCESS){
|
||||||
sem_post(&m->sem);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sem_post(&m->sem);
|
|
||||||
pthread_detach(pthread_self());
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,17 +434,16 @@ ncneofetch(struct ncdirect* nc){
|
|||||||
.nc = nc,
|
.nc = nc,
|
||||||
.dinfo = fi.distro,
|
.dinfo = fi.distro,
|
||||||
};
|
};
|
||||||
sem_init(&display_marshal.sem, 0, 0);
|
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
if(pthread_create(&tid, NULL, display_thread, &display_marshal)){
|
const bool launched = !pthread_create(&tid, NULL, display_thread, &display_marshal);
|
||||||
sem_post(&display_marshal.sem);
|
|
||||||
}
|
|
||||||
unix_gethostname(&fi);
|
unix_gethostname(&fi);
|
||||||
unix_getusername(&fi);
|
unix_getusername(&fi);
|
||||||
fetch_env_vars(&fi);
|
fetch_env_vars(&fi);
|
||||||
fetch_x_props(&fi);
|
fetch_x_props(&fi);
|
||||||
fetch_cpu_info(&fi);
|
fetch_cpu_info(&fi);
|
||||||
sem_wait(&display_marshal.sem);
|
if(launched){
|
||||||
|
pthread_join(tid, NULL);
|
||||||
|
}
|
||||||
if(infoplane(nc, &fi)){
|
if(infoplane(nc, &fi)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -254,6 +254,8 @@ int ncdirect_cursor_pop(ncdirect* n){
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
ncdirect_dump_plane(ncdirect* n, const ncplane* np){
|
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;
|
int dimy, dimx;
|
||||||
ncplane_dim_yx(np, &dimy, &dimx);
|
ncplane_dim_yx(np, &dimy, &dimx);
|
||||||
for(int y = 0 ; y < dimy ; ++y){
|
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_fg(n, channels_fg(channels));
|
||||||
ncdirect_bg(n, channels_bg(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){
|
if(printf("%s", strlen(egc) == 0 ? " " : egc) < 0){
|
||||||
return -1;
|
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
|
// 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
|
// 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.
|
// 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_left(n, dimx);
|
||||||
//ncdirect_cursor_down(n, 1);
|
if(y == toty){
|
||||||
|
ncdirect_cursor_down(n, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -332,7 +342,9 @@ nc_err_e ncdirect_render_image(ncdirect* n, const char* file, ncblitter_e blitte
|
|||||||
return NCERR_SYSTEM;
|
return NCERR_SYSTEM;
|
||||||
}
|
}
|
||||||
ncvisual_destroy(ncv);
|
ncvisual_destroy(ncv);
|
||||||
ncdirect_dump_plane(n, faken);
|
if(ncdirect_dump_plane(n, faken)){
|
||||||
|
return NCERR_SYSTEM;
|
||||||
|
}
|
||||||
free_plane(faken);
|
free_plane(faken);
|
||||||
return NCERR_SUCCESS;
|
return NCERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user