notcurses_options: fold bools into flags

This commit is contained in:
nick black 2020-06-07 05:08:46 -04:00
parent e2b43092c3
commit b2dcc50606
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
44 changed files with 74 additions and 100 deletions

View File

@ -2,6 +2,8 @@ This document attempts to list user-visible changes and any major internal
rearrangements of Notcurses.
* 1.5.0 (not yet released)
* The various `bool`s of `struct notcurses_options` have been folded into
that `struct`'s `flags` field. Each `bool` has its own `NCOPTION_`.
* Added a Pixel API for working directly with the contents of `ncvisual`s,
including `ncvisual_at_yx()` and `ncvisual_set_yx()`.

View File

@ -840,7 +840,34 @@ typedef enum {
// prior to notcurses_init(), you should not set this bit. Even if you are
// invoking setlocale(), this behavior shouldn't be an issue unless you're
// doing something weird (setting a locale not based on LANG).
#define NCOPTION_INHIBIT_SETLOCALE 0x0001
#define NCOPTION_INHIBIT_SETLOCALE 0x0001
// Checking for Sixel support requires writing an escape, and then reading an
// inline reply from the terminal. Since this can interact poorly with actual
// user input, it's not done unless Sixel will actually be used. Set this flag
// to unconditionally test for Sixel support in notcurses_init().
#define NCOPTION_VERIFY_SIXEL 0x0002
// We typically install a signal handler for SIGWINCH that generates a resize
// event in the notcurses_getc() queue. Set to inhibit this handler.
#define NCOPTION_NO_WINCH_SIGHANDLER 0x0004
// We typically install a signal handler for SIG{INT, SEGV, ABRT, QUIT} that
// restores the screen, and then calls the old signal handler. Set to inhibit
// registration of these signal handlers.
#define NCOPTION_NO_QUIT_SIGHANDLERS 0x0008
// By default, we hide the cursor if possible. This flag inhibits use of
// the civis capability, retaining the cursor.
#define NCOPTION_RETAIN_CURSOR 0x0010
// Notcurses typically prints version info in notcurses_init() and performance
// info in notcurses_stop(). This inhibits that output.
#define NCOPTION_SUPPRESS_BANNERS 0x0020
// If smcup/rmcup capabilities are indicated, notcurses defaults to making use
// of the "alternate screen". This flag inhibits use of smcup/rmcup.
#define NCOPTION_NO_ALTERNATE_SCREEN 0x0040
// Configuration for notcurses_init().
typedef struct notcurses_options {
@ -848,22 +875,6 @@ typedef struct notcurses_options {
// the environment variable TERM is used. Failure to open the terminal
// definition will result in failure to initialize notcurses.
const char* termtype;
// If smcup/rmcup capabilities are indicated, notcurses defaults to making
// use of the "alternate screen". This flag inhibits use of smcup/rmcup.
bool inhibit_alternate_screen;
// By default, we hide the cursor if possible. This flag inhibits use of
// the civis capability, retaining the cursor.
bool retain_cursor;
// Notcurses typically prints version info in notcurses_init() and performance
// info in notcurses_stop(). This inhibits that output.
bool suppress_banner;
// We typically install a signal handler for SIG{INT, SEGV, ABRT, QUIT} that
// restores the screen, and then calls the old signal handler. Set to inhibit
// registration of these signal handlers.
bool no_quit_sighandlers;
// We typically install a signal handler for SIGWINCH that generates a resize
// event in the notcurses_getc() queue. Set to inhibit this handler.
bool no_winch_sighandler;
// If non-NULL, notcurses_render() will write each rendered frame to this
// FILE* in addition to outfp. This is used primarily for debugging.
FILE* renderfp;
@ -878,7 +889,7 @@ typedef struct notcurses_options {
// General flags; see NCOPTION_*. This is expressed as a bitfield so that
// future options can be added without reshaping the struct. Undefined bits
// must be set to 0.
unsigned flags;
uint64_t flags;
} notcurses_options;
// Lex a margin argument according to the standard notcurses definition. There

View File

@ -65,22 +65,6 @@ typedef struct notcurses_options {
// the environment variable TERM is used. Failure to open the terminal
// definition will result in failure to initialize notcurses.
const char* termtype;
// If smcup/rmcup capabilities are indicated, notcurses defaults to making
// use of the "alternate screen". This flag inhibits use of smcup/rmcup.
bool inhibit_alternate_screen;
// By default, we hide the cursor if possible. This flag inhibits use of
// the civis capability, retaining the cursor.
bool retain_cursor;
// Notcurses typically prints version info in notcurses_init() and performance
// info in notcurses_stop(). This inhibits that output.
bool suppress_banner;
// We typically install a signal handler for SIG{INT, SEGV, ABRT, QUIT} that
// restores the screen, and then calls the old signal handler. Set to inhibit
// registration of these signal handlers.
bool no_quit_sighandlers;
// We typically install a signal handler for SIGWINCH that generates a resize
// event in the notcurses_getc() queue. Set to inhibit this handler.
bool no_winch_sighandler;
// If non-NULL, notcurses_render() will write each rendered frame to this
// FILE* in addition to outfp. This is used primarily for debugging.
FILE* renderfp;
@ -95,7 +79,7 @@ typedef struct notcurses_options {
// General flags; see NCOPTION_*. This is expressed as a bitfield so that
// future options can be added without reshaping the struct. Undefined bits
// must be set to 0.
unsigned flags;
uint64_t flags;
} notcurses_options;
struct notcurses* notcurses_init(const notcurses_options*, FILE*);
int notcurses_lex_margins(const char* op, notcurses_options* opts);

View File

@ -12,8 +12,10 @@
// works on a scrolling plane
static int
allglyphs(struct notcurses* nc, struct ncplane* column, int legendy){
// some of these cause major problems with Kitty, if not others, due to
// heavy duty beating on freetype FIXME reenable when reasonable
const int valid_planes[] = {
0, 1, 2, 3, 14, 15, 16, -1
0, 1, /*2,*/ 3, 14, /*15, 16,*/ -1
};
struct ncplane* std = notcurses_stdplane(nc);
const int dimx = ncplane_dim_x(column);
@ -74,13 +76,13 @@ int allglyphs_demo(struct notcurses* nc){
}
}
struct ncplane* column = ncplane_aligned(n, height, width,
(dimy - height) / 2,
(dimy - height) / 2 + 1,
NCALIGN_CENTER, NULL);
if(column == NULL){
return -1;
}
ncplane_set_scrolling(column, true);
int r = allglyphs(nc, column, dimy - 2);
int r = allglyphs(nc, column, 2);
ncplane_destroy(column);
return r;
}

View File

@ -242,7 +242,7 @@ handle_opts(int argc, char** argv, notcurses_options* opts, bool* ignore_failure
*ignore_failures = true;
break;
case 'k':
opts->inhibit_alternate_screen = true;
opts->flags |= NCOPTION_NO_ALTERNATE_SCREEN;
break;
case 'f':
if(opts->renderfp){
@ -479,7 +479,7 @@ int main(int argc, char** argv){
if(dimy < MIN_SUPPORTED_ROWS || dimx < MIN_SUPPORTED_COLS){
goto err;
}
if(nopts.inhibit_alternate_screen){ // no one cares. 1s max.
if((nopts.flags & NCOPTION_NO_ALTERNATE_SCREEN)){ // no one cares. 1s max.
if(demodelay.tv_sec >= 1){
sleep(1);
}else{

View File

@ -735,6 +735,10 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
fprintf(stderr, "Provided an illegal negative margin, refusing to start\n");
return NULL;
}
if(opts->flags > NCOPTION_NO_ALTERNATE_SCREEN){
fprintf(stderr, "Provided an illegal Notcurses option, refusing to start\n");
return NULL;
}
notcurses* ret = malloc(sizeof(*ret));
if(ret == NULL){
return ret;
@ -815,7 +819,9 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
free(ret);
return NULL;
}
if(setup_signals(ret, opts->no_quit_sighandlers, opts->no_winch_sighandler)){
if(setup_signals(ret,
(opts->flags & NCOPTION_NO_QUIT_SIGHANDLERS),
(opts->flags & NCOPTION_NO_WINCH_SIGHANDLER))){
goto err;
}
int termerr;
@ -827,9 +833,10 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
if(update_term_dimensions(ret->ttyfd, &dimy, &dimx)){
goto err;
}
ret->suppress_banner = opts->flags & NCOPTION_SUPPRESS_BANNERS;
char* shortname_term = termname();
char* longname_term = longname();
if(!opts->suppress_banner){
if(!ret->suppress_banner){
fprintf(stderr, "Term: %dx%d %s (%s)\n", dimy, dimx,
shortname_term ? shortname_term : "?",
longname_term ? longname_term : "?");
@ -842,7 +849,7 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
goto err;
}
// Neither of these is supported on e.g. the "linux" virtual console.
if(!opts->inhibit_alternate_screen){
if(!(opts->flags & NCOPTION_NO_ALTERNATE_SCREEN)){
term_verify_seq(&ret->tcache.smcup, "smcup");
term_verify_seq(&ret->tcache.rmcup, "rmcup");
}
@ -857,7 +864,7 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
free_plane(ret->top);
goto err;
}
if(!opts->retain_cursor){
if(!(opts->flags & NCOPTION_RETAIN_CURSOR)){
if(ret->tcache.civis && term_emit("civis", ret->tcache.civis, ret->ttyfp, true)){
free_plane(ret->top);
goto err;
@ -868,7 +875,6 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
goto err;
}
ret->rstate.x = ret->rstate.y = -1;
ret->suppress_banner = opts->suppress_banner;
init_banner(ret);
// flush on the switch to alternate screen, lest initial output be swept away
if(ret->tcache.smcup && term_emit("smcup", ret->tcache.smcup, ret->ttyfp, true)){

View File

@ -5,11 +5,6 @@ using namespace ncpp;
notcurses_options NotCurses::default_notcurses_options = {
/* termtype */ nullptr,
/* inhibit_alternate_screen */ false,
/* retain_cursor */ false,
/* suppress_bannner */ false,
/* no_quit_sighandlers */ false,
/* no_winch_sighandler */ false,
/* renderfp */ nullptr,
/* loglevel */ NCLogLevel::Silent,
/* margin_t */ 0,

View File

@ -111,7 +111,7 @@ void parse_args(int argc, char** argv, struct notcurses_options* opts,
break;
}
}
opts->suppress_banner = true;
opts->flags |= NCOPTION_SUPPRESS_BANNERS;
}
int runreels(NotCurses& nc, ncreel_options& nopts){

View File

@ -13,8 +13,7 @@ int main(int argc, char** argv){
return EXIT_FAILURE;
}
struct notcurses_options nopts = {
.flags = NCOPTION_INHIBIT_SETLOCALE,
.inhibit_alternate_screen = true,
.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&nopts, NULL);
struct ncplane* std = notcurses_stdplane(nc);

View File

@ -11,8 +11,7 @@ using namespace ncpp;
auto main() -> int {
setlocale(LC_ALL, "");
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
nopts.flags |= NCOPTION_INHIBIT_SETLOCALE;
nopts.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN;
NotCurses nc(nopts);
std::unique_ptr<Plane> n (nc.get_stdplane());
int dimx, dimy;

View File

@ -42,8 +42,7 @@ int main(int argc, char** argv){
}
setlocale(LC_ALL, "");
notcurses_options opts = {
.inhibit_alternate_screen = true,
.flags = NCOPTION_INHIBIT_SETLOCALE,
.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
struct ncplane* n = notcurses_stdplane(nc);

View File

@ -3,7 +3,7 @@
int main(void){
struct notcurses_options nopts = {
.inhibit_alternate_screen = true,
.flags = NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&nopts, NULL);
if(nc == NULL){

View File

@ -11,8 +11,7 @@ int main(void){
return EXIT_FAILURE;
}
struct notcurses_options opts = {
.inhibit_alternate_screen = true,
.flags = NCOPTION_INHIBIT_SETLOCALE,
.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
if(nc == NULL){

View File

@ -29,8 +29,7 @@ auto main() -> int {
return EXIT_FAILURE;
}
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
nopts.flags = NCOPTION_INHIBIT_SETLOCALE;
nopts.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN;
NotCurses nc(nopts);
const char c[] =

View File

@ -42,8 +42,7 @@ int main(int argc, char** argv){
}
setlocale(LC_ALL, "");
notcurses_options opts = {
.inhibit_alternate_screen = true,
.flags = NCOPTION_INHIBIT_SETLOCALE,
.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
if(nc == NULL){

View File

@ -16,8 +16,7 @@ int main(int argc, char** argv){
file = argv[1];
}
notcurses_options opts{};
opts.inhibit_alternate_screen = true;
opts.flags = NCOPTION_INHIBIT_SETLOCALE;
opts.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN;
struct notcurses* nc;
if((nc = notcurses_init(&opts, nullptr)) == nullptr){
return EXIT_FAILURE;

View File

@ -9,8 +9,7 @@ int main(void){
return EXIT_FAILURE;
}
struct notcurses_options opts = {
.inhibit_alternate_screen = true,
.flags = NCOPTION_INHIBIT_SETLOCALE,
.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&opts, NULL);
if(nc == NULL){

View File

@ -9,8 +9,7 @@ auto main() -> int {
return EXIT_FAILURE;
}
notcurses_options opts{};
opts.inhibit_alternate_screen = true;
opts.flags = NCOPTION_INHIBIT_SETLOCALE;
opts.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN;
struct notcurses* nc = notcurses_init(&opts, nullptr);
if(nc == nullptr){
return EXIT_FAILURE;

View File

@ -221,8 +221,7 @@ rotate(struct notcurses* nc){
int main(void){
setlocale(LC_ALL, "");
struct notcurses_options nopts = {
.inhibit_alternate_screen = true,
.flags = NCOPTION_INHIBIT_SETLOCALE,
.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&nopts, NULL);
int r = 0;

View File

@ -13,8 +13,7 @@ using namespace ncpp;
auto main() -> int {
setlocale(LC_ALL, "");
notcurses_options nopts{};
nopts.inhibit_alternate_screen = true;
nopts.flags = NCOPTION_INHIBIT_SETLOCALE;
nopts.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN;
NotCurses nc(nopts);
std::shared_ptr<Plane> n(nc.get_stdplane());
int dimx, dimy;

View File

@ -20,9 +20,8 @@ int main(int argc, char** argv){
file = argv[1];
}
notcurses_options opts{};
opts.inhibit_alternate_screen = true;
opts.loglevel = NCLOGLEVEL_TRACE;
opts.flags = NCOPTION_INHIBIT_SETLOCALE;
opts.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN;
struct notcurses* nc;
if((nc = notcurses_init(&opts, nullptr)) == nullptr){
return EXIT_FAILURE;

View File

@ -4,8 +4,7 @@
int main(void){
setlocale(LC_ALL, "");
struct notcurses_options nops = {
.inhibit_alternate_screen = true,
.flags = NCOPTION_INHIBIT_SETLOCALE,
.flags = NCOPTION_INHIBIT_SETLOCALE | NCOPTION_NO_ALTERNATE_SCREEN,
};
struct notcurses* nc = notcurses_init(&nops, NULL);
struct ncplane* n = notcurses_stdplane(nc);

View File

@ -142,7 +142,7 @@ auto handle_opts(int argc, char** argv, notcurses_options& opts,
}
break;
case 'k':{
opts.inhibit_alternate_screen = true;
opts.flags |= NCOPTION_NO_ALTERNATE_SCREEN;
break;
}case 'm':{
if(opts.margin_t || opts.margin_r || opts.margin_b || opts.margin_l){

View File

@ -6,8 +6,7 @@ TEST_CASE("Cell") {
return;
}
// common initialization
notcurses_options nopts{};
nopts.suppress_banner = true;
TestOptions nopts{};
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -29,7 +29,6 @@ auto fadeaborter(struct notcurses* nc, struct ncplane* ncp,
TEST_CASE("Fade") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -50,7 +50,6 @@ auto testfdeofdestroys(struct ncfdplane* n, int fderrno, void* curry) -> int {
TEST_CASE("FdsAndSubprocs"
* doctest::description("Fdplanes and subprocedures")) {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -7,7 +7,6 @@ TEST_CASE("Fills") {
return;
}
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -3,7 +3,6 @@
TEST_CASE("Geometry") {
notcurses_options nopts{};
nopts.suppress_banner = true;
notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -2,7 +2,6 @@
TEST_CASE("NotcursesInput") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -12,4 +12,11 @@
auto find_data(const char* datum) -> char*;
auto enforce_utf8() -> bool;
class TestOptions : public notcurses_options {
public:
TestOptions() {
flags = NCOPTION_SUPPRESS_BANNERS;
}
};
#endif

View File

@ -4,7 +4,6 @@
TEST_CASE("MenuTest") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -22,7 +22,6 @@ TEST_CASE("NCPlane") {
return;
}
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -6,7 +6,6 @@
TEST_CASE("NotcursesBase") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -2,7 +2,6 @@
TEST_CASE("Palette256") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -8,7 +8,6 @@ TEST_CASE("Plot") {
return;
}
notcurses_options nopts{};
nopts.suppress_banner = true;
auto nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -4,7 +4,6 @@
TEST_CASE("Readers") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -13,7 +13,6 @@ auto panelcb(struct nctablet* t, int begx, int begy, int maxx, int maxy, bool cl
TEST_CASE("Reels") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -2,7 +2,6 @@
TEST_CASE("Resize") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -31,7 +31,6 @@ TEST_CASE("Rotate") {
return;
}
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -5,7 +5,6 @@
TEST_CASE("Scrolling") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -4,7 +4,6 @@
TEST_CASE("Selectors") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -3,7 +3,6 @@
TEST_CASE("Visual") {
notcurses_options nopts{};
nopts.suppress_banner = true;
notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -8,7 +8,6 @@ TEST_CASE("Wide") {
return;
}
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;

View File

@ -4,7 +4,6 @@
TEST_CASE("ZAxis") {
notcurses_options nopts{};
nopts.suppress_banner = true;
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
if(!nc_){
return;