From eed328240d04caedfaeef83342cf219758e20ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sat, 6 Jul 2024 01:00:30 +0200 Subject: [PATCH] Add \e[ m escape to mark a line. Ctrl+PgUp/+PgDn scroll to marked lines Primarily useful for C++ enthusiasts so if you get a megabyte of errors you can go back to the first one Recommended usage: PS1="$PS1\e[ m" Ref: https://101010.pl/@atax1a@infosec.exchange/112734806523834451 --- config.def.h | 2 ++ st.c | 41 +++++++++++++++++++++++++++++++++++++++++ st.h | 3 +++ 3 files changed, 46 insertions(+) diff --git a/config.def.h b/config.def.h index fc3079e..5bf8132 100644 --- a/config.def.h +++ b/config.def.h @@ -226,7 +226,9 @@ static Shortcut shortcuts[] = { { ShiftMask, XK_Insert, selpaste, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} }, + { ControlMask, XK_Page_Up, kscrolltoprevmark }, { ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} }, + { ControlMask, XK_Page_Down, kscrolltonextmark }, { TERMMOD, XK_I, iso14755, {.i = 0} }, }; diff --git a/st.c b/st.c index ddd14c1..353d6c6 100644 --- a/st.c +++ b/st.c @@ -1104,6 +1104,44 @@ kscrollup(const Arg* a) } } +void +kscrolltonextmark(const Arg* a) +{ + int orig_scr = term.scr; + + while (--term.scr >= 0) + if (TLINE(0)->mode & ATTR_MARKED) { + found: + if (term.scr != orig_scr) { + selscroll(0, term.scr - orig_scr); + tfulldirt(); + } + return; + } + + term.scr = 0; + for(int i = 0; i < term.row; ++i) + if (TLINE(i)->mode & ATTR_MARKED) + goto found; + + term.scr = orig_scr; +} + +void +kscrolltoprevmark(const Arg* a) +{ + int orig_scr = term.scr; + + while (++term.scr <= HISTSIZE) + if (TLINE(0)->mode & ATTR_MARKED) { + selscroll(0, term.scr - orig_scr); + tfulldirt(); + return; + } + + term.scr = orig_scr; +} + void tscrolldown(int orig, int n, int copyhist) { @@ -1881,6 +1919,9 @@ csihandle(void) if (xsetcursor(csiescseq.arg[0])) goto unknown; break; + case 'm': /* mark line to quickly scroll back to later */ + term.line[term.c.y]->mode |= ATTR_MARKED; + break; default: goto unknown; } diff --git a/st.h b/st.h index 9dba57d..469e5c4 100644 --- a/st.h +++ b/st.h @@ -35,6 +35,7 @@ enum glyph_attribute { ATTR_WDUMMY = 1 << 10, ATTR_BOXDRAW = 1 << 11, ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, + ATTR_MARKED = 1 << 12, }; enum selection_mode { @@ -84,6 +85,8 @@ void draw(void); void kscrolldown(const Arg *); void kscrollup(const Arg *); +void kscrolltonextmark(const Arg *); +void kscrolltoprevmark(const Arg *); void iso14755(const Arg *); void printscreen(const Arg *); void printsel(const Arg *); -- 2.39.2