From a0afbdfb15c8c350a7ee3e221f9450305caddb98 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 17 Oct 2020 19:52:19 -0400 Subject: [PATCH] notcurses-view: support -b to select blitter #1063 --- doc/man/man1/notcurses-view.1.md | 3 +++ src/view/view.cpp | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/man/man1/notcurses-view.1.md b/doc/man/man1/notcurses-view.1.md index 518a7b3eb..44bfa5a1b 100644 --- a/doc/man/man1/notcurses-view.1.md +++ b/doc/man/man1/notcurses-view.1.md @@ -23,6 +23,9 @@ and videos to a terminal. Media will be scaled to the terminal's size. **-s scalemode**: Scaling mode, one of **none**, **scale**, or **stretch**. +**-b blitter**: Blitter, one of **ascii**, **halfblocks**, **quadblitter**, +or **braille**. + **-m margins**: Define rendering margins (see below). **-k**: Inhibit use of the alternate screen. Necessary if you want the output left on your terminal after the program exits. diff --git a/src/view/view.cpp b/src/view/view.cpp index 5b0e39413..47ce842f9 100644 --- a/src/view/view.cpp +++ b/src/view/view.cpp @@ -21,6 +21,7 @@ void usage(std::ostream& o, const char* name, int exitcode){ o << " -k: don't use the alternate screen\n"; o << " -l loglevel: integer between 0 and 9, goes to stderr'\n"; o << " -s scaletype: one of 'none', 'scale', or 'stretch'\n"; + o << " -b blitter: one of 'ascii', 'halfblock', 'quadblitter' or 'braille'\n"; o << " -m margins: margin, or 4 comma-separated margins\n"; o << " -d mult: non-negative floating point scale for frame time" << std::endl; exit(exitcode); @@ -142,11 +143,12 @@ auto perframe(struct ncvisual* ncv, struct ncvisual_options* vopts, // can exit() directly. returns index in argv of first non-option param. auto handle_opts(int argc, char** argv, notcurses_options& opts, - float* timescale, ncscale_e* scalemode) -> int { + float* timescale, ncscale_e* scalemode, ncblitter_e* blitter) + -> int { *timescale = 1.0; *scalemode = NCSCALE_STRETCH; int c; - while((c = getopt(argc, argv, "hl:d:s:m:k")) != -1){ + while((c = getopt(argc, argv, "hl:d:s:b:m:k")) != -1){ switch(c){ case 'h': usage(std::cout, argv[0], EXIT_SUCCESS); @@ -158,6 +160,13 @@ auto handle_opts(int argc, char** argv, notcurses_options& opts, usage(std::cerr, argv[0], EXIT_FAILURE); } break; + case 'b': + if(notcurses_lex_blitter(optarg, blitter)){ + std::cerr << "Invalid blitter specification (got " + << optarg << ")" << std::endl; + usage(std::cerr, argv[0], EXIT_FAILURE); + } + break; case 'k':{ opts.flags |= NCOPTION_NO_ALTERNATE_SCREEN; break; @@ -216,7 +225,8 @@ auto main(int argc, char** argv) -> int { float timescale; ncscale_e scalemode; notcurses_options nopts{}; - auto nonopt = handle_opts(argc, argv, nopts, ×cale, &scalemode); + ncblitter_e blitter = NCBLIT_DEFAULT; + auto nonopt = handle_opts(argc, argv, nopts, ×cale, &scalemode, &blitter); nopts.flags |= NCOPTION_INHIBIT_SETLOCALE; NotCurses nc{nopts}; if(!nc.can_open_images()){ @@ -224,7 +234,6 @@ auto main(int argc, char** argv) -> int { std::cerr << "Notcurses was compiled without multimedia support\n"; return EXIT_FAILURE; } - ncblitter_e blitter = NCBLIT_DEFAULT; int dimy, dimx; bool failed = false; {