From b2892fd44b91c8a550da270266954c1bfd43b47e Mon Sep 17 00:00:00 2001
From: Hans Petter Jansson <hpj@hpjansson.org>
Date: Sat, 9 Mar 2024 00:29:38 +0100
Subject: [PATCH] chafa: Emit newline/index after sixel image

This positions the cursor correctly ~everywhere.

See #192 (GitHub).
---
 tools/chafa/chafa.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/tools/chafa/chafa.c b/tools/chafa/chafa.c
index c882fea..6225947 100644
--- a/tools/chafa/chafa.c
+++ b/tools/chafa/chafa.c
@@ -2590,19 +2590,19 @@ write_image_epilogue (gint dest_width)
     }
     else /* CHAFA_PIXEL_MODE_SIXELS */
     {
-        /* Sixel mode leaves cursor somewhere at or below the leftmost column */
+        /* Sixel mode leaves the cursor in the leftmost column of the final band */
 
-        if (left_space > 0)
+        if (options.relative)
         {
-            if (options.relative)
-            {
+            p0 = chafa_term_info_emit_cursor_down_scroll (options.term_info, p0);
+
+            if (left_space > 0)
                 p0 = chafa_term_info_emit_cursor_left (options.term_info, p0,
                                                        left_space);
-            }
-            else
-            {
-                *(p0++) = '\r';
-            }
+        }
+        else
+        {
+            *(p0++) = '\n';
         }
     }