add follow action
authorLaurent Mazet <mazet@softndesign.org>
Sun, 12 May 2024 22:19:21 +0000 (00:19 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 12 May 2024 22:19:21 +0000 (00:19 +0200)
cmd.c
cmore.c

diff --git a/cmd.c b/cmd.c
index 355b633ef464b684c0ea7048ec7d4d376044f56e..95d1718134a88385a243184a670eba0605ba68d7 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -112,6 +112,10 @@ void free_lines (char **lines)
 {
     int i = 0;
 
+    if (!lines) {
+        return;
+    }
+
     while (lines[i]) {
         free (lines[i++]);
     }
diff --git a/cmore.c b/cmore.c
index 6271d232e750ae493d8ffa8fd08c9d03f98f528b..ad2243b9be96200027c5081196b0a04a372eed61 100644 (file)
--- a/cmore.c
+++ b/cmore.c
@@ -17,19 +17,28 @@ char *version = "0.1";
 
 char *input = NULL;
 char *command = NULL;
+char **lines = NULL;
 int second = 0;
 
-void display (char **lines, int xmax, int ymax)
+void display (char **lines, int xmax, int ymax, int keep_skip)
 {
     int stop = 0;
 
+    if (!lines) {
+        return;
+    }
+
 #ifdef __PDCURSES__
     statusmsg ("Press 'q' or escape to quit");
 #else
     statusmsg ("Press 'q' or double-escape to quit");
 #endif
 
-    int skip = 0;
+    static int skip;
+    if (!keep_skip) {
+        skip = 0;
+    }
+
     while (!stop) {
         clsbody ();
         int i = 0;
@@ -107,8 +116,6 @@ void display (char **lines, int xmax, int ymax)
 
 void process (void)
 {
-    static char **lines = NULL;
-
     int xmax, ymax;
     WINDOW *wbody = bodywin ();
     getmaxyx (wbody, ymax, xmax);
@@ -132,18 +139,10 @@ void process (void)
         exit (1);
     }
 
-    if (!lines) {
-        lines = split_lines (buffer, xmax);
-        free (buffer);
-    }
-
-    if (lines) {
-        display (lines, xmax, ymax);
-        if (buffer) {
-            free_lines (lines);
-            lines = NULL;
-        }
-    }
+    free_lines (lines);
+    lines = split_lines (buffer, xmax);
+    free (buffer);
+    display (lines, xmax, ymax, 0);
 
     if (second > 0) {
         VERBOSE (DEBUG, fprintf (stdout, "sleeping for %d''\n", second));
@@ -153,6 +152,15 @@ void process (void)
     }
 }
 
+void follow (void)
+{
+    int xmax, ymax;
+    WINDOW *wbody = bodywin ();
+    getmaxyx (wbody, ymax, xmax);
+
+    display (lines, xmax, ymax, 1);
+}
+
 void about (void)
 {
     int xmax, ymax;
@@ -205,15 +213,11 @@ void chfile (void)
     }
 }
 
-void contdisp (void)
-{
-}
-
 menu SubMenu0[] =
 {
     { "Command", chcmd, "Change command"},
     { "File", chfile, "Change file"},
-    { "Display", contdisp, "Continue"},
+    { "Display", follow, "Continue"},
     { "Refresh", process, "Refresh"},
     { "Exit", DoExit, "Terminate program" },
     { "", (FUNC)0, "" }