URI: 
       support a custom program run before every slide - catpoint - Catpoint simple presenting software.
  HTML git clone git://bitreich.org/catpoint/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/catpoint/
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit 89508a45aedca7ffde34fc4ac871c91f2e825652
   DIR parent a09f93d317d1d5a400e46806b0c066170632961a
  HTML Author: Josuah Demangeon <me@josuah.net>
       Date:   Fri,  9 Aug 2024 14:25:36 +0200
       
       support a custom program run before every slide
       
       Ignore transitions when hitting uppercase H, J, K, L
       This allows skipping quickly through the slides.
       
       The catpoint-wrap utility will prepend a to every text file:
       
           $ catpoint-wrap ./script.sh *.txt
       
       Signed-off-by: Josuah Demangeon <me@josuah.net>
       Signed-off-by: Christoph Lohmann <20h@r-36.net>
       
       Diffstat:
         M Makefile                            |       2 +-
         A catpoint-wrap                       |      11 +++++++++++
         M catpoint.1                          |      23 +++++++++++++++++++++++
         M catpoint.c                          |      74 +++++++++++++++++++++++++++----
         A showoff/random-animation.sh         |      12 ++++++++++++
       
       5 files changed, 113 insertions(+), 9 deletions(-)
       ---
   DIR diff --git a/Makefile b/Makefile
       @@ -19,7 +19,7 @@ CATPOINT_LDFLAGS = ${LDFLAGS} -lncursesw
        
        SRC = ${NAME}.c
        MAN1 = ${NAME}.1
       -BIN = ${NAME}
       +BIN = ${NAME} catpoint-animation
        OBJ = ${SRC:.c=.o}
        
        all: catpoint
   DIR diff --git a/catpoint-wrap b/catpoint-wrap
       @@ -0,0 +1,11 @@
       +#!/bin/sh -e
       +
       +animation_script=$1
       +shift
       +
       +for slide; do
       +    set -- "$@" "$animation_script" "$slide"
       +    shift
       +done
       +
       +exec ./catpoint "$@"
   DIR diff --git a/catpoint.1 b/catpoint.1
       @@ -12,6 +12,7 @@
        reads text files from the
        .Ar files
        arguments and prints them to the terminal.
       +If the file is executable, it is run with the next slides as an argument.
        The slides can be navigated with keybinds.
        .Sh KEYBINDS
        .Bl -tag -width Ds
       @@ -21,6 +22,8 @@ Quit
        Go to next slide.
        .It h, k, ARROW LEFT, ARROW UP, PAGE UP
        Go to previous slide.
       +.It L, J, H, K
       +Go to next/previous slide without transition.
        .It ., u, BEGIN KEY, HOME KEY
        Go to the first slide.
        .It i, END KEY
       @@ -37,6 +40,26 @@ Quit
        .It SIGWINCH
        Redraw the current slide contents.
        .El
       +.Sh EXAMPLES
       +Present all the text files in the current directory:
       +.Pp
       +.Dl $ catpoint *.txt
       +.Pp
       +Run the
       +.Pa ./run.sh
       +executable before the slide
       +.Pa 2.txt
       +and
       +.Pa 5.txt
       +while rendering all the others normally:
       +.Pp
       +.Dl $ catpoint 1.txt ./run.sh 2.txt 3.txt 4.txt ./run.sh 5.txt
       +.Pp
       +Insert
       +.Pa ./run.sh
       +before every text file so that it runs on each slide:
       +.Pp
       +.Dl $ catpoint-wrap ./run.sh *.txt
        .Sh EXIT STATUS
        .Ex -std
        .Sh SEE ALSO
   DIR diff --git a/catpoint.c b/catpoint.c
       @@ -3,6 +3,7 @@
        #include <sys/mman.h>
        #include <sys/stat.h>
        #include <sys/types.h>
       +#include <sys/wait.h>
        
        #include <curses.h>
        #include <errno.h>
       @@ -33,6 +34,18 @@ unloadcurrentslide(void)
        }
        
        void
       +setupwin(void)
       +{
       +        initscr();
       +        cbreak();
       +        noecho();
       +        nonl();
       +        intrflush(stdscr, FALSE);
       +        keypad(stdscr, TRUE);
       +        curs_set(FALSE); /* hide cursor */
       +}
       +
       +void
        cleanup(void)
        {
                unloadcurrentslide();
       @@ -70,6 +83,29 @@ quit(int sig)
        }
        
        void
       +executeslide(char **argv)
       +{
       +        pid_t pid;
       +
       +        endwin();
       +
       +        fprintf(stderr, "\x1b[H\x1b[J");
       +        fflush(stderr);
       +
       +        switch ((pid = fork())) {
       +        case 0:
       +                execvp(argv[0], argv);
       +        case -1:
       +                perror(argv[0]);
       +                break;
       +        default:
       +                waitpid(pid, NULL, 0);
       +        }
       +
       +        setupwin();
       +}
       +
       +void
        loadcurrentslide(char **argv, int slide)
        {
                struct stat statbuf;
       @@ -133,6 +169,7 @@ main(int argc, char *argv[])
                        errno = 0;
                        die("usage: %s file ...", argv[0]);
                }
       +
                slidefiles = ++argv;
                nslides = --argc;
        
       @@ -145,13 +182,7 @@ main(int argc, char *argv[])
                currentslidelen = 0;
        
                /* init curses */
       -        initscr();
       -        cbreak();
       -        noecho();
       -        nonl();
       -        intrflush(stdscr, FALSE);
       -        keypad(stdscr, TRUE);
       -        curs_set(FALSE); /* hide cursor */
       +        setupwin();
        
        show:
                /* display slide if changed */
       @@ -161,7 +192,12 @@ show:
                }
                clear();
                refresh();
       -        printw("%.*s", currentslidelen, currentslidep);
       +
       +        if (access(slidefiles[currentslide], X_OK) == 0) {
       +                executeslide(slidefiles + currentslide);
       +        } else {
       +                printw("%.*s", currentslidelen, currentslidep);
       +        }
        
        again:
                c = getch();
       @@ -173,6 +209,17 @@ again:
                /* end presentation */
                case 'q':
                        break;
       +        /* next without transition */
       +        case 'J':
       +        case 'L':
       +                for (int i = currentslide + 1; i < nslides; i++) {
       +                        if (access(slidefiles[i], X_OK) && i != currentslide) {
       +                                currentslide = i;
       +                                slidechanged = 1;
       +                                goto show;
       +                        }
       +                }
       +                goto again;
                /* next */
                case ' ':
                case 'l':
       @@ -186,6 +233,17 @@ again:
                                goto show;
                        }
                        goto again;
       +        /* prev without transition */
       +        case 'H':
       +        case 'K':
       +                for (int i = currentslide - 1; i >= 0; i--) {
       +                        if (access(slidefiles[i], X_OK) && i != currentslide) {
       +                                currentslide = i;
       +                                slidechanged = 1;
       +                                goto show;
       +                        }
       +                }
       +                goto again;
                /* prev */
                case 'h':
                case 'k':
   DIR diff --git a/showoff/random-animation.sh b/showoff/random-animation.sh
       @@ -0,0 +1,12 @@
       +#!/bin/sh
       +
       +randomanimation() {
       +        printf '%s\n' beams binarypath blackhole bouncyballs bubbles burn \
       +                colorshift crumble decrypt errorcorrect expand fireworks \
       +                matrix middleout orbittingvolley overflow pour print rain \
       +                randomsequence rings scattered slice slide spotlights spray \
       +                swarm synthgrid unstable vhstape waves wipe \
       +        | sort -R | head -n 1
       +}
       +
       +exec tte --frame-rate 400 --input-file "$1" "$(randomanimation)"