[metric] prefix all defs with NC

This commit is contained in:
nick black 2021-11-08 20:09:28 -05:00 committed by nick black
parent c20e859a6d
commit 12e01fdf5c
11 changed files with 117 additions and 106 deletions

View File

@ -16,6 +16,8 @@ rearrangements of Notcurses.
was reimplemented as a trivial wrapper around `ncnmetric()`.
* `qprefix()`, `bprefix()`, and `iprefix()` have been renamed
`ncqprefix()`, `ncbprefix()`, and `nciprefix()`, respectively.
All related constants have been prefixed with `NC`, and the old
definitions will be removed for abi3.
The former forms have been deprecated, and will be removed in abi3.
* `notcurses_mice_enable()` and `notcurses_mouse_disable()` replace
`notcurses_mouse_enable()` and `notcurses_mouse_disable()`, which

View File

@ -11,16 +11,16 @@ notcurses_metric - fixed-width numeric output with metric suffixes
**#include <notcurses/notcurses.h>**
```c
#define PREFIXCOLUMNS 7
#define IPREFIXCOLUMNS 8
#define BPREFIXCOLUMNS 9
#define PREFIXSTRLEN (PREFIXCOLUMNS + 1)
#define IPREFIXSTRLEN (IPREFIXCOLUMNS + 1)
#define BPREFIXSTRLEN (BPREFIXCOLUMNS + 1)
#define NCPREFIXCOLUMNS 7
#define NCIPREFIXCOLUMNS 8
#define NCBPREFIXCOLUMNS 9
#define NCPREFIXSTRLEN (NCPREFIXCOLUMNS + 1)
#define NCIPREFIXSTRLEN (NCIPREFIXCOLUMNS + 1)
#define NCBPREFIXSTRLEN (NCBPREFIXCOLUMNS + 1)
#define NCMETRICFWIDTH(x, cols) ((int)(strlen(x) - ncstrwidth(x) + (cols)))
#define PREFIXFMT(x) NCMETRICFWIDTH((x), PREFIXCOLUMNS), (x)
#define IPREFIXFMT(x) NCMETRIXFWIDTH((x), IPREFIXCOLUMNS), (x)
#define BPREFIXFMT(x) NCMETRICFWIDTH((x), BPREFIXCOLUMNS), (x)
#define NCPREFIXFMT(x) NCMETRICFWIDTH((x), NCPREFIXCOLUMNS), (x)
#define NCIPREFIXFMT(x) NCMETRIXFWIDTH((x), NCIPREFIXCOLUMNS), (x)
#define NCBPREFIXFMT(x) NCMETRICFWIDTH((x), NCBPREFIXCOLUMNS), (x)
```
**const char* ncmetric(uintmax_t ***val***, uintmax_t ***decimal***, char* ***buf***, int ***omitdec***, unsigned ***mult***, int ***uprefix***);**
@ -36,8 +36,8 @@ notcurses_metric - fixed-width numeric output with metric suffixes
**ncmetric** (and the helper wrappers **qprefix** and **bprefix**) accept
very large (or very small) non-negative numbers, and prepare formatted output
of a maximum width using metric suffixes. The suffix can represent arbitrary
amounts of growth, but is designed for 1000 (**PREFIX**) or 1024
(**IPREFIX**). 1024 is used for "digital units of information", i.e. kibibytes
amounts of growth, but is designed for 1000 (**NCPREFIX**) or 1024
(**NCIPREFIX**). 1024 is used for "digital units of information", i.e. kibibytes
and gibibits. **ncmetric** supports the large suffixes KMGTPEZY (Kilo, Mega,
Giga, Tera, Peta, Exa, Zetta, and Yotta) and the small suffixes mµnpfazy
(Milli, Micro, Nano, Pico, Femto, Atto, Zepto, and Yocto). This covers the
@ -49,26 +49,26 @@ a 64-bit **uintmax_t**.
should be larger than **val**. The output will be written to **buf**, which
must be at least:
* **PREFIXSTRLEN** + 1 bytes for a 1000-based value
* **IPREFIXSTRLEN** + 1 bytes for a 1024-based value
* **BPREFIXSTRLEN** + 1 bytes for a 1024-based value with an 'i' suffix
* **NCPREFIXSTRLEN** + 1 bytes for a 1000-based value
* **NCIPREFIXSTRLEN** + 1 bytes for a 1024-based value
* **NCBPREFIXSTRLEN** + 1 bytes for a 1024-based value with an 'i' suffix
Three helper functions are provided to simplify these common cases:
```
// Mega, kilo, gigafoo. Use PREFIXSTRLEN + 1 and PREFIXCOLUMNS.
// Mega, kilo, gigafoo. Use NCPREFIXSTRLEN + 1 and NCPREFIXCOLUMNS.
static inline const char*
ncqprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
return ncmetric(val, decimal, buf, omitdec, 1000, '\0');
}
// Mibi, kebi, gibibytes sans 'i' suffix. Use IPREFIXSTRLEN + 1.
// Mibi, kebi, gibibytes sans 'i' suffix. Use NCIPREFIXSTRLEN + 1.
static inline const char*
nciprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
return ncmetric(val, decimal, buf, omitdec, 1024, '\0');
}
// Mibi, kebi, gibibytes. Use BPREFIXSTRLEN + 1 and BPREFIXCOLUMNS.
// Mibi, kebi, gibibytes. Use NCBPREFIXSTRLEN + 1 and NCBPREFIXCOLUMNS.
static inline const char*
ncbprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
return ncmetric(val, decimal, buf, omitdec, 1024, 'i');
@ -86,9 +86,9 @@ bytes, since Unicode doesn't necessarily map to single-byte characters
(including the 'µ' micro suffix). The corresponding defines for maximum column
length are:
* **PREFIXCOLUMNS** (7)
* **IPREFIXCOLUMNS** (8)
* **BPREFIXCOLUMNS** (9)
* **NCPREFIXCOLUMNS** (7)
* **NCIPREFIXCOLUMNS** (8)
* **NCBPREFIXCOLUMNS** (9)
In general, the maximum-width output will take the form **CCC.mmMu**, where C
are digits of the characteristic (up to ceil(log10(**mult**)) digits), the
@ -101,15 +101,15 @@ Three more defines are provided to simplify formatted fixed-width output using
the results of **ncmetric**. Each of these macros accepts a character buffer
holding the result of the call, and expand to *two* arguments:
* **PREFIXFMT(x)**
* **IPREFIXFMT(x)**
* **BPREFIXFMT(x)**
* **NCPREFIXFMT(x)**
* **NCIPREFIXFMT(x)**
* **NCBPREFIXFMT(x)**
These can be used in e.g. the following ungainly fashion:
**ncplane_printf(n, "%*s", PREFIXFMT(buf));**
**ncplane_printf(n, "%*s", NCPREFIXFMT(buf));**
to ensure that the output is always **PREFIXCOLUMNS** wide.
to ensure that the output is always **NCPREFIXCOLUMNS** wide.
# RETURN VALUES

View File

@ -3374,25 +3374,25 @@ API const char* ncnmetric(uintmax_t val, size_t s, uintmax_t decimal,
__attribute__ ((nonnull (4)));
// The number of columns is one fewer, as the STRLEN expressions must leave
// an extra byte open in case 'µ' (U+00B5, 0xC2 0xB5) shows up. PREFIXCOLUMNS
// an extra byte open in case 'µ' (U+00B5, 0xC2 0xB5) shows up. NCPREFIXCOLUMNS
// is the maximum number of columns used by a mult == 1000 (standard)
// ncmetric() call. IPREFIXCOLUMNS is the maximum number of columns used by a
// mult == 1024 (digital information) ncmetric(). BPREFIXSTRLEN is the maximum
// ncmetric() call. NCIPREFIXCOLUMNS is the maximum number of columns used by a
// mult == 1024 (digital information) ncmetric(). NCBPREFIXSTRLEN is the maximum
// number of columns used by a mult == 1024 call making use of the 'i' suffix.
// This is the true number of columns; to set up a printf()-style maximum
// field width, you should use [IB]PREFIXFMT (see below).
#define PREFIXCOLUMNS 7
#define IPREFIXCOLUMNS 8
#define BPREFIXCOLUMNS 9
#define PREFIXSTRLEN (PREFIXCOLUMNS + 1) // Does not include a '\0' (xxx.xxU)
#define IPREFIXSTRLEN (IPREFIXCOLUMNS + 1) // Does not include a '\0' (xxxx.xxU)
#define BPREFIXSTRLEN (BPREFIXCOLUMNS + 1) // Does not include a '\0' (xxxx.xxUi), i == prefix
// field width, you should use NC[IB]PREFIXFMT (see below).
#define NCPREFIXCOLUMNS 7
#define NCIPREFIXCOLUMNS 8
#define NCBPREFIXCOLUMNS 9
#define NCPREFIXSTRLEN (NCPREFIXCOLUMNS + 1) // Does not include a '\0' (xxx.xxU)
#define NCIPREFIXSTRLEN (NCIPREFIXCOLUMNS + 1) // Does not include a '\0' (xxxx.xxU)
#define NCBPREFIXSTRLEN (NCBPREFIXCOLUMNS + 1) // Does not include a '\0' (xxxx.xxUi), i == prefix
// Used as arguments to a variable field width (i.e. "%*s" -- these are the *).
// We need this convoluted grotesquery to properly handle 'µ'.
#define NCMETRICFWIDTH(x, cols) ((int)(strlen(x) - ncstrwidth(x) + (cols)))
#define PREFIXFMT(x) NCMETRICFWIDTH((x), PREFIXCOLUMNS), (x)
#define IPREFIXFMT(x) NCMETRIXFWIDTH((x), IPREFIXCOLUMNS), (x)
#define BPREFIXFMT(x) NCMETRICFWIDTH((x), BPREFIXCOLUMNS), (x)
#define NCPREFIXFMT(x) NCMETRICFWIDTH((x), NCPREFIXCOLUMNS), (x)
#define NCIPREFIXFMT(x) NCMETRIXFWIDTH((x), NCIPREFIXCOLUMNS), (x)
#define NCBPREFIXFMT(x) NCMETRICFWIDTH((x), NCBPREFIXCOLUMNS), (x)
// Mega, kilo, gigafoo. Use PREFIXSTRLEN + 1 and PREFIXCOLUMNS.
static inline const char*
@ -4310,6 +4310,16 @@ bprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
return ncmetric(val, decimal, buf, omitdec, 1024, 'i');
}
#define PREFIXCOLUMNS 7
#define IPREFIXCOLUMNS 8
#define BPREFIXCOLUMNS 9
#define PREFIXSTRLEN (PREFIXCOLUMNS + 1) // Does not include a '\0' (xxx.xxU)
#define IPREFIXSTRLEN (IPREFIXCOLUMNS + 1) // Does not include a '\0' (xxxx.xxU)
#define BPREFIXSTRLEN (BPREFIXCOLUMNS + 1) // Does not include a '\0' (xxxx.xxUi), i == prefix
#define PREFIXFMT(x) NCMETRICFWIDTH((x), PREFIXCOLUMNS), (x)
#define IPREFIXFMT(x) NCMETRIXFWIDTH((x), IPREFIXCOLUMNS), (x)
#define BPREFIXFMT(x) NCMETRICFWIDTH((x), BPREFIXCOLUMNS), (x)
#undef API
#undef ALLOC

View File

@ -404,9 +404,9 @@ summary_table(struct notcurses* nc, const char* spec, bool canimage, bool canvid
table_segment(n, "%a", "");
table_segment(n, "%w", "");
table_segment(n, "TheoFPS", "\n══╤════════╤════════╪═══════╪═════════╪═══════╪══╪══╪══╪═══════╣\n");
char timebuf[PREFIXSTRLEN + 1];
char tfpsbuf[PREFIXSTRLEN + 1];
char totalbuf[BPREFIXSTRLEN + 1];
char timebuf[NCPREFIXSTRLEN + 1];
char tfpsbuf[NCPREFIXSTRLEN + 1];
char totalbuf[NCBPREFIXSTRLEN + 1];
uint64_t nsdelta = 0;
for(size_t i = 0 ; i < strlen(spec) ; ++i){
nsdelta += results[i].timens;
@ -437,7 +437,7 @@ summary_table(struct notcurses* nc, const char* spec, bool canimage, bool canvid
ncplane_printf(n, "%8s", demos[results[i].selector - 'a'].name);
ncplane_set_fg_rgb8(n, 178, 102, 255);
ncplane_printf(n, "│%*ss│%7" PRIu64 "│%*s│%7.1f│%2" PRId64 "│%2" PRId64 "│%2" PRId64 "│%*s║",
PREFIXFMT(timebuf), results[i].stats.renders, BPREFIXFMT(totalbuf),
NCPREFIXFMT(timebuf), results[i].stats.renders, NCBPREFIXFMT(totalbuf),
results[i].timens ?
results[i].stats.renders / ((double)results[i].timens / NANOSECS_IN_SEC) : 0.0,
(results[i].timens ?
@ -446,7 +446,7 @@ summary_table(struct notcurses* nc, const char* spec, bool canimage, bool canvid
results[i].stats.raster_ns * 100 / results[i].timens : 0),
(results[i].timens ?
results[i].stats.writeout_ns * 100 / results[i].timens : 0),
PREFIXFMT(tfpsbuf));
NCPREFIXFMT(tfpsbuf));
ncplane_set_fg_rgb(n, rescolor);
ncplane_printf(n, "%s\n", results[i].result < 0 ? "FAILED" :
results[i].result > 0 ? "ABORTED" :
@ -463,9 +463,9 @@ summary_table(struct notcurses* nc, const char* spec, bool canimage, bool canvid
ncbprefix(totalbytes, 1, totalbuf, 0);
table_segment(n, "", "══╧════════╧════════╪═══════╪═════════╪═══════╧══╧══╧══╧═══════╝\n");
ncplane_putstr(n, " ");
table_printf(n, "", "%*ss", PREFIXFMT(timebuf));
table_printf(n, "", "%*ss", NCPREFIXFMT(timebuf));
table_printf(n, "", "%7lu", totalframes);
table_printf(n, "", "%*s", BPREFIXFMT(totalbuf));
table_printf(n, "", "%*s", NCBPREFIXFMT(totalbuf));
//table_printf(nc, "│", "%7.1f", nsdelta ? totalframes / ((double)nsdelta / NANOSECS_IN_SEC) : 0);
ncplane_putchar(n, '\n');
ncplane_set_fg_rgb8(n, 0xfe, 0x20, 0x76); // PANTONE Strong Red C + 3x0x20

View File

@ -392,7 +392,7 @@ hud_print_finished(elem* list){
if(ncplane_printf_yx(hud, line, 1, "%d", e->frames) < 0){
return -1;
}
char buf[PREFIXCOLUMNS + 2];
char buf[NCPREFIXCOLUMNS + 2];
ncnmetric(e->totalns, sizeof(buf), NANOSECS_IN_SEC, buf, 0, 1000, '\0');
for(int x = 6 ; x < 14 - ncstrwidth(buf) ; ++x){
nccell ci = CELL_TRIVIAL_INITIALIZER;
@ -612,7 +612,7 @@ int demo_render(struct notcurses* nc){
if(ncplane_printf_yx(hud, 1, 1, "%d", elems->frames) < 0){
return -1;
}
char buf[PREFIXCOLUMNS + 2];
char buf[NCPREFIXCOLUMNS + 2];
ncnmetric(ns, sizeof(buf), NANOSECS_IN_SEC, buf, 0, 1000, '\0');
for(int x = 6 ; x < 14 - ncstrwidth(buf) ; ++x){
nccell ci = CELL_TRIVIAL_INITIALIZER;

View File

@ -430,7 +430,7 @@ infoplane_notcurses(struct notcurses* nc, const fetched_info* fi, int planeheigh
#if defined(__linux__)
struct sysinfo sinfo;
sysinfo(&sinfo);
char totalmet[BPREFIXSTRLEN + 1], usedmet[BPREFIXSTRLEN + 1];
char totalmet[NCBPREFIXSTRLEN + 1], usedmet[NCBPREFIXSTRLEN + 1];
ncbprefix(sinfo.totalram, 1, totalmet, 1);
ncbprefix(sinfo.totalram - sinfo.freeram, 1, usedmet, 1);
ncplane_printf_aligned(infop, 2, NCALIGN_RIGHT, "Processes: %hu ", sinfo.procs);
@ -439,7 +439,7 @@ infoplane_notcurses(struct notcurses* nc, const fetched_info* fi, int planeheigh
uint64_t ram;
size_t oldlenp = sizeof(ram);
if(sysctlbyname("hw.memsize", &ram, &oldlenp, NULL, 0) == 0){
char tram[BPREFIXSTRLEN + 1];
char tram[NCBPREFIXSTRLEN + 1];
bprefix(ram, 1, tram, 1);
ncplane_printf_aligned(infop, 2, NCALIGN_LEFT, " RAM: %sB", tram);
}

View File

@ -661,9 +661,8 @@ bool ncmenu_offer_input(ncmenu* n, const ncinput* nc){
// we can't actually select menu items in this function, since we need to
// invoke an arbitrary function as a result.
if(nc->id == NCKEY_BUTTON1 && nc->evtype == NCTYPE_RELEASE){
int y, x;
y = nc->y;
x = nc->x;
int y = nc->y;
int x = nc->x;
unsigned dimy, dimx;
ncplane_dim_yx(n->ncp, &dimy, &dimx);
if(!ncplane_translate_abs(n->ncp, &y, &x)){

View File

@ -31,7 +31,7 @@ typedef struct ncplot {
outside these bounds are counted, but the displayed range covers only this. */
unsigned slotcount;
int slotstart; /* index of most recently-written slot */
bool labelaxisd; /* label dependent axis (consumes PREFIXCOLUMNS columns) */
bool labelaxisd; /* label dependent axis (consumes NCPREFIXCOLUMNS columns) */
bool exponentiali; /* exponential independent axis */
bool detectdomain; /* is domain detection in effect (stretch the domain)? */
bool detectonlymax; /* domain detection applies only to max, not min */
@ -114,7 +114,7 @@ int redraw_pixelplot_##T(nc##X##plot* ncp){ \
}else{ \
interval = ncp->maxy < ncp->miny ? 0 : (ncp->maxy - ncp->miny) / ((double)dimy * states); \
} \
const int startx = ncp->plot.labelaxisd ? PREFIXCOLUMNS : 0; /* plot cols begin here */ \
const int startx = ncp->plot.labelaxisd ? NCPREFIXCOLUMNS : 0; /* plot cols begin here */ \
/* if we want fewer slots than there are available columns, our final column \
will be other than the plane's final column. most recent x goes here. */ \
const unsigned finalx = (ncp->plot.slotcount < scaleddim - 1 - (startx * scale) ? \
@ -124,7 +124,7 @@ int redraw_pixelplot_##T(nc##X##plot* ncp){ \
/* show the *top* of each interval range */ \
for(unsigned y = 0 ; y < dimy ; ++y){ \
ncplane_set_channels(ncp->plot.ncp, ncp->plot.channels[y * states]); \
char buf[PREFIXSTRLEN + 1]; \
char buf[NCPREFIXSTRLEN + 1]; \
if(ncp->plot.exponentiali){ \
if(y == dimy - 1){ /* we cheat on the top row to exactly match maxy */ \
ncmetric(ncp->maxy * 100, 100, buf, 0, 1000, '\0'); \
@ -136,15 +136,15 @@ int redraw_pixelplot_##T(nc##X##plot* ncp){ \
} \
if(y == dimy - 1 && strlen(ncp->plot.title)){ \
ncplane_printf_yx(ncp->plot.ncp, dimy - y - 1, 0, "%*.*s %s", \
PREFIXSTRLEN, PREFIXSTRLEN, buf, ncp->plot.title); \
NCPREFIXSTRLEN, NCPREFIXSTRLEN, buf, ncp->plot.title); \
}else{ \
ncplane_printf_yx(ncp->plot.ncp, dimy - y - 1, 0, "%*.*s", \
PREFIXSTRLEN, PREFIXSTRLEN, buf); \
NCPREFIXSTRLEN, NCPREFIXSTRLEN, buf); \
} \
} \
}else if(strlen(ncp->plot.title)){ \
ncplane_set_channels(ncp->plot.ncp, ncp->plot.channels[(dimy - 1) * states]); \
ncplane_printf_yx(ncp->plot.ncp, 0, PREFIXCOLUMNS - strlen(ncp->plot.title), "%s", ncp->plot.title); \
ncplane_printf_yx(ncp->plot.ncp, 0, NCPREFIXCOLUMNS - strlen(ncp->plot.title), "%s", ncp->plot.title); \
} \
ncplane_set_styles(ncp->plot.ncp, NCSTYLE_NONE); \
if((int)finalx < startx){ /* exit on pathologically narrow planes */ \
@ -284,7 +284,7 @@ int redraw_plot_##T(nc##X##plot* ncp){ \
}else{ \
interval = ncp->maxy < ncp->miny ? 0 : (ncp->maxy - ncp->miny) / ((double)dimy * states); \
} \
const int startx = ncp->plot.labelaxisd ? PREFIXCOLUMNS : 0; /* plot cols begin here */ \
const int startx = ncp->plot.labelaxisd ? NCPREFIXCOLUMNS : 0; /* plot cols begin here */ \
/* if we want fewer slots than there are available columns, our final column \
will be other than the plane's final column. most recent x goes here. */ \
const unsigned finalx = (ncp->plot.slotcount < scaleddim - 1 - (startx * scale) ? \
@ -294,7 +294,7 @@ int redraw_plot_##T(nc##X##plot* ncp){ \
/* show the *top* of each interval range */ \
for(unsigned y = 0 ; y < dimy ; ++y){ \
ncplane_set_channels(ncp->plot.ncp, ncp->plot.channels[y]); \
char buf[PREFIXSTRLEN + 1]; \
char buf[NCPREFIXSTRLEN + 1]; \
if(ncp->plot.exponentiali){ \
if(y == dimy - 1){ /* we cheat on the top row to exactly match maxy */ \
ncmetric(ncp->maxy * 100, 100, buf, 0, 1000, '\0'); \
@ -305,14 +305,14 @@ int redraw_plot_##T(nc##X##plot* ncp){ \
ncmetric((ncp->maxy - interval * states * (dimy - y - 1)) * 100, 100, buf, 0, 1000, '\0'); \
} \
if(y == dimy - 1 && strlen(ncp->plot.title)){ \
ncplane_printf_yx(ncp->plot.ncp, dimy - y - 1, PREFIXCOLUMNS - strlen(buf), "%s %s", buf, ncp->plot.title); \
ncplane_printf_yx(ncp->plot.ncp, dimy - y - 1, NCPREFIXCOLUMNS - strlen(buf), "%s %s", buf, ncp->plot.title); \
}else{ \
ncplane_printf_yx(ncp->plot.ncp, dimy - y - 1, PREFIXCOLUMNS - strlen(buf), "%s", buf); \
ncplane_printf_yx(ncp->plot.ncp, dimy - y - 1, NCPREFIXCOLUMNS - strlen(buf), "%s", buf); \
} \
} \
}else if(strlen(ncp->plot.title)){ \
ncplane_set_channels(ncp->plot.ncp, ncp->plot.channels[dimy - 1]); \
ncplane_printf_yx(ncp->plot.ncp, 0, PREFIXCOLUMNS - strlen(ncp->plot.title), "%s", ncp->plot.title); \
ncplane_printf_yx(ncp->plot.ncp, 0, NCPREFIXCOLUMNS - strlen(ncp->plot.title), "%s", ncp->plot.title); \
} \
ncplane_set_styles(ncp->plot.ncp, NCSTYLE_NONE); \
if((int)finalx < startx){ /* exit on pathologically narrow planes */ \
@ -482,7 +482,7 @@ create_##T(nc##X##plot* ncpp, ncplane* n, const ncplot_options* opts, const T mi
/* if we're sizing the plot based off the plane dimensions, scale it by the \
plot geometry's width for all calculations */ \
const unsigned scaleddim = dimx * (bset->geom == NCBLIT_PIXEL ? ncplane_notcurses(n)->tcache.cellpixx : bset->width); \
const unsigned scaledprefixlen = PREFIXCOLUMNS * (bset->geom == NCBLIT_PIXEL ? ncplane_notcurses(n)->tcache.cellpixx : bset->width); \
const unsigned scaledprefixlen = NCPREFIXCOLUMNS * (bset->geom == NCBLIT_PIXEL ? ncplane_notcurses(n)->tcache.cellpixx : bset->width); \
if((ncpp->plot.slotcount = ncpp->plot.rangex) == 0){ \
ncpp->plot.slotcount = scaleddim; \
} \

View File

@ -197,7 +197,7 @@ int ncreader_write_egc(ncreader* n, const char* egc){
}
++n->xproject;
}
}else if((unsigned)n->ncp->x >= n->ncp->lenx){
}else if(n->ncp->x >= n->ncp->lenx){
++n->xproject;
}
// use ncplane_putegc on both planes because it'll get cursor movement right

View File

@ -166,10 +166,10 @@ void summarize_stats(notcurses* nc){
clreol = "";
}
const ncstats *stats = &nc->stashed_stats;
char totalbuf[BPREFIXSTRLEN + 1];
char minbuf[BPREFIXSTRLEN + 1];
char maxbuf[BPREFIXSTRLEN + 1];
char avgbuf[BPREFIXSTRLEN + 1];
char totalbuf[NCBPREFIXSTRLEN + 1];
char minbuf[NCBPREFIXSTRLEN + 1];
char maxbuf[NCBPREFIXSTRLEN + 1];
char avgbuf[NCBPREFIXSTRLEN + 1];
if(stats->renders){
ncqprefix(stats->render_ns, NANOSECS_IN_SEC, totalbuf, 0);
ncqprefix(stats->render_min_ns, NANOSECS_IN_SEC, minbuf, 0);

View File

@ -26,7 +26,7 @@ TEST_CASE("Metric") {
REQUIRE(0 == fesetround(FE_TONEAREST));
SUBCASE("CornerInts") {
char buf[PREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
impericize_ncmetric(0, 1, buf, 0, 1000, '\0');
CHECK(!strcmp("0.00", buf));
impericize_ncmetric(0, 1, buf, 0, 1024, 'i');
@ -74,7 +74,7 @@ TEST_CASE("Metric") {
}
SUBCASE("Maxints") {
char buf[PREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
// FIXME these will change based on the size of intmax_t and uintmax_t
impericize_ncmetric(INTMAX_MAX - 1, 1, buf, 0, 1000, '\0');
CHECK(!strcmp("9.22E", buf));
@ -87,7 +87,7 @@ TEST_CASE("Metric") {
}
SUBCASE("Maxints1024") {
char buf[PREFIXSTRLEN + 1], gold[PREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1], gold[NCPREFIXSTRLEN + 1];
// FIXME these will change based on the size of intmax_t and uintmax_t
REQUIRE(ncmetric(((double)(INTMAX_MAX - 1ull)), 1, buf, 0, 1024, 'i'));
sprintf(gold, "%.2fEi", ((double)(INTMAX_MAX - 1ull)) / (1ull << 60));
@ -110,8 +110,8 @@ TEST_CASE("Metric") {
const char suffixes[] = "\0KMGTPE";
SUBCASE("PowersOfTen") {
char gold[PREFIXSTRLEN + 1];
char buf[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t goldval = 1;
uintmax_t val = 1;
size_t i = 0;
@ -133,8 +133,8 @@ TEST_CASE("Metric") {
}
SUBCASE("PowersOfTenNoDec") {
char gold[PREFIXSTRLEN + 1];
char buf[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t goldval = 1;
uintmax_t val = 1;
size_t i = 0;
@ -156,8 +156,8 @@ TEST_CASE("Metric") {
}
SUBCASE("PowersOfTwo") {
char gold[BPREFIXSTRLEN + 1];
char buf[BPREFIXSTRLEN + 1];
char gold[NCBPREFIXSTRLEN + 1];
char buf[NCBPREFIXSTRLEN + 1];
uintmax_t goldval = 1;
uintmax_t val = 1;
size_t i = 0;
@ -179,8 +179,8 @@ TEST_CASE("Metric") {
}
SUBCASE("PowersOfTwoNoDec") {
char gold[BPREFIXSTRLEN + 1];
char buf[BPREFIXSTRLEN + 1];
char gold[NCBPREFIXSTRLEN + 1];
char buf[NCBPREFIXSTRLEN + 1];
uintmax_t goldval = 1;
uintmax_t val = 1;
size_t i = 0;
@ -202,8 +202,8 @@ TEST_CASE("Metric") {
}
SUBCASE("PowersOfTwoAsTens") {
char gold[PREFIXSTRLEN + 1];
char buf[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t vfloor = 1;
uintmax_t val = 1;
size_t i = 0;
@ -225,8 +225,8 @@ TEST_CASE("Metric") {
}
SUBCASE("PowersOfTenAsTwos") {
char gold[BPREFIXSTRLEN + 1];
char buf[BPREFIXSTRLEN + 1];
char gold[NCBPREFIXSTRLEN + 1];
char buf[NCBPREFIXSTRLEN + 1];
uintmax_t vfloor = 1;
uintmax_t val = 1;
size_t i = 0;
@ -248,8 +248,8 @@ TEST_CASE("Metric") {
}
SUBCASE("PowersOfTenMinusOne") {
char gold[PREFIXSTRLEN + 1];
char buf[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t vfloor = 1;
uintmax_t val = 1;
size_t i = 0;
@ -271,8 +271,8 @@ TEST_CASE("Metric") {
}
SUBCASE("PowersOfTenPlusOne") {
char gold[PREFIXSTRLEN + 1];
char buf[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t vfloor = 1;
uintmax_t val = 1;
size_t i = 0;
@ -294,8 +294,8 @@ TEST_CASE("Metric") {
}
SUBCASE("PowersOfTenMinusOneAsTwos") {
char gold[BPREFIXSTRLEN + 1];
char buf[BPREFIXSTRLEN + 1];
char gold[NCBPREFIXSTRLEN + 1];
char buf[NCBPREFIXSTRLEN + 1];
uintmax_t vfloor = 1;
uintmax_t val = 1;
size_t i = 0;
@ -323,9 +323,9 @@ TEST_CASE("Metric") {
// nanoseconds, but want output in seconds.
// This requires 'decimal' = GIG.
SUBCASE("ScaledGigSupra") {
char gold[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
snprintf(gold, sizeof(gold), "%.2f", 9.029); // 9.02
char buf[PREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t val = 9027854993;
uintmax_t decimal = GIG;
REQUIRE(ncqprefix(val, decimal, buf, 0));
@ -333,9 +333,9 @@ TEST_CASE("Metric") {
}
SUBCASE("ScaledGigUnity") {
char gold[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
snprintf(gold, sizeof(gold), "%.2f", 1.0); // 1.00
char buf[PREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t decimal = GIG;
uintmax_t val = decimal;
REQUIRE(ncqprefix(val, decimal, buf, 0));
@ -343,9 +343,9 @@ TEST_CASE("Metric") {
}
SUBCASE("ScaledGigJustAbove") {
char gold[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
snprintf(gold, sizeof(gold), "%.2f", 1.0); // 1.00
char buf[PREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t val = 1000000001;
uintmax_t decimal = GIG;
REQUIRE(ncqprefix(val, decimal, buf, 0));
@ -353,9 +353,9 @@ TEST_CASE("Metric") {
}
SUBCASE("ScaledGigJustBelow") {
char gold[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
snprintf(gold, sizeof(gold), "%.2fm", 999.999); //999.99
char buf[PREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t val = 999999999;
uintmax_t decimal = GIG;
REQUIRE(ncqprefix(val, decimal, buf, 0));
@ -363,9 +363,9 @@ TEST_CASE("Metric") {
}
SUBCASE("ScaledGigSub") {
char gold[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
snprintf(gold, sizeof(gold), "%.2fm", 27.85); // 27.85
char buf[PREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t val = 27854993;
uintmax_t decimal = GIG;
REQUIRE(ncqprefix(val, decimal, buf, 0));
@ -373,9 +373,9 @@ TEST_CASE("Metric") {
}
SUBCASE("ScaledGigSubSub") {
char gold[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
snprintf(gold, sizeof(gold), "%.2fm", 7.85); // 7.85
char buf[PREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t val = 7854993;
uintmax_t decimal = GIG;
REQUIRE(ncqprefix(val, decimal, buf, 0));
@ -383,7 +383,7 @@ TEST_CASE("Metric") {
}
SUBCASE("SmallCorners") {
char buf[PREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
impericize_ncmetric(1, 1000, buf, 0, 1000, '\0');
CHECK(!strcmp("1.00m", buf));
impericize_ncmetric(1, 1024, buf, 0, 1024, 'i');
@ -431,8 +431,8 @@ TEST_CASE("Metric") {
}else{
smallsuffixes = L"yzafpnum";
}
char gold[PREFIXSTRLEN + 1];
char buf[PREFIXSTRLEN + 1];
char gold[NCPREFIXSTRLEN + 1];
char buf[NCPREFIXSTRLEN + 1];
uintmax_t goldval = 1;
uintmax_t val = 1;
size_t i = 0;
@ -456,7 +456,7 @@ TEST_CASE("Metric") {
// inspired by #929
SUBCASE("BigMult") {
char qbuf[IPREFIXSTRLEN + 1];
char qbuf[NCIPREFIXSTRLEN + 1];
CHECK(nullptr != impericize_ncmetric(1115614, 1000, qbuf, 0, 1000, '\0'));
CHECK(0 == strcmp("1.11K", qbuf));
CHECK(nullptr != impericize_ncmetric(372688, 1024, qbuf, 0, 1024, '\0'));