bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#57607: Feature request: Use the character cell on bottom-right corne


From: Akib Azmain Turja
Subject: bug#57607: Feature request: Use the character cell on bottom-right corner of a terminal
Date: Tue, 04 Oct 2022 19:05:21 +0600

Akib Azmain Turja <akib@disroot.org> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Akib Azmain Turja <akib@disroot.org>
>>> Cc: 57607@debbugs.gnu.org,  gerd.moellmann@gmail.com
>>> Date: Tue, 04 Oct 2022 13:22:51 +0600
>>> 
>>> > Thanks.  But could you please describe the idea of the patch in some
>>> > comment?  It is hard to follow the code, especially since the diff has
>>> > many pure whitespace changes.
>>> 
>>> The idea is that you write the string just like before (for example, you
>>> want to write "hello" in a five columns width terminal, so you write
>>> only "hell", so that the line shows "hell "), then move a character
>>> backward and write the last glyph (write "o", so that the line shows
>>> "helo "), move a character backward again and arrange that after writing
>>> the next glyph, the character on the current position will be pushed
>>> towards right and write the glyph before the last one (write "l", now
>>> the line shows "hello").
>>> 
>>> Should I add the explanation to the function as comment?
>>
>> Yes, please.  It would also help if the respective parts of the code
>> were annotated with comments that explain their role in the algorithm.
>
> OK.

Done.

>
>>
>>> > Also, this:
>>> >
>>> >> +      /* Go to the previous position. */
>>> >> +      cmgoto (tty, curY (tty), curX (tty) - 1);
>>> >> +      cmplus (tty, 1);
>>> >
>>> > Seem to assume the last character takes just one column?  What about
>>> > characters whose width is 2 columns?
>>> 
>>> Yes, I assume that.  I don't think any multi-char width glyph reach this
>>> function (I think they are converted to single column width glyphs, for
>>> example "^L" is converted to "^" and "L").  The reason of the assumption
>>> is the following code:
>>> 
>>> --8<---------------cut here---------------start------------->8---
>>>   if (AutoWrap (tty)
>>>       && curY (tty) + 1 == FRAME_TOTAL_LINES (f)
>>>       && (curX (tty) + len) == FRAME_COLS (f))
>>>     len --;
>>> --8<---------------cut here---------------end--------------->8---
>>> 
>>> Which also assumes the same.
>>
>> Please try with some 2-column CJK characters, I'm not sure the example
>> with ^L is relevant here.  You can find the list of wide characters in
>> characters.el (search for "width"); for example, characters in the
>> U+FF00 block can be useful.
>
> Thanks, "CJK STROKE D" doesn't work as expected, and the result depends
> on terminal in use.  How can I determine the width of a glyph?
>
>> (And the existing code could have bugs,
>> no need to assume it is always correct.)
>
> Yes, it can, but in most cases, my brain has more bugs.
>
>>
>>> > And finally, it would be nice to avoid so much code duplication
>>> > between tty_write_glyphs and tty_write_glyphs_with_face.  Is that
>>> > feasible?
>>> 
>>> Yes, I think so.  I think it possible to just add a new argument
>>> "face_id" to tty_write_glyphs would the trick.  tty_write_glyph will try
>>> to use "face_id" if it is specified, otherwise fallback to the face_id
>>> in the string.  But how to "not" specify a face_id?  Would a NULL work?
>>
>> face_id is an integer, and zero is a valid value (it means the default
>> face), so NULL won't do.  But you can use -1 to mean "no face ID".
>> Just make sure you never pass it to FACE_FROM_ID etc.
>>
>> Thanks.
>
> OK, I'll try that.  Thanks.

Done.  Looks like Emacs still works.  Here are the patches:

From 72af00d8610bdc194062b246aab0e38f22174aeb Mon Sep 17 00:00:00 2001
From: Akib Azmain Turja <akib@disroot.org>
Date: Mon, 3 Oct 2022 14:18:59 +0600
Subject: [PATCH 1/2] Write on the bottom-right character cell on terminal

Correctly write on the bottom-right character cell on text terminals
if the terminal allows to do this.  Also fixes bug#57728.

* src/term.c (tty_write_glyphs, tty_write_glyphs_with_face): Write on
the bottom-right character cell if the terminal supports it.

* src/term.c (glyph_on_char_cell_before_last): New static variable to
hold the current glyph on the character cell before the cell on the
bottom-right corner.
---
 src/term.c | 266 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 225 insertions(+), 41 deletions(-)

diff --git a/src/term.c b/src/term.c
index 2e43d892..283a65c4 100644
--- a/src/term.c
+++ b/src/term.c
@@ -718,7 +718,7 @@ encode_terminal_code (struct glyph *src, int src_len,
   return (encode_terminal_dst);
 }
 
-
+static struct glyph glyph_on_char_cell_before_last;
 
 /* An implementation of write_glyphs for termcap frames. */
 
@@ -727,7 +727,7 @@ tty_write_glyphs (struct frame *f, struct glyph *string, 
int len)
 {
   unsigned char *conversion_buffer;
   struct coding_system *coding;
-  int n, stringlen;
+  int n, stringlen, write_on_last_cell;
 
   struct tty_display_info *tty = FRAME_TTY (f);
 
@@ -737,55 +737,158 @@ tty_write_glyphs (struct frame *f, struct glyph *string, 
int len)
   /* Don't dare write in last column of bottom line, if Auto-Wrap,
      since that would scroll the whole frame on some terminals.  */
 
-  if (AutoWrap (tty)
-      && curY (tty) + 1 == FRAME_TOTAL_LINES (f)
-      && (curX (tty) + len) == FRAME_COLS (f))
+  write_on_last_cell = (AutoWrap (tty)
+                       && curY (tty) + 1 == FRAME_TOTAL_LINES (f)
+                       && (curX (tty) + len) == FRAME_COLS (f));
+  if (write_on_last_cell)
     len --;
-  if (len <= 0)
-    return;
 
-  cmplus (tty, len);
+  if (FRAME_COLS (f) == 1
+      || !(tty->TS_ins_char || tty->TS_ins_multi_chars
+          || (tty->TS_insert_mode && tty->TS_end_insert_mode)))
+    write_on_last_cell = false;
+
+  if (len <= 0 && !write_on_last_cell)
+    return;
 
   /* If terminal_coding does any conversion, use it, otherwise use
      safe_terminal_coding.  We can't use CODING_REQUIRE_ENCODING here
      because it always return 1 if the member src_multibyte is 1.  */
-  coding = (FRAME_TERMINAL_CODING (f)->common_flags & 
CODING_REQUIRE_ENCODING_MASK
+  coding = ((FRAME_TERMINAL_CODING (f)->common_flags
+            & CODING_REQUIRE_ENCODING_MASK)
            ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
   /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
      the tail.  */
   coding->mode &= ~CODING_MODE_LAST_BLOCK;
 
-  for (stringlen = len; stringlen != 0; stringlen -= n)
+  if (len > 0)
     {
-      /* Identify a run of glyphs with the same face.  */
-      int face_id = string->face_id;
+      cmplus (tty, len);
+
+      if (write_on_last_cell)
+       glyph_on_char_cell_before_last = string[len - 1];
+
+      for (stringlen = len; stringlen != 0; stringlen -= n)
+       {
+         /* Identify a run of glyphs with the same face.  */
+         int face_id = string->face_id;
+
+         for (n = 1; n < stringlen; ++n)
+           if (string[n].face_id != face_id)
+             break;
+
+         /* Turn appearance modes of the face of the run on.  */
+         tty_highlight_if_desired (tty);
+         turn_on_face (f, face_id);
 
-      for (n = 1; n < stringlen; ++n)
-       if (string[n].face_id != face_id)
-         break;
+         if (n == stringlen && !write_on_last_cell)
+           /* This is the last run.  */
+           coding->mode |= CODING_MODE_LAST_BLOCK;
+         conversion_buffer = encode_terminal_code (string, n,
+                                                   coding);
+         if (coding->produced > 0)
+           {
+             block_input ();
+             fwrite (conversion_buffer, 1, coding->produced,
+                     tty->output);
+             clearerr (tty->output);
+             if (tty->termscript)
+               fwrite (conversion_buffer, 1, coding->produced,
+                       tty->termscript);
+             unblock_input ();
+           }
+         string += n;
 
-      /* Turn appearance modes of the face of the run on.  */
+         /* Turn appearance modes off.  */
+         turn_off_face (f, face_id);
+         tty_turn_off_highlight (tty);
+       }
+    }
+
+  /* Write on the bottom-right corner. */
+  if (write_on_last_cell)
+    {
+      /* Go to the previous position. */
+      cmgoto (tty, curY (tty), curX (tty) - 1);
+      cmplus (tty, 1);
+
+      int face_id = string->face_id;
+
+      /* Turn appearance modes of the face.  */
       tty_highlight_if_desired (tty);
       turn_on_face (f, face_id);
 
-      if (n == stringlen)
-       /* This is the last run.  */
-       coding->mode |= CODING_MODE_LAST_BLOCK;
-      conversion_buffer = encode_terminal_code (string, n, coding);
+      conversion_buffer = encode_terminal_code (string, 1, coding);
       if (coding->produced > 0)
        {
          block_input ();
-         fwrite (conversion_buffer, 1, coding->produced, tty->output);
+         fwrite (conversion_buffer, 1, coding->produced,
+                 tty->output);
          clearerr (tty->output);
          if (tty->termscript)
-           fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
+           fwrite (conversion_buffer, 1, coding->produced,
+                   tty->termscript);
+         unblock_input ();
+       }
+
+      /* Go to the previous position. */
+      cmgoto (tty, curY (tty), curX (tty) - 1);
+      cmplus (tty, 1);
+
+      /* Arrange that after writing the next glyph, the glyph on the
+         current character cell is somehow pushed to the bottom-right
+        corner. */
+      if (tty->TS_ins_char)
+       {
+         OUTPUT1 (tty, tty->TS_ins_char);
+       }
+      else if (tty->TS_ins_multi_chars)
+       {
+         char *buf = tparam (tty->TS_ins_multi_chars, 0, 0, 1, 0,
+                             0, 0);
+         OUTPUT1 (tty, buf);
+         xfree (buf);
+       }
+      else
+       {
+         tty_turn_on_insert (tty);
+       }
+
+      if (face_id != glyph_on_char_cell_before_last.face_id)
+       {
+
+         /* Turn appearance modes of the face.  */
+         turn_off_face (f, face_id);
+         tty_turn_off_highlight (tty);
+
+         face_id = glyph_on_char_cell_before_last.face_id;
+
+         tty_highlight_if_desired (tty);
+         turn_on_face (f, face_id);
+       }
+
+      /* This is the last run.  */
+      coding->mode |= CODING_MODE_LAST_BLOCK;
+      conversion_buffer
+       = encode_terminal_code (&glyph_on_char_cell_before_last, 1,
+                               coding);
+      if (coding->produced > 0)
+       {
+         block_input ();
+         fwrite (conversion_buffer, 1, coding->produced,
+                 tty->output);
+         clearerr (tty->output);
+         if (tty->termscript)
+           fwrite (conversion_buffer, 1, coding->produced,
+                   tty->termscript);
          unblock_input ();
        }
-      string += n;
 
       /* Turn appearance modes off.  */
       turn_off_face (f, face_id);
       tty_turn_off_highlight (tty);
+
+      tty_turn_off_insert (tty);
     }
 
   cmcheckmagic (tty);
@@ -799,6 +902,7 @@ tty_write_glyphs_with_face (register struct frame *f, 
register struct glyph *str
 {
   unsigned char *conversion_buffer;
   struct coding_system *coding;
+  int write_on_last_cell;
 
   struct tty_display_info *tty = FRAME_TTY (f);
 
@@ -808,38 +912,118 @@ tty_write_glyphs_with_face (register struct frame *f, 
register struct glyph *str
   /* Don't dare write in last column of bottom line, if Auto-Wrap,
      since that would scroll the whole frame on some terminals.  */
 
-  if (AutoWrap (tty)
-      && curY (tty) + 1 == FRAME_TOTAL_LINES (f)
-      && (curX (tty) + len) == FRAME_COLS (f))
+  write_on_last_cell = (AutoWrap (tty)
+                       && curY (tty) + 1 == FRAME_TOTAL_LINES (f)
+                       && (curX (tty) + len) == FRAME_COLS (f));
+  if (write_on_last_cell)
     len --;
-  if (len <= 0)
-    return;
 
-  cmplus (tty, len);
+  if (FRAME_COLS (f) == 1
+      || !(tty->TS_ins_char || tty->TS_ins_multi_chars
+          || (tty->TS_insert_mode && tty->TS_end_insert_mode)))
+    write_on_last_cell = false;
+
+  if (len <= 0 && !write_on_last_cell)
+    return;
 
   /* If terminal_coding does any conversion, use it, otherwise use
      safe_terminal_coding.  We can't use CODING_REQUIRE_ENCODING here
      because it always return 1 if the member src_multibyte is 1.  */
-  coding = (FRAME_TERMINAL_CODING (f)->common_flags & 
CODING_REQUIRE_ENCODING_MASK
+  coding = ((FRAME_TERMINAL_CODING (f)->common_flags
+            & CODING_REQUIRE_ENCODING_MASK)
            ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
-  /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
-     the tail.  */
+
+  /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only
+     at the tail.  */
   coding->mode &= ~CODING_MODE_LAST_BLOCK;
 
   /* Turn appearance modes of the face.  */
   tty_highlight_if_desired (tty);
   turn_on_face (f, face_id);
 
-  coding->mode |= CODING_MODE_LAST_BLOCK;
-  conversion_buffer = encode_terminal_code (string, len, coding);
-  if (coding->produced > 0)
+  if (len > 0)
+    {
+      cmplus (tty, len);
+      if (write_on_last_cell)
+       glyph_on_char_cell_before_last = string[len - 1];
+      else
+       coding->mode |= CODING_MODE_LAST_BLOCK;
+
+      conversion_buffer = encode_terminal_code (string, len, coding);
+      if (coding->produced > 0)
+       {
+         block_input ();
+         fwrite (conversion_buffer, 1, coding->produced,
+                 tty->output);
+         clearerr (tty->output);
+         if (tty->termscript)
+           fwrite (conversion_buffer, 1, coding->produced,
+                   tty->termscript);
+         unblock_input ();
+       }
+    }
+
+  /* Write on the bottom-right corner. */
+  if (write_on_last_cell)
     {
-      block_input ();
-      fwrite (conversion_buffer, 1, coding->produced, tty->output);
-      clearerr (tty->output);
-      if (tty->termscript)
-       fwrite (conversion_buffer, 1, coding->produced, tty->termscript);
-      unblock_input ();
+      /* Go to the previous position. */
+      cmgoto (tty, curY (tty), curX (tty) - 1);
+      cmplus (tty, 1);
+
+      conversion_buffer = encode_terminal_code (string, 1, coding);
+      if (coding->produced > 0)
+       {
+         block_input ();
+         fwrite (conversion_buffer, 1, coding->produced,
+                 tty->output);
+         clearerr (tty->output);
+         if (tty->termscript)
+           fwrite (conversion_buffer, 1, coding->produced,
+                   tty->termscript);
+         unblock_input ();
+       }
+
+      /* Go to the previous position. */
+      cmgoto (tty, curY (tty), curX (tty) - 1);
+      cmplus (tty, 1);
+
+      /* Arrange that after writing the next glyph, the glyph on the
+         current character cell is somehow pushed to the bottom-right
+        corner. */
+      if (tty->TS_ins_char)
+       {
+         OUTPUT1 (tty, tty->TS_ins_char);
+       }
+      else if (tty->TS_ins_multi_chars)
+       {
+         char *buf = tparam (tty->TS_ins_multi_chars, 0, 0, 1,
+                             0, 0, 0);
+         OUTPUT1 (tty, buf);
+         xfree (buf);
+       }
+      else
+       {
+         tty_turn_on_insert (tty);
+       }
+
+      /* This is the last run.  */
+      coding->mode |= CODING_MODE_LAST_BLOCK;
+      conversion_buffer
+       = encode_terminal_code (&glyph_on_char_cell_before_last, 1,
+                               coding);
+      if (coding->produced > 0)
+       {
+         block_input ();
+         fwrite (conversion_buffer, 1, coding->produced,
+                 tty->output);
+         clearerr (tty->output);
+         if (tty->termscript)
+           fwrite (conversion_buffer, 1, coding->produced,
+                   tty->termscript);
+         unblock_input ();
+       }
+
+      tty_turn_off_insert (tty);
     }
 
   /* Turn appearance modes off.  */
-- 
2.37.1

From b090cba28981d7a0e40f87211e9b8b065bfdf3e3 Mon Sep 17 00:00:00 2001
From: Akib Azmain Turja <akib@disroot.org>
Date: Tue, 4 Oct 2022 18:54:58 +0600
Subject: [PATCH 2/2] Merge tty_write_glyphs and tty_write_glyphs_with_face

* src/term.c (tty_write_glyphs_1, tty_write_glyphs)
(tty_write_glyphs_with_face): Merge tty_write_glyphs and
tty_write_glyphs_with_face into tty_write_glyphs_1.  Define
tty_write_glyphs as a wrapper of tty_write_glyphs_1.
---
 src/term.c | 243 +++++++++++++++++------------------------------------
 1 file changed, 79 insertions(+), 164 deletions(-)

diff --git a/src/term.c b/src/term.c
index 283a65c4..db1dd2a4 100644
--- a/src/term.c
+++ b/src/term.c
@@ -723,7 +723,8 @@ encode_terminal_code (struct glyph *src, int src_len,
 /* An implementation of write_glyphs for termcap frames. */
 
 static void
-tty_write_glyphs (struct frame *f, struct glyph *string, int len)
+tty_write_glyphs_1 (struct frame *f, struct glyph *string, int len,
+                   int face_id)
 {
   unsigned char *conversion_buffer;
   struct coding_system *coding;
@@ -761,6 +762,13 @@ tty_write_glyphs (struct frame *f, struct glyph *string, 
int len)
      the tail.  */
   coding->mode &= ~CODING_MODE_LAST_BLOCK;
 
+  if (face_id >= 0)
+    {
+      /* Turn appearance modes of the face.  */
+      tty_highlight_if_desired (tty);
+      turn_on_face (f, face_id);
+    }
+
   if (len > 0)
     {
       cmplus (tty, len);
@@ -770,16 +778,27 @@ tty_write_glyphs (struct frame *f, struct glyph *string, 
int len)
 
       for (stringlen = len; stringlen != 0; stringlen -= n)
        {
-         /* Identify a run of glyphs with the same face.  */
-         int face_id = string->face_id;
+         int local_face_id;
 
-         for (n = 1; n < stringlen; ++n)
-           if (string[n].face_id != face_id)
-             break;
+         if (face_id >= 0)
+           {
+             /* This will be a problem when we run the loop another
+                time, but this is the only iteration. */
+             n = stringlen;
+           }
+         else
+           {
+             /* Identify a run of glyphs with the same face.  */
+             local_face_id = string->face_id;
 
-         /* Turn appearance modes of the face of the run on.  */
-         tty_highlight_if_desired (tty);
-         turn_on_face (f, face_id);
+             for (n = 1; n < stringlen; ++n)
+               if (string[n].face_id != local_face_id)
+                 break;
+
+             /* Turn appearance modes of the face of the run on.  */
+             tty_highlight_if_desired (tty);
+             turn_on_face (f, local_face_id);
+           }
 
          if (n == stringlen && !write_on_last_cell)
            /* This is the last run.  */
@@ -799,24 +818,41 @@ tty_write_glyphs (struct frame *f, struct glyph *string, 
int len)
            }
          string += n;
 
-         /* Turn appearance modes off.  */
-         turn_off_face (f, face_id);
-         tty_turn_off_highlight (tty);
+         if (face_id < 0)
+           {
+             /* Turn appearance modes off.  */
+             turn_off_face (f, local_face_id);
+             tty_turn_off_highlight (tty);
+           }
        }
     }
 
   /* Write on the bottom-right corner. */
   if (write_on_last_cell)
     {
-      /* Go to the previous position. */
+      /* The algorithm here is: we write the whole string except the
+         last glyph, then move back to the beginning of previous
+        glyph, write the last glyph, move back again, and insert the
+        glyph before the last glyph in such a way that last glyph at
+         cursor' position gets pushed to the corner. */
+
+      /* Go to the beginning of previous glyph. */
+      /* BUG: This assume the previous glyph is a single column width
+         glyph, so this won't work for multi column width, and the
+         result is terminal-dependent. */
       cmgoto (tty, curY (tty), curX (tty) - 1);
       cmplus (tty, 1);
 
-      int face_id = string->face_id;
+      int local_face_id;
 
-      /* Turn appearance modes of the face.  */
-      tty_highlight_if_desired (tty);
-      turn_on_face (f, face_id);
+      if (face_id < 0)
+       {
+         local_face_id = string->face_id;
+
+         /* Turn appearance modes of the face.  */
+         tty_highlight_if_desired (tty);
+         turn_on_face (f, local_face_id);
+       }
 
       conversion_buffer = encode_terminal_code (string, 1, coding);
       if (coding->produced > 0)
@@ -831,12 +867,15 @@ tty_write_glyphs (struct frame *f, struct glyph *string, 
int len)
          unblock_input ();
        }
 
-      /* Go to the previous position. */
+      /* Go to the beginning of previous glyph. */
+      /* BUG: This assume the previous glyph is a single column width
+         glyph, so this won't work for multi column width, and the
+         result is terminal-dependent. */
       cmgoto (tty, curY (tty), curX (tty) - 1);
       cmplus (tty, 1);
 
       /* Arrange that after writing the next glyph, the glyph on the
-         current character cell is somehow pushed to the bottom-right
+         current character cell gets pushed to the bottom-right
         corner. */
       if (tty->TS_ins_char)
        {
@@ -854,17 +893,18 @@ tty_write_glyphs (struct frame *f, struct glyph *string, 
int len)
          tty_turn_on_insert (tty);
        }
 
-      if (face_id != glyph_on_char_cell_before_last.face_id)
+      if (face_id < 0
+         && local_face_id != glyph_on_char_cell_before_last.face_id)
        {
 
          /* Turn appearance modes of the face.  */
-         turn_off_face (f, face_id);
+         turn_off_face (f, local_face_id);
          tty_turn_off_highlight (tty);
 
-         face_id = glyph_on_char_cell_before_last.face_id;
+         local_face_id = glyph_on_char_cell_before_last.face_id;
 
          tty_highlight_if_desired (tty);
-         turn_on_face (f, face_id);
+         turn_on_face (f, local_face_id);
        }
 
       /* This is the last run.  */
@@ -884,157 +924,32 @@ tty_write_glyphs (struct frame *f, struct glyph *string, 
int len)
          unblock_input ();
        }
 
+      if (face_id < 0)
+       {
+         /* Turn appearance modes off.  */
+         turn_off_face (f, local_face_id);
+         tty_turn_off_highlight (tty);
+       }
+
+      tty_turn_off_insert (tty);
+    }
+
+  if (face_id >= 0)
+    {
       /* Turn appearance modes off.  */
       turn_off_face (f, face_id);
       tty_turn_off_highlight (tty);
-
-      tty_turn_off_insert (tty);
     }
 
   cmcheckmagic (tty);
 }
 
-#ifndef DOS_NT
-
 static void
-tty_write_glyphs_with_face (register struct frame *f, register struct glyph 
*string,
-                           register int len, register int face_id)
+tty_write_glyphs (struct frame *f, struct glyph *string, int len)
 {
-  unsigned char *conversion_buffer;
-  struct coding_system *coding;
-  int write_on_last_cell;
-
-  struct tty_display_info *tty = FRAME_TTY (f);
-
-  tty_turn_off_insert (tty);
-  tty_hide_cursor (tty);
-
-  /* Don't dare write in last column of bottom line, if Auto-Wrap,
-     since that would scroll the whole frame on some terminals.  */
-
-  write_on_last_cell = (AutoWrap (tty)
-                       && curY (tty) + 1 == FRAME_TOTAL_LINES (f)
-                       && (curX (tty) + len) == FRAME_COLS (f));
-  if (write_on_last_cell)
-    len --;
-
-  if (FRAME_COLS (f) == 1
-      || !(tty->TS_ins_char || tty->TS_ins_multi_chars
-          || (tty->TS_insert_mode && tty->TS_end_insert_mode)))
-    write_on_last_cell = false;
-
-  if (len <= 0 && !write_on_last_cell)
-    return;
-
-  /* If terminal_coding does any conversion, use it, otherwise use
-     safe_terminal_coding.  We can't use CODING_REQUIRE_ENCODING here
-     because it always return 1 if the member src_multibyte is 1.  */
-  coding = ((FRAME_TERMINAL_CODING (f)->common_flags
-            & CODING_REQUIRE_ENCODING_MASK)
-           ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
-
-  /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only
-     at the tail.  */
-  coding->mode &= ~CODING_MODE_LAST_BLOCK;
-
-  /* Turn appearance modes of the face.  */
-  tty_highlight_if_desired (tty);
-  turn_on_face (f, face_id);
-
-  if (len > 0)
-    {
-      cmplus (tty, len);
-      if (write_on_last_cell)
-       glyph_on_char_cell_before_last = string[len - 1];
-      else
-       coding->mode |= CODING_MODE_LAST_BLOCK;
-
-      conversion_buffer = encode_terminal_code (string, len, coding);
-      if (coding->produced > 0)
-       {
-         block_input ();
-         fwrite (conversion_buffer, 1, coding->produced,
-                 tty->output);
-         clearerr (tty->output);
-         if (tty->termscript)
-           fwrite (conversion_buffer, 1, coding->produced,
-                   tty->termscript);
-         unblock_input ();
-       }
-    }
-
-  /* Write on the bottom-right corner. */
-  if (write_on_last_cell)
-    {
-      /* Go to the previous position. */
-      cmgoto (tty, curY (tty), curX (tty) - 1);
-      cmplus (tty, 1);
-
-      conversion_buffer = encode_terminal_code (string, 1, coding);
-      if (coding->produced > 0)
-       {
-         block_input ();
-         fwrite (conversion_buffer, 1, coding->produced,
-                 tty->output);
-         clearerr (tty->output);
-         if (tty->termscript)
-           fwrite (conversion_buffer, 1, coding->produced,
-                   tty->termscript);
-         unblock_input ();
-       }
-
-      /* Go to the previous position. */
-      cmgoto (tty, curY (tty), curX (tty) - 1);
-      cmplus (tty, 1);
-
-      /* Arrange that after writing the next glyph, the glyph on the
-         current character cell is somehow pushed to the bottom-right
-        corner. */
-      if (tty->TS_ins_char)
-       {
-         OUTPUT1 (tty, tty->TS_ins_char);
-       }
-      else if (tty->TS_ins_multi_chars)
-       {
-         char *buf = tparam (tty->TS_ins_multi_chars, 0, 0, 1,
-                             0, 0, 0);
-         OUTPUT1 (tty, buf);
-         xfree (buf);
-       }
-      else
-       {
-         tty_turn_on_insert (tty);
-       }
-
-      /* This is the last run.  */
-      coding->mode |= CODING_MODE_LAST_BLOCK;
-      conversion_buffer
-       = encode_terminal_code (&glyph_on_char_cell_before_last, 1,
-                               coding);
-      if (coding->produced > 0)
-       {
-         block_input ();
-         fwrite (conversion_buffer, 1, coding->produced,
-                 tty->output);
-         clearerr (tty->output);
-         if (tty->termscript)
-           fwrite (conversion_buffer, 1, coding->produced,
-                   tty->termscript);
-         unblock_input ();
-       }
-
-      tty_turn_off_insert (tty);
-    }
-
-  /* Turn appearance modes off.  */
-  turn_off_face (f, face_id);
-  tty_turn_off_highlight (tty);
-
-  cmcheckmagic (tty);
+  tty_write_glyphs_1 (f, string, len, -1);
 }
 
-#endif
-
 /* An implementation of insert_glyphs for termcap frames. */
 
 static void
@@ -2615,8 +2530,8 @@ tty_draw_row_with_mouse_face (struct window *w, struct 
glyph_row *row,
   cursor_to (f, pos_y, pos_x);
 
   if (draw == DRAW_MOUSE_FACE)
-    tty_write_glyphs_with_face (f, row->glyphs[TEXT_AREA] + start_hpos,
-                               nglyphs, face_id);
+    tty_write_glyphs_1 (f, row->glyphs[TEXT_AREA] + start_hpos,
+                       nglyphs, face_id);
   else if (draw == DRAW_NORMAL_TEXT)
     write_glyphs (f, row->glyphs[TEXT_AREA] + start_hpos, nglyphs);
 
-- 
2.37.1

-- 
Akib Azmain Turja

Find me on Mastodon at @akib@hostux.social.

This message is signed by me with my GnuPG key.  Its fingerprint is:

    7001 8CE5 819F 17A3 BBA6  66AF E74F 0EFA 922A E7F5

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]