[hud] use ncmetric for elapsed time

This commit is contained in:
nick black 2021-11-07 07:02:38 -05:00 committed by nick black
parent 0231768406
commit 51e90ca7e9
6 changed files with 25 additions and 15 deletions

View File

@ -392,9 +392,13 @@ hud_print_finished(elem* list){
if(ncplane_printf_yx(hud, line, 1, "%d", e->frames) < 0){ if(ncplane_printf_yx(hud, line, 1, "%d", e->frames) < 0){
return -1; return -1;
} }
if(ncplane_printf_yx(hud, line, 7, "%"PRIu64".%03"PRIu64"s", char buf[PREFIXCOLUMNS];
e->totalns / NANOSECS_IN_SEC, ncmetric(e->totalns, NANOSECS_IN_SEC, buf, 0, 1000, '\0');
(e->totalns % NANOSECS_IN_SEC) / 1000000) < 0){ for(size_t x = 6 ; x < 14 - strlen(buf) ; ++x){
nccell ci = CELL_TRIVIAL_INITIALIZER;
ncplane_putc_yx(hud, 1, x, &ci);
}
if(ncplane_printf_yx(hud, line, 14 - strlen(buf), "%ss", buf) < 0){
return -1; return -1;
} }
if(ncplane_putstr_yx(hud, line, 16, e->name) < 0){ if(ncplane_putstr_yx(hud, line, 16, e->name) < 0){
@ -608,8 +612,13 @@ int demo_render(struct notcurses* nc){
if(ncplane_printf_yx(hud, 1, 1, "%d", elems->frames) < 0){ if(ncplane_printf_yx(hud, 1, 1, "%d", elems->frames) < 0){
return -1; return -1;
} }
if(ncplane_printf_yx(hud, 1, 7, "%"PRIu64".%03"PRIu64"s", ns / NANOSECS_IN_SEC, char buf[PREFIXCOLUMNS];
(ns % NANOSECS_IN_SEC) / 1000000) < 0){ ncmetric(ns, NANOSECS_IN_SEC, buf, 0, 1000, '\0');
for(size_t x = 6 ; x < 14 - strlen(buf) ; ++x){
nccell ci = CELL_TRIVIAL_INITIALIZER;
ncplane_putc_yx(hud, 1, x, &ci);
}
if(ncplane_printf_yx(hud, 1, 14 - strlen(buf), "%ss", buf) < 0){
return -1; return -1;
} }
if(ncplane_putstr_yx(hud, 1, 16, elems->name) < 0){ if(ncplane_putstr_yx(hud, 1, 16, elems->name) < 0){

View File

@ -3,7 +3,7 @@
static int y; static int y;
static int targy; static int targy;
static int xstart; static unsigned xstart;
static struct ncplane* on; static struct ncplane* on;
struct ncvisual_options vopts; struct ncvisual_options vopts;
@ -114,7 +114,7 @@ videothread(void* vnc){
} }
static struct ncplane* static struct ncplane*
outro_message(struct notcurses* nc, int* rows, int* cols){ outro_message(struct notcurses* nc, unsigned* rows, unsigned* cols){
const char str0[] = " ATL, baby! ATL! "; const char str0[] = " ATL, baby! ATL! ";
const char str1[] = " throw your hands in the air "; const char str1[] = " throw your hands in the air ";
const char* str2 = notcurses_canutf8(nc) ? " hack on! —dank❤ " : " hack on! --dank "; const char* str2 = notcurses_canutf8(nc) ? " hack on! —dank❤ " : " hack on! --dank ";
@ -207,7 +207,7 @@ int outro(struct notcurses* nc){
ncplane_set_name(vopts.n, "bnnr"); ncplane_set_name(vopts.n, "bnnr");
} }
xstart = cols; xstart = cols;
int ystart = rows; unsigned ystart = rows;
on = outro_message(nc, &ystart, &xstart); on = outro_message(nc, &ystart, &xstart);
if(on == NULL){ if(on == NULL){
return -1; return -1;

View File

@ -192,7 +192,7 @@ ncreel_demo_core(struct notcurses* nc){
tabletctx* tctxs = NULL; tabletctx* tctxs = NULL;
bool aborted = false; bool aborted = false;
int x = 8, y = 4; int x = 8, y = 4;
int dimy, dimx; unsigned dimy, dimx;
struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx); struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx);
struct ncplane_options nopts = { struct ncplane_options nopts = {
.y = y, .y = y,

View File

@ -25,7 +25,7 @@ fade_block(struct notcurses* nc, struct ncplane* nn, const struct timespec* subd
// negative row will result in vertical pbar on the left side // negative row will result in vertical pbar on the left side
static struct ncprogbar* static struct ncprogbar*
pbar_make(struct notcurses* nc, int row){ pbar_make(struct notcurses* nc, int row){
int dimx, dimy; unsigned dimx, dimy;
struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx); struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx);
struct ncplane_options nopts = { struct ncplane_options nopts = {
.y = row < 0 ? 4 : row, .y = row < 0 ? 4 : row,
@ -42,8 +42,9 @@ pbar_make(struct notcurses* nc, int row){
uint64_t channels = 0; uint64_t channels = 0;
ncchannels_set_bg_rgb(&channels, 0); ncchannels_set_bg_rgb(&channels, 0);
ncplane_set_base(pbar, "", 0, channels); ncplane_set_base(pbar, "", 0, channels);
int posy, posx, pdimy, pdimx; int posy, posx;
ncplane_yx(pbar, &posy, &posx); ncplane_yx(pbar, &posy, &posx);
unsigned pdimy, pdimx;
ncplane_dim_yx(pbar, &pdimy, &pdimx); ncplane_dim_yx(pbar, &pdimy, &pdimx);
ncplane_cursor_move_yx(std, posy - 1, posx - 1); ncplane_cursor_move_yx(std, posy - 1, posx - 1);
channels = 0; channels = 0;
@ -66,7 +67,7 @@ pbar_make(struct notcurses* nc, int row){
static int static int
draw_block(struct ncplane* nn, uint32_t blockstart){ draw_block(struct ncplane* nn, uint32_t blockstart){
int dimx, dimy; unsigned dimx, dimy;
ncplane_dim_yx(nn, &dimy, &dimx); ncplane_dim_yx(nn, &dimy, &dimx);
nccell ul = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER; nccell ul = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER;
nccell ll = CELL_TRIVIAL_INITIALIZER, lr = CELL_TRIVIAL_INITIALIZER; nccell ll = CELL_TRIVIAL_INITIALIZER, lr = CELL_TRIVIAL_INITIALIZER;
@ -207,7 +208,7 @@ int unicodeblocks_demo(struct notcurses* nc){
return 0; return 0;
} }
ncplane_greyscale(notcurses_stdplane(nc)); ncplane_greyscale(notcurses_stdplane(nc));
int pbarrow = 4 + BLOCKSIZE / CHUNKSIZE + 4; unsigned pbarrow = 4 + BLOCKSIZE / CHUNKSIZE + 4;
if(pbarrow > maxy - 2){ if(pbarrow > maxy - 2){
pbarrow = -1; pbarrow = -1;
} }

View File

@ -319,7 +319,7 @@ unicodedumper(struct ncplane* n, const char* indent){
uint64_t ul = NCCHANNELS_INITIALIZER(0xff, 0xff, 0xff, 0x19, 0x19, 0x70); uint64_t ul = NCCHANNELS_INITIALIZER(0xff, 0xff, 0xff, 0x19, 0x19, 0x70);
uint64_t ll = NCCHANNELS_INITIALIZER(0xff, 0xff, 0xff, 0x19, 0x19, 0x70); uint64_t ll = NCCHANNELS_INITIALIZER(0xff, 0xff, 0xff, 0x19, 0x19, 0x70);
ncplane_cursor_move_yx(n, y - 15, 0); ncplane_cursor_move_yx(n, y - 15, 0);
ncplane_stain(n, -1, -1, y - 1, 79, ul, ur, ll, lr); ncplane_stain(n, -1, -1, 15, 80, ul, ur, ll, lr);
ncplane_set_styles(n, NCSTYLE_BOLD | NCSTYLE_ITALIC); ncplane_set_styles(n, NCSTYLE_BOLD | NCSTYLE_ITALIC);
ncplane_cursor_move_yx(n, y - 12, 54); ncplane_cursor_move_yx(n, y - 12, 54);
wviz(n, L"🯁🯂🯃https://notcurses.com"); wviz(n, L"🯁🯂🯃https://notcurses.com");

View File

@ -24,7 +24,7 @@ typedef struct ncvisual {
uint32_t* data; // (scaled) RGBA image data, rowstride bytes per row uint32_t* data; // (scaled) RGBA image data, rowstride bytes per row
unsigned pixx, pixy; // pixel geometry, *not* cell geometry unsigned pixx, pixy; // pixel geometry, *not* cell geometry
// lines are sometimes padded. this many true bytes per row in data. // lines are sometimes padded. this many true bytes per row in data.
int rowstride; unsigned rowstride;
bool owndata; // we own data iff owndata == true bool owndata; // we own data iff owndata == true
} ncvisual; } ncvisual;