st-scrollback-mark-0.9.2.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       st-scrollback-mark-0.9.2.diff (2933B)
       ---
            1 From eed328240d04caedfaeef83342cf219758e20ded Mon Sep 17 00:00:00 2001
            2 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczleweli@nabijaczleweli.xyz>
            3 Date: Sat, 6 Jul 2024 01:00:30 +0200
            4 Subject: [PATCH] Add \e[ m escape to mark a line. Ctrl+PgUp/+PgDn scroll to
            5  marked lines
            6 
            7 Primarily useful for C++ enthusiasts so if you get a megabyte of errors
            8 you can go back to the first one
            9 
           10 Recommended usage: PS1="$PS1\e[ m"
           11 
           12 Ref: https://101010.pl/@atax1a@infosec.exchange/112734806523834451
           13 ---
           14  config.def.h |  2 ++
           15  st.c         | 41 +++++++++++++++++++++++++++++++++++++++++
           16  st.h         |  3 +++
           17  3 files changed, 46 insertions(+)
           18 
           19 diff --git a/config.def.h b/config.def.h
           20 index fc3079e..5bf8132 100644
           21 --- a/config.def.h
           22 +++ b/config.def.h
           23 @@ -226,7 +226,9 @@ static Shortcut shortcuts[] = {
           24          { ShiftMask,            XK_Insert,      selpaste,       {.i =  0} },
           25          { TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
           26          { ShiftMask,            XK_Page_Up,     kscrollup,      {.i = -1} },
           27 +        { ControlMask,          XK_Page_Up,     kscrolltoprevmark         },
           28          { ShiftMask,            XK_Page_Down,   kscrolldown,    {.i = -1} },
           29 +        { ControlMask,          XK_Page_Down,   kscrolltonextmark         },
           30          { TERMMOD,              XK_I,           iso14755,       {.i =  0} },
           31  };
           32  
           33 diff --git a/st.c b/st.c
           34 index ddd14c1..353d6c6 100644
           35 --- a/st.c
           36 +++ b/st.c
           37 @@ -1104,6 +1104,44 @@ kscrollup(const Arg* a)
           38          }
           39  }
           40  
           41 +void
           42 +kscrolltonextmark(const Arg* a)
           43 +{
           44 +        int orig_scr = term.scr;
           45 +
           46 +        while (--term.scr >= 0)
           47 +                if (TLINE(0)->mode & ATTR_MARKED) {
           48 +                found:
           49 +                        if (term.scr != orig_scr) {
           50 +                                selscroll(0, term.scr - orig_scr);
           51 +                                tfulldirt();
           52 +                        }
           53 +                        return;
           54 +                }
           55 +
           56 +        term.scr = 0;
           57 +        for(int i = 0; i < term.row; ++i)
           58 +                if (TLINE(i)->mode & ATTR_MARKED)
           59 +                        goto found;
           60 +
           61 +        term.scr = orig_scr;
           62 +}
           63 +
           64 +void
           65 +kscrolltoprevmark(const Arg* a)
           66 +{
           67 +        int orig_scr = term.scr;
           68 +
           69 +        while (++term.scr <= HISTSIZE)
           70 +                if (TLINE(0)->mode & ATTR_MARKED) {
           71 +                        selscroll(0, term.scr - orig_scr);
           72 +                        tfulldirt();
           73 +                        return;
           74 +                }
           75 +
           76 +        term.scr = orig_scr;
           77 +}
           78 +
           79  void
           80  tscrolldown(int orig, int n, int copyhist)
           81  {
           82 @@ -1881,6 +1919,9 @@ csihandle(void)
           83                          if (xsetcursor(csiescseq.arg[0]))
           84                                  goto unknown;
           85                          break;
           86 +                case 'm': /* mark line to quickly scroll back to later */
           87 +                        term.line[term.c.y]->mode |= ATTR_MARKED;
           88 +                        break;
           89                  default:
           90                          goto unknown;
           91                  }
           92 diff --git a/st.h b/st.h
           93 index 9dba57d..469e5c4 100644
           94 --- a/st.h
           95 +++ b/st.h
           96 @@ -35,6 +35,7 @@ enum glyph_attribute {
           97          ATTR_WDUMMY     = 1 << 10,
           98          ATTR_BOXDRAW    = 1 << 11,
           99          ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
          100 +        ATTR_MARKED     = 1 << 12,
          101  };
          102  
          103  enum selection_mode {
          104 @@ -84,6 +85,8 @@ void draw(void);
          105  
          106  void kscrolldown(const Arg *);
          107  void kscrollup(const Arg *);
          108 +void kscrolltonextmark(const Arg *);
          109 +void kscrolltoprevmark(const Arg *);
          110  void iso14755(const Arg *);
          111  void printscreen(const Arg *);
          112  void printsel(const Arg *);
          113 -- 
          114 2.39.2
          115