This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit cdf86b52dfcf1bac7996a6f738eeea438af47a0b
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 01:12:15 2026 -0600

    backlog_view: map only the head for a terminal nothing renders
    
    A terminal that nothing renders keeps its viewport on the bottom. Read
    through a view, its store would keep the two pages behind the head
    mapped, and up to one more until the release pass, so pages nobody
    asked for would stay raw. Which pages those are depends on when the
    view last followed the head, so the raw pages would no longer be just
    the ones a reader asked for.
    
    A pty flagged backlog_head_only keeps the head, which resize reads to
    wrap the newest entry again, and nothing else: no window is asked for,
    and every page it left is released at the next idle.
---
 src/bin/backlog_view.c |  8 ++++--
 src/bin/termpty.c      | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/bin/termpty.h      |  3 +++
 src/bin/tytest.c       |  1 +
 src/bin/unit_tests.h   |  1 +
 5 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/src/bin/backlog_view.c b/src/bin/backlog_view.c
index a8985147..686711d4 100644
--- a/src/bin/backlog_view.c
+++ b/src/bin/backlog_view.c
@@ -533,6 +533,8 @@ _page_kept(const BacklogView *view, const BacklogViewPage *page)
 {
    if (_page_is_head(view, page))
      return EINA_TRUE;
+   if (view->ty->backlog_head_only)
+     return EINA_FALSE;
    return backlog_window_keeps((int)(page - view->pages), _anchor_index(view));
 }
 
@@ -584,7 +586,8 @@ _pages_request_next(BacklogView *view)
    anchor = _anchor_index(view);
    if (_page_wanted(&view->pages[view->pages_count - 1]))
      page = &view->pages[view->pages_count - 1];
-   for (d = 0; d <= BACKLOG_KEEP_BEHIND && !page; d++)
+   for (d = 0; d <= BACKLOG_KEEP_BEHIND && !page &&
+        !view->ty->backlog_head_only; d++)
      {
         i = anchor - d;
         if (i >= 0 && _page_wanted(&view->pages[i]))
@@ -616,7 +619,8 @@ _window_update(BacklogView *view)
      return;
    if (view->released && view->release_anchor_id >= view->pages[0].id)
      release_index = (int)(view->release_anchor_id - view->pages[0].id);
-   if (backlog_window_needs_pass(_anchor_index(view), release_index))
+   if (view->ty->backlog_head_only ||
+       backlog_window_needs_pass(_anchor_index(view), release_index))
      _release_pass_schedule(view);
    _pages_request_next(view);
 }
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 19790369..49af9bea 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -5995,6 +5995,73 @@ tytest_backlog_clear_ids(void)
    return 0;
 }
 
+static int
+_ty_view_mapped_count(Termpty *ty)
+{
+   BacklogView *view = ty->backlog_view;
+   unsigned int i;
+   int n = 0;
+
+   for (i = 0; i < view->pages_count; i++)
+     n += view->pages[i].mapped != NULL;
+   return n;
+}
+
+/* Test: the view of a pty that nothing renders keeps only the head mapped,
+ * and lets go of the heads it left; a resize still rewraps the newest
+ * entry, which is in the head. */
+int
+tytest_backlog_view_head_only(void)
+{
+   const Termcell *cells;
+   Termpty ty;
+   ssize_t w = 0;
+   int i;
+
+   _ty_test_init(&ty, 80, 24);
+   termpty_backlog_size_set(&ty, 0);
+   termpty_backlog_size_set(&ty, 2000);
+   /* the window around the bottom, for a pty that is rendered */
+   _ty_padded_feed(&ty, 1, 128 * 6, 0);
+   termpty_backlog_follow(&ty);
+   _ty_loop_run(0.01);
+   assert(ty.backlog_view->pages_count > 3);
+   assert(_ty_view_mapped_count(&ty) > 1);
+
+   ty.backlog_head_only = 1;
+   for (i = 0; i < 3; i++)
+     {
+        _ty_padded_feed(&ty, 1000 + i * 128, 1000 + i * 128 + 127, 0);
+        termpty_backlog_follow(&ty);
+        _ty_loop_run(0.01);
+        assert(_ty_view_mapped_count(&ty) == 1);
+        assert(ty.backlog_view->pages[ty.backlog_view->pages_count - 1]
+               .mapped);
+     }
+
+   /* a line that wrapped, its first row in the backlog */
+   _ty_feed(&ty, "\033[2J\033[H");
+   for (i = 0; i < 100; i++)
+     _ty_feed(&ty, "w");
+   _ty_feed(&ty, "\r\n");
+   for (i = 0; i < 22; i++)
+     _ty_feed(&ty, "z\r\n");
+   termpty_backlog_follow(&ty);
+   assert(BACKLOG_ROW_GET(&ty, 1)->w == 80);
+   assert(BACKLOG_ROW_GET(&ty, 1)->cells[79].att.autowrapped);
+   termpty_resize(&ty, 120, 24);
+   /* the whole line, once, scrolled back off the screen it fills */
+   cells = termpty_cellrow_get(&ty, -1, &w);
+   assert(cells && (w == 100) && (cells[99].codepoint == 'w'));
+   cells = termpty_cellrow_get(&ty, -2, &w);
+   assert(cells && (cells[0].codepoint != 'w'));
+   _ty_loop_run(0.01);
+   assert(_ty_view_mapped_count(&ty) == 1);
+   _ty_backlog_rows_check(&ty);
+   _ty_test_shutdown(&ty);
+   return 0;
+}
+
 /* Test: a window that reaches compressed pages has them rebuilt on a
  * thread, rather than on the next read. */
 int
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index e7c2614b..b9fe3bf7 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -343,6 +343,9 @@ struct tag_Termpty
     * termpty_backlog_external_*() put in it, as in a tymux shadow pty
     * mirroring the daemon's. Once sized, it keeps its size. */
    unsigned int backlog_external_only : 1;
+   /* Nothing renders the pty, as in tymuxd: its view keeps only the head
+    * mapped, with no window around a viewport. */
+   unsigned int backlog_head_only : 1;
    /* how far the scan of the incomplete sequence at the head of buf went */
    unsigned int seq_scanned;
    /* bumped on each palette rewrite (OSC 4); scopes the truecolour cache */
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 8629239b..e807ff1e 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -41,6 +41,7 @@ static struct {
        { "backlog_hook_wrap_replay", tytest_backlog_hook_wrap_replay},
        { "backlog_hook_long_wrap", tytest_backlog_hook_long_wrap},
        { "backlog_clear_ids", tytest_backlog_clear_ids},
+       { "backlog_view_head_only", tytest_backlog_view_head_only},
        { "backlog_wide_entry_rows", tytest_backlog_wide_entry_rows},
        { "backlog_external", tytest_backlog_external},
        { "backlog_store_termpty", tytest_backlog_store_termpty},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 38ac37aa..78dccfe6 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -11,6 +11,7 @@ int tytest_backlog_hook(void);
 int tytest_backlog_hook_wrap_replay(void);
 int tytest_backlog_hook_long_wrap(void);
 int tytest_backlog_clear_ids(void);
+int tytest_backlog_view_head_only(void);
 int tytest_backlog_wide_entry_rows(void);
 int tytest_backlog_external(void);
 int tytest_backlog_store_termpty(void);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to