From 2e6b07081e5ddb1ecff45b5c1f0f8d4000b89802 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 14 Feb 2021 18:38:28 -0500 Subject: [PATCH] ncplayer: -k will use direct mode #1342 --- doc/man/man1/ncplayer.1.md | 3 ++- src/player/play.cpp | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/doc/man/man1/ncplayer.1.md b/doc/man/man1/ncplayer.1.md index 6c77795db..e7e809b1c 100644 --- a/doc/man/man1/ncplayer.1.md +++ b/doc/man/man1/ncplayer.1.md @@ -38,7 +38,7 @@ be any non-negative number. **-L**: Loop frames until a key is pressed. -**-k**: Inhibit use of the alternate screen. Necessary if you want the output left on your terminal after the program exits. +**-k**: Use direct mode (see **notcurses_direct(3)**). This will have the effect of leaving the output on-screen after program exit, and generating it inline (rather than clearing the screen and placing it at the top). **-q**: Print neither frame/timing information along the top of the screen, nor the output summary on exit. @@ -79,6 +79,7 @@ fixed-width font with good coverage of the Unicode Block Drawing Characters. # SEE ALSO **notcurses(3)**, +**notcurses_direct(3)**, **notcurses_visual(3)**, **terminfo(5)**, **unicode(7)** diff --git a/src/player/play.cpp b/src/player/play.cpp index 2bf963c32..94064b039 100644 --- a/src/player/play.cpp +++ b/src/player/play.cpp @@ -22,7 +22,7 @@ void usage(std::ostream& o, const char* name, int exitcode){ o << " -h: display help and exit with success\n"; o << " -V: print program name and version\n"; o << " -q: be quiet (no frame/timing information along top of screen)\n"; - o << " -k: don't use the alternate screen\n"; + o << " -k: use direct mode rather than rendered mode\n"; o << " -L: loop frames\n"; o << " -t seconds: delay t seconds after each file\n"; o << " -l loglevel: integer between 0 and 9, goes to stderr'\n"; @@ -259,6 +259,13 @@ auto handle_opts(int argc, char** argv, notcurses_options& opts, bool* quiet, return optind; } +int direct_mode_player(int argc, char** argv, bool quiet, float timescale, + ncscale_e scalemode, ncblitter_e blitter, + float displaytime, bool loop){ + // FIXME + return 0; +} + auto main(int argc, char** argv) -> int { if(setlocale(LC_ALL, "") == nullptr){ std::cerr << "Couldn't set locale based off LANG\n"; @@ -272,6 +279,15 @@ auto main(int argc, char** argv) -> int { bool loop = false; auto nonopt = handle_opts(argc, argv, ncopts, &quiet, ×cale, &scalemode, &blitter, &displaytime, &loop); + // if -k was provided, we now use direct mode rather than simply not using the + // alternate screen, so that output is inline with the shell. + if(ncopts.flags & NCOPTION_NO_ALTERNATE_SCREEN){ + if(direct_mode_player(argc, argv, quiet, timescale, scalemode, blitter, displaytime, loop)){ + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } + // no -k, we're using full rendered mode (and the alternate screen). ncopts.flags |= NCOPTION_INHIBIT_SETLOCALE; if(quiet){ ncopts.flags |= NCOPTION_SUPPRESS_BANNERS; @@ -296,9 +312,7 @@ auto main(int argc, char** argv) -> int { failed = true; break; } - if(!(ncopts.flags & NCOPTION_NO_ALTERNATE_SCREEN)){ - stdn->erase(); - } + stdn->erase(); struct ncvisual_options vopts{}; int r; vopts.n = *stdn;