Skip to content

Commit

Permalink
[ncneofetch] fix up infoplane placement for bottom of screen #2196
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Nov 24, 2021
1 parent 8cc9770 commit b0bd292
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
32 changes: 21 additions & 11 deletions src/fetch/main.c
Expand Up @@ -4,6 +4,7 @@
#include <string.h>
#include <unistd.h>
#include <locale.h>
#include <assert.h>
#include <strings.h>
#include <pthread.h>
#include <semaphore.h>
Expand Down Expand Up @@ -475,14 +476,13 @@ drawpalette(struct notcurses* nc){
}

static int
infoplane_notcurses(struct notcurses* nc, const fetched_info* fi, int planeheight){
infoplane_notcurses(struct notcurses* nc, const fetched_info* fi,
int planeheight, int nextline){
const int planewidth = 72;
unsigned dimy;
unsigned y;
struct ncplane* std = notcurses_stddim_yx(nc, &dimy, NULL);
ncplane_cursor_yx(std, &y, NULL);
struct ncplane_options nopts = {
.y = y,
.y = nextline,
.x = NCALIGN_CENTER,
.rows = planeheight,
.cols = planewidth,
Expand Down Expand Up @@ -573,6 +573,11 @@ infoplane_notcurses(struct notcurses* nc, const fetched_info* fi, int planeheigh
ncchannels_set_bg_rgb8(&channels, 0x50, 0x50, 0x50);
ncplane_set_base(infop, " ", 0, channels);
ncplane_scrollup_child(std, infop);
int parend = ncplane_abs_y(std) + ncplane_dim_y(std) - 1; // where parent ends
int chend = ncplane_abs_y(infop) + ncplane_dim_y(infop) - 1; // where child ends
if(chend > parend){
ncplane_move_rel(infop, -(chend - parend), 0);
}
ncplane_putchar(std, '\n');
if(notcurses_render(nc)){
return -1;
Expand All @@ -581,14 +586,15 @@ infoplane_notcurses(struct notcurses* nc, const fetched_info* fi, int planeheigh
}

static int
infoplane(struct notcurses* nc, const fetched_info* fi){
infoplane(struct notcurses* nc, const fetched_info* fi, int nextline){
const int planeheight = 7;
int r = infoplane_notcurses(nc, fi, planeheight);
int r = infoplane_notcurses(nc, fi, planeheight, nextline);
r |= notcurses_stop(nc);
return r;
}

struct marshal {
int nextline; // line following display plane, where info plane ought be placed
struct notcurses* nc;
const distro_info* dinfo;
const char* logo; // read from /etc/os-release (or builtin), may be NULL
Expand Down Expand Up @@ -640,9 +646,9 @@ neologo_present(struct notcurses* nc, const char* nlogo){
ncplane_set_fg_default(n);
ncplane_set_styles(n, NCSTYLE_BOLD | NCSTYLE_ITALIC);
if(notcurses_canopen_images(nc)){
ncplane_putstr_aligned(n, -1, NCALIGN_CENTER, "(no image file is known for your distro)");
ncplane_putstr_aligned(n, -1, NCALIGN_CENTER, "(no image file is known for your distro)\n");
}else{
ncplane_putstr_aligned(n, -1, NCALIGN_CENTER, "(notcurses was compiled without image support)");
ncplane_putstr_aligned(n, -1, NCALIGN_CENTER, "(notcurses was compiled without image support)\n");
}
ncplane_off_styles(n, NCSTYLE_BOLD | NCSTYLE_ITALIC);
return notcurses_render(nc);
Expand Down Expand Up @@ -687,8 +693,7 @@ display_thread(void* vmarshal){
ncplane_move_yx(iplane, y, x);
ncplane_scrollup_child(notcurses_stdplane(m->nc), iplane);
notcurses_render(m->nc);
ncplane_cursor_move_yx(notcurses_stdplane(m->nc),
ncplane_abs_y(iplane) + ncplane_dim_y(iplane), 0);
m->nextline = ncplane_abs_y(iplane) + ncplane_dim_y(iplane);
return NULL;
}
}
Expand All @@ -698,6 +703,9 @@ display_thread(void* vmarshal){
return NULL;
}
}
unsigned nl;
ncplane_cursor_yx(notcurses_stdplane(m->nc), &nl, NULL);
m->nextline = nl;
return NULL;
}

Expand Down Expand Up @@ -731,6 +739,7 @@ ncneofetch(struct notcurses* nc){
.dinfo = fi.distro,
.logo = fi.logo,
.neologo = fi.neologo,
.nextline = -1,
};
pthread_t tid;
const bool launched = !pthread_create(&tid, NULL, display_thread, &display_marshal);
Expand All @@ -747,7 +756,8 @@ ncneofetch(struct notcurses* nc){
if(launched){
pthread_join(tid, NULL);
}
if(infoplane(nc, &fi)){
assert(display_marshal.nextline >= 0);
if(infoplane(nc, &fi, display_marshal.nextline)){
free_fetched_info(&fi);
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/internal.h
Expand Up @@ -1810,6 +1810,7 @@ cancel_and_join(const char* name, pthread_t tid, void** res){

static inline int
emit_scrolls(const tinfo* ti, int count, fbuf* f){
logdebug("emitting %d scrolls\n", count);
if(count > 1){
const char* indn = get_escape(ti, ESCAPE_INDN);
if(indn){
Expand All @@ -1836,7 +1837,6 @@ emit_scrolls(const tinfo* ti, int count, fbuf* f){
// tracking in |nc|
static inline int
emit_scrolls_track(notcurses* nc, int count, fbuf* f){
logdebug("emitting %d scrolls\n", count);
if(emit_scrolls(&nc->tcache, count, f)){
return -1;
}
Expand Down
7 changes: 2 additions & 5 deletions src/lib/notcurses.c
Expand Up @@ -1639,14 +1639,12 @@ int ncplane_scrollup_child(ncplane* n, const ncplane* child){
logerror("child plane is fixed\n");
return -1;
}
int parend = ncplane_abs_y(n) + ncplane_dim_y(n); // where parent ends
int chend = ncplane_abs_y(child) + ncplane_dim_y(child); // where child ends
fprintf(stderr, "CHEND: %d PAREND: %d\n", chend, parend);
int parend = ncplane_abs_y(n) + ncplane_dim_y(n) - 1; // where parent ends
int chend = ncplane_abs_y(child) + ncplane_dim_y(child) - 1; // where child ends
if(chend <= parend){
return 0;
}
int r = chend - parend; // how many rows we need scroll parent
fprintf(stderr, "SCROLLING %d\n", r);
int ret = ncplane_scrollup(n, r);
return ret;
}
Expand Down Expand Up @@ -2175,7 +2173,6 @@ move_bound_planes(ncplane* n, int dy, int dx){
}

int ncplane_move_yx(ncplane* n, int y, int x){
fprintf(stderr, "MOVE PLANE TO %d/%d\n", y, x);
if(n == ncplane_notcurses(n)->stdplane){
return -1;
}
Expand Down

0 comments on commit b0bd292

Please sign in to comment.