[hackers] [st] Fix cursor move with wide glyphs || Quentin Rameau

From: <git_AT_suckless.org>
Date: Sun, 25 Feb 2024 11:57:03 +0100 (CET)

commit 7473a8d1a57e5f9aba41b953f4e498c35e1c9dc5
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Sun Feb 25 01:31:31 2024 +0100
Commit: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
CommitDate: Sun Feb 25 11:56:43 2024 +0100

    Fix cursor move with wide glyphs
    
    st would always move back 1 column,
    even with wide glyhps (using more than a single column).
    
    The glyph rune is set on its first column,
    and the other ones are to 0,
    so loop until we detect the start of the previous glyph.

diff --git a/st.c b/st.c
index 034954d..77c3e8a 100644
--- a/st.c
+++ b/st.c
_AT_@ -86,8 +86,8 @@ enum escape_state {
 
 typedef struct {
         Glyph attr; /* current char attributes */
- int x;
- int y;
+ int x; /* terminal column */
+ int y; /* terminal row */
         char state;
 } TCursor;
 
_AT_@ -2175,12 +2175,16 @@ tstrsequence(uchar c)
 void
 tcontrolcode(uchar ascii)
 {
+ size_t i;
+
         switch (ascii) {
         case '\t': /* HT */
                 tputtab(1);
                 return;
         case '\b': /* BS */
- tmoveto(term.c.x-1, term.c.y);
+ for (i = 1; term.c.x && term.line[term.c.y][term.c.x - i].u == 0; ++i)
+ ;
+ tmoveto(term.c.x - i, term.c.y);
                 return;
         case '\r': /* CR */
                 tmoveto(0, term.c.y);
Received on Sun Feb 25 2024 - 11:57:03 CET

This archive was generated by hypermail 2.3.0 : Sun Feb 25 2024 - 12:00:39 CET