Skip to content

Commit

Permalink
ncdirect_render_image(): handle newlines properly
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
dankamongmen committed Jul 2, 2020
1 parent 31c584e commit 6b5fd0d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
13 changes: 4 additions & 9 deletions src/fetch/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down
18 changes: 15 additions & 3 deletions src/lib/direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -266,16 +268,24 @@ 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;
}
}
// 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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 6b5fd0d

Please sign in to comment.