[ncplayer] nc.stop() before exception print

This commit is contained in:
nick black 2021-03-22 01:16:29 -04:00 committed by Nick Black
parent 086c151ac8
commit 5e2911d590

View File

@ -319,35 +319,15 @@ int direct_mode_player(int argc, char** argv, ncscale_e scalemode,
return failed ? -1 : 0;
}
int rendered_mode_player(int argc, char** argv, ncscale_e scalemode,
ncblitter_e blitter, notcurses_options& ncopts,
int rendered_mode_player_inner(NotCurses& nc, int argc, char** argv,
ncscale_e scalemode, ncblitter_e blitter,
bool quiet, bool loop,
double timescale, double displaytime){
// no -k, we're using full rendered mode (and the alternate screen).
ncopts.flags |= NCOPTION_INHIBIT_SETLOCALE;
if(quiet){
ncopts.flags |= NCOPTION_SUPPRESS_BANNERS;
}
NotCurses nc{ncopts};
if(!nc.can_open_images()){
nc.stop();
std::cerr << "Notcurses was compiled without multimedia support\n";
return EXIT_FAILURE;
}
int dimy, dimx;
bool failed = false;
{
std::unique_ptr<Plane> stdn(nc.get_stdplane(&dimy, &dimx));
for(auto i = 0 ; i < argc ; ++i){
std::unique_ptr<Visual> ncv;
try{
ncv = std::make_unique<Visual>(argv[i]);
}catch(std::exception& e){
// FIXME want to stop nc first :/ can't due to stdn, ugh
std::cerr << argv[i] << ": " << e.what() << "\n";
failed = true;
break;
}
stdn->erase();
struct ncvisual_options vopts{};
int r;
@ -376,15 +356,13 @@ int rendered_mode_player(int argc, char** argv, ncscale_e scalemode,
if(displaytime < 0){
stdn->printf(0, NCAlign::Center, "press key to advance");
if(!nc.render()){
failed = true;
break;
return -1;
}
char32_t ie = nc.getc(true);
if(ie == (char32_t)-1){
failed = true;
break;
return -1;
}else if(ie == 'q'){
goto done;
return 0;
}else if(ie == 'L'){
--i;
nc.refresh(nullptr, nullptr);
@ -394,8 +372,7 @@ int rendered_mode_player(int argc, char** argv, ncscale_e scalemode,
}else if(ie == NCKey::Resize){
--i; // rerun with the new size
if(!nc.refresh(&dimy, &dimx)){
failed = true;
break;
return -1;
}
}
}else{
@ -412,16 +389,40 @@ int rendered_mode_player(int argc, char** argv, ncscale_e scalemode,
}while(loop && r == 0);
if(r < 0){ // positive is intentional abort
std::cerr << "Error decoding " << argv[i] << std::endl;
failed = true;
break;
return -1;
}
}
return 0;
}
int rendered_mode_player(int argc, char** argv, ncscale_e scalemode,
ncblitter_e blitter, notcurses_options& ncopts,
bool quiet, bool loop,
double timescale, double displaytime){
// no -k, we're using full rendered mode (and the alternate screen).
ncopts.flags |= NCOPTION_INHIBIT_SETLOCALE;
if(quiet){
ncopts.flags |= NCOPTION_SUPPRESS_BANNERS;
}
NotCurses nc{ncopts};
if(!nc.can_open_images()){
nc.stop();
std::cerr << "Notcurses was compiled without multimedia support\n";
return EXIT_FAILURE;
}
int r;
try{
r = rendered_mode_player_inner(nc, argc, argv, scalemode, blitter,
quiet, loop, timescale, displaytime);
}catch(std::exception& e){
nc.stop();
std::cerr << e.what() << "\n";
return -1;
}
done:
if(!nc.stop()){
return -1;
}
return failed;
return r;
}
auto main(int argc, char** argv) -> int {