notcurses-view: support -b to select blitter #1063

This commit is contained in:
nick black 2020-10-17 19:52:19 -04:00
parent e6bc09084c
commit a0afbdfb15
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 16 additions and 4 deletions

View File

@ -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.

View File

@ -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, &timescale, &scalemode);
ncblitter_e blitter = NCBLIT_DEFAULT;
auto nonopt = handle_opts(argc, argv, nopts, &timescale, &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;
{