]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
Add pause functionality to replay
authorjNullj <15849761+jNullj@users.noreply.github.com>
Mon, 6 May 2024 21:39:12 +0000 (00:39 +0300)
committerjNullj <15849761+jNullj@users.noreply.github.com>
Mon, 6 May 2024 21:39:12 +0000 (00:39 +0300)
Adds pause to replay_setup.
Adds functions to toggle and get pause state.
Adds stdin keys read - looks for space for pause toggle.
Adds replay pause to replay render loop.

term-utils/script-playutils.c
term-utils/script-playutils.h
term-utils/scriptreplay.c

index 1dec1afc81174053ecf44336b43f232b0473e06b..854d9525228f36e13939f0a5e1a3f1598c9cee12 100644 (file)
@@ -8,6 +8,7 @@
 #include <math.h>
 #include <unistd.h>
 #include <sys/time.h>
+#include <stdbool.h>
 
 #include "c.h"
 #include "xalloc.h"
@@ -59,6 +60,7 @@ struct replay_setup {
        size_t                  nlogs;
 
        struct replay_step      step;   /* current step */
+       bool pause;
 
        FILE                    *timing_fp;
        const char              *timing_filename;
@@ -102,7 +104,10 @@ static inline void timerinc(struct timeval *a, struct timeval *b)
 
 struct replay_setup *replay_new_setup(void)
 {
-       return  xcalloc(1, sizeof(struct replay_setup));
+       struct replay_setup *ret;
+       ret = xcalloc(1, sizeof(struct replay_setup));
+       ret->pause = false;
+       return  ret;
 }
 
 void replay_free_setup(struct replay_setup *stp)
@@ -297,6 +302,17 @@ int replay_step_is_empty(struct replay_step *step)
        return step->size == 0 && step->type == 0;
 }
 
+bool replay_get_is_paused(struct replay_setup *setup)
+{
+       assert(setup);
+       return setup->pause;
+}
+
+void replay_toggle_pause(struct replay_setup *setup)
+{
+       assert(setup);
+       setup->pause = !setup->pause;
+}
 
 static int read_multistream_step(struct replay_step *step, FILE *f, char type)
 {
index 53b3fd2877d760488320d384cca212f92f9bf26d..f3bce5fe4ffe13a3c3674d8b493fa2ee0893b2ea 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef UTIL_LINUX_SCRIPT_PLAYUTILS_H
 #define UTIL_LINUX_SCRIPT_PLAYUTILS_H
 
+#include <stdbool.h>
+
 #include "c.h"
 #include "debug.h"
 
@@ -47,4 +49,7 @@ int replay_get_next_step(struct replay_setup *stp, char *streams, struct replay_
 
 int replay_emit_step_data(struct replay_setup *stp, struct replay_step *step, int fd);
 
+bool replay_get_is_paused(struct replay_setup *setup);
+void replay_toggle_pause(struct replay_setup *setup);
+
 #endif /* UTIL_LINUX_SCRIPT_PLAYUTILS_H */
index ab3581eed0095da4d60b7ebff4e8d5eee0dbcd62..d08b8734530f109e723b7e0497403b80fd631f98 100644 (file)
@@ -30,6 +30,8 @@
 #include <sys/time.h>
 #include <termios.h>
 #include <fcntl.h>
+#include <wchar.h>
+#include <stdbool.h>
 
 #include "c.h"
 #include "xalloc.h"
@@ -149,12 +151,14 @@ int
 main(int argc, char *argv[])
 {
        static const struct timeval mindelay = { .tv_sec = 0, .tv_usec = 100 };
+       static const struct timeval inputDelay = { .tv_sec = 0, .tv_usec = 100000 };
        struct timeval maxdelay;
 
        int isterm;
        int saved_flag;
        struct termios saved;
 
+       wint_t c;
        struct replay_setup *setup = NULL;
        struct replay_step *step = NULL;
        char streams[6] = {0};          /* IOSI - in, out, signal,info */
@@ -318,6 +322,19 @@ main(int argc, char *argv[])
        isterm = setterm(&saved, &saved_flag);
 
        do {
+               c = fgetwc(stdin);
+               switch (c) {
+                       case ' ':
+                               replay_toggle_pause(setup);
+                               break;
+               }
+
+               if (replay_get_is_paused(setup))
+               {
+                       delay_for(&inputDelay);
+                       continue;
+               }
+               
                rc = replay_get_next_step(setup, streams, &step);
                if (rc)
                        break;