notcurses_view: accept -s option

pull/287/head
nick black 5 years ago committed by Nick Black
parent 56479fd777
commit 3bd0732e81

@ -8,7 +8,7 @@ notcurses-view - Render images and video to the console
# SYNOPSIS # SYNOPSIS
**notcurses-view** [**-h|--help**] [**-d delaymult**] [**-l loglevel**] files **notcurses-view** [**-h|--help**] [**-d delaymult**] [**-l loglevel**] [**-s scalemode**] files
# DESCRIPTION # DESCRIPTION
@ -21,6 +21,8 @@ and videos to the terminal. Media will be scaled to the terminal's size.
**-l loglevel**: Log everything (high log level) or nothing (log level 0) to stderr. **-l loglevel**: Log everything (high log level) or nothing (log level 0) to stderr.
**-s scalemode**: Scaling mode, one of **none**, **scale**, or **stretch**.
files: Select which files to render, and what order to render them in. files: Select which files to render, and what order to render them in.
# NOTES # NOTES

@ -106,6 +106,8 @@ notcurses_ncplane - operations on notcurses planes
**unsigned ncplane_styles(struct ncplane* n);** **unsigned ncplane_styles(struct ncplane* n);**
**void ncplane_greyscale(struct ncplane* n);**
## DESCRIPTION ## DESCRIPTION
Ncplanes are the fundamental drawing object of notcurses. All output functions Ncplanes are the fundamental drawing object of notcurses. All output functions

@ -1,4 +1,5 @@
#include <array> #include <array>
#include <cstring>
#include <cstdlib> #include <cstdlib>
#include <clocale> #include <clocale>
#include <sstream> #include <sstream>
@ -18,7 +19,10 @@ static void usage(std::ostream& os, const char* name, int exitcode)
__attribute__ ((noreturn)); __attribute__ ((noreturn));
void usage(std::ostream& o, const char* name, int exitcode){ void usage(std::ostream& o, const char* name, int exitcode){
o << "usage: " << name << " [ -h ] [ -l loglevel ] [ -d mult ] files" << '\n'; o << "usage: " << name << " [ -h ] [ -l loglevel ] [ -d mult ] [ -s scaletype ] files" << '\n';
o << " -l loglevel: integer between 0 and 9, goes to stderr'\n";
o << " -s scaletype: one of 'none', 'scale', or 'stretch'\n";
o << " -d mult: positive floating point scale for frame time" << std::endl;
exit(exitcode); exit(exitcode);
} }
@ -68,14 +72,25 @@ int perframe(struct notcurses* nc, struct ncvisual* ncv, void* vframecount){
} }
// can exit() directly. returns index in argv of first non-option param. // can exit() directly. returns index in argv of first non-option param.
int handle_opts(int argc, char** argv, notcurses_options* opts, float* timescale) { int handle_opts(int argc, char** argv, notcurses_options* opts, float* timescale,
ncscale_e *scalemode) {
*timescale = 1.0; *timescale = 1.0;
*scalemode = NCSCALE_SCALE;
int c; int c;
while((c = getopt(argc, argv, "hl:d:")) != -1){ while((c = getopt(argc, argv, "hl:d:s:")) != -1){
switch(c){ switch(c){
case 'h': case 'h':
usage(std::cout, argv[0], EXIT_SUCCESS); usage(std::cout, argv[0], EXIT_SUCCESS);
break; break;
case 's':
if(strcmp(optarg, "stretch") == 0){
*scalemode = NCSCALE_STRETCH;
}else if(strcmp(optarg, "scale") == 0){
*scalemode = NCSCALE_SCALE;
}else if(strcmp(optarg, "none") == 0){
*scalemode = NCSCALE_NONE;
}
break;
case 'd':{ case 'd':{
std::stringstream ss; std::stringstream ss;
ss << optarg; ss << optarg;
@ -118,7 +133,8 @@ int main(int argc, char** argv){
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
notcurses_options opts{}; notcurses_options opts{};
float timescale; float timescale;
auto nonopt = handle_opts(argc, argv, &opts, &timescale); ncscale_e stretchmode;
auto nonopt = handle_opts(argc, argv, &opts, &timescale, &stretchmode);
auto nc = notcurses_init(&opts, stdout); auto nc = notcurses_init(&opts, stdout);
if(nc == nullptr){ if(nc == nullptr){
return EXIT_FAILURE; return EXIT_FAILURE;
@ -135,7 +151,8 @@ int main(int argc, char** argv){
std::array<char, 128> errbuf; std::array<char, 128> errbuf;
int frames = 0; int frames = 0;
int averr; int averr;
auto ncv = ncplane_visual_open(ncp, argv[i], &averr); auto ncv = ncvisual_open_plane(nc, argv[i], &averr,
0, 0, stretchmode);
if(ncv == nullptr){ if(ncv == nullptr){
av_make_error_string(errbuf.data(), errbuf.size(), averr); av_make_error_string(errbuf.data(), errbuf.size(), averr);
notcurses_stop(nc); notcurses_stop(nc);
@ -161,7 +178,7 @@ int main(int argc, char** argv){
notcurses_stop(nc); notcurses_stop(nc);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if(ncplane_resize_simple(ncp, dimy, dimx)){ if(ncplane_resize_simple(ncvisual_plane(ncv), dimy, dimx)){
notcurses_stop(nc); notcurses_stop(nc);
return EXIT_FAILURE; return EXIT_FAILURE;
} }

Loading…
Cancel
Save