[hackers] [st] support REP (repeat) escape sequence || Avi Halachmi (:avih)

From: <git_AT_suckless.org>
Date: Sat, 16 May 2020 14:09:12 +0200 (CEST)

commit e8392b282c2eaa28725241a9612804fb55113da4
Author: Avi Halachmi (:avih) <avihpit_AT_yahoo.com>
AuthorDate: Thu May 14 18:18:07 2020 +0300
Commit: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
CommitDate: Sat May 16 14:08:10 2020 +0200

    support REP (repeat) escape sequence
    
    The sequence \e[Nb prints the last printed char N (more) times if it's
    printable, and it's ignored after newline or other control chars.
    
    This is Ecma-048/ANSI-X3.6 sequence and not DEC VT. It's supported by
    xterm, and ncurses uses it when possible, e.g. when TERM is xterm* (and
    with this commit also st*).
    
    xterm supports only codepoints<=255, possibly due to internal limits.
    We support any value/codepoint which was placed in a cell.
    
    To test:
    - tput rep 65 4 -> prints 'AAAA'
    - printf "\342\225\246\033[4b" -> prints U+2566 1+4 times.

diff --git a/st.c b/st.c
index 0d35613..54af098 100644
--- a/st.c
+++ b/st.c
_AT_@ -129,6 +129,7 @@ typedef struct {
         int charset; /* current charset */
         int icharset; /* selected charset for sequence */
         int *tabs;
+ Rune lastc; /* last printed char outside of sequence, 0 if control */
 } Term;
 
 /* CSI Escape sequence structs */
_AT_@ -1648,6 +1649,12 @@ csihandle(void)
                 if (csiescseq.arg[0] == 0)
                         ttywrite(vtiden, strlen(vtiden), 0);
                 break;
+ case 'b': /* REP -- if last char is printable print it <n> more times */
+ DEFAULT(csiescseq.arg[0], 1);
+ if (term.lastc)
+ while (csiescseq.arg[0]-- > 0)
+ tputc(term.lastc);
+ break;
         case 'C': /* CUF -- Cursor <n> Forward */
         case 'a': /* HPR -- Cursor <n> Forward */
                 DEFAULT(csiescseq.arg[0], 1);
_AT_@ -2373,6 +2380,8 @@ check_control_code:
                 /*
                  * control codes are not shown ever
                  */
+ if (!term.esc)
+ term.lastc = 0;
                 return;
         } else if (term.esc & ESC_START) {
                 if (term.esc & ESC_CSI) {
_AT_@ -2422,6 +2431,7 @@ check_control_code:
         }
 
         tsetchar(u, &term.c.attr, term.c.x, term.c.y);
+ term.lastc = u;
 
         if (width == 2) {
                 gp->mode |= ATTR_WIDE;
diff --git a/st.info b/st.info
index d0694e2..e5393db 100644
--- a/st.info
+++ b/st.info
_AT_@ -184,6 +184,7 @@ st-mono| simpleterm monocolor,
 # XTerm extensions
         rmxx=\E[29m,
         smxx=\E[9m,
+ rep=%p1%c\E[%p2%{1}%-%db,
 # tmux extensions, see TERMINFO EXTENSIONS in tmux(1)
         Tc,
         Ms=\E]52;%p1%s;%p2%s\007,
Received on Sat May 16 2020 - 14:09:12 CEST

This archive was generated by hypermail 2.3.0 : Sat May 16 2020 - 14:12:35 CEST