]> git.neil.brown.name Git - edlib.git/commitdiff
Disable LOG during refresh if log is visible.
authorNeilBrown <neil@brown.name>
Sat, 9 Sep 2023 02:17:28 +0000 (12:17 +1000)
committerNeilBrown <neil@brown.name>
Sat, 9 Sep 2023 02:17:28 +0000 (12:17 +1000)
If there is a view on the log, then allowing log during
refresh trigger recursion in unhelpful way.

Also line-count is sync in testing mode, and log is big
so disable line-count then.

This allows log to be viewed when viewing a test.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
core-log.c
core-pane.c
lib-linecount.c

index 64b42b994916d76e601dd09660291463c6d529d4..23c87435119df260d5904ddbc2c87c72bc1f44a5 100644 (file)
@@ -89,7 +89,7 @@ Core features
       implemented at least by lib-search, doc-text and probably many
       others.  It is particularly for things that are awkward to test
       with the ncurses/replay test approach.
-- [ ] Send global notify before/after refresh.  LOG must suspend logging
+- [X] Send global notify before/after refresh.  LOG must suspend logging
       (or notifications at least) during refresh if is visible anywhere
 - [ ] Do I want "Display" as in "Display:close", or "window" as in
       "window:notify".  Decide, and make everything consistent.
index 2c3ba63e78cca66427e1bc04775dc0654b7a561c..0c81c35faf2995dd0268a09ea96da9f690f127c0 100644 (file)
@@ -37,7 +37,8 @@ struct logbuf {
 static struct log {
        struct doc              doc;
        struct list_head        log;
-       int blocked;
+       int                     blocked;
+       int                     refresh_active;
 } *log_doc safe;
 
 #include "core-pane.h"
@@ -75,11 +76,16 @@ void LOG(char *fmt, ...)
        struct logbuf *b;
        struct timeval now;
 
-       if (!(void*)log_doc)
+       if (!(void*)log_doc || !log_pane)
                /* too early */
                return;
        if (!fmt)
                return;
+       if (log_doc->refresh_active) {
+               /* Mustn't log anything if doc is being viewed */
+               if (pane_notify("doc:notify-viewers", log_pane))
+                       return;
+       }
        if (log_doc->blocked)
                return;
        log_doc->blocked = 1;
@@ -401,6 +407,14 @@ DEF_CMD(log_close)
        return 1;
 }
 
+DEF_CMD(log_refresh_active)
+{
+       struct log *l = ci->home->doc_data;
+
+       l->refresh_active = ci->num;
+       return 1;
+}
+
 static struct map *log_map;
 DEF_LOOKUP_CMD(log_handle, log_map);
 
@@ -433,9 +447,16 @@ static void log_init(struct pane *ed safe)
        log_pane = doc_register(ed, &log_handle.c);
        if (!log_pane)
                return;
+       if (edlib_testing(ed))
+               /* line-count is SYNC when testing, and log can
+                * get big - so disable
+                */
+               attr_set_str(&log_pane->attrs, "linecount-disable", "yes");
        log_doc = log_pane->doc_data;
        INIT_LIST_HEAD(&log_doc->log);
 
+       call("editor:request:Refresh-active", log_pane);
+
        fname = getenv("EDLIB_LOG");
        if (!fname || !*fname)
                return;
@@ -461,6 +482,7 @@ void log_setup(struct pane *ed safe)
        key_add(log_map, "doc:destroy", &log_destroy);
        key_add(log_map, "doc:log:append", &log_append);
        key_add(log_map, "Close", &log_close);
+       key_add(log_map, "Refresh-active", &log_refresh_active);
        if(0)key_add(log_map, "debug:validate-marks", &log_val_marks);
 
        log_init(ed);
index 1ba2bf1480f43669fa6a8364be6c12f0445c1912..28bc14aa03783e71345ea95925f52913a503044a 100644 (file)
@@ -410,7 +410,7 @@ REDEF_CMD(pane_refresh)
 
        if (p->damaged & DAMAGED_CLOSED)
                return 1;
-
+       call("editor:notify:Refresh-active", p, 1);
        time_start(TIME_REFRESH);
        while (cnt-- &&
               (p->damaged &
@@ -422,20 +422,24 @@ REDEF_CMD(pane_refresh)
                pane_do_refresh(p);
                p->damaged &= ~DAMAGED_DEBUG;
        }
+       if (cnt < 0)
+               p->damaged |= DAMAGED_DEBUG;
        pane_do_postorder(p);
+       p->damaged &= ~DAMAGED_DEBUG;
        if (p->damaged) {
                static time_t last_warn;
                static int rpt;
                if (last_warn + 5 < time(NULL))
                        rpt = 0;
                if (rpt++ < 5)
-                       LOG("WARNING %sroot pane damaged after refresh: %d",
+                       LOG("WARNING %sroot pane damaged after refresh: 0x%x",
                            p->parent != p ? "":"non-", p->damaged);
                last_warn = time(NULL);
                call("editor:notify:Message:broadcast",p, 0, NULL,
                     "Refresh looping - see log");
        }
        time_stop(TIME_REFRESH);
+       call("editor:notify:Refresh-active", p, 0);
        return 1;
 }
 
index ea22953ab18a520ffe6c2b89d63cab66d6235c17..ba233228d103589b20fe015bec6f0b0e1c7b83cc 100644 (file)
@@ -351,8 +351,6 @@ DEF_CMD(linecount_notify_count)
        /* num==1 means we don't want to wait for precision */
        bool sync = ci->mark2 && ci->num != 1;
 
-       if (strcmp(ci->key, "CountLinesAsync") == 0)
-               sync = False;
        count_calculate(d, ci->mark2, ci->home, cli->view_num,
                        sync);
        return 1;