bakkeby / st-flexipatch

An st build with preprocessor directives to decide which patches to include during build time
MIT License
347 stars 107 forks source link

osc133: initial patch implementation #127

Open UtkarshVerma opened 5 months ago

UtkarshVerma commented 5 months ago

This patch introduces support for OSC133 as discussed in #126. It borrows veltza's st-sx implementation and introduces two new key bindings, <ctrl+shift+z/x> to scroll between prompts.

veltza commented 5 months ago

I'm wondering if the OSC 133 should be a core feature since it doesn't do anything by itself. Only certain patches such as the scrollback and externalpipe can take advantage of it.

bakkeby commented 2 months ago

I'd propose these changes as the patch seems to specifically depend on the reflow patch. I think technically it would be feasible to make it work with the scrollback patch as well, but that can be added later if need be.

diff --git a/config.def.h b/config.def.h
index 18df30f..fe1584a 100644
--- a/config.def.h
+++ b/config.def.h
@@ -457,7 +457,7 @@ static Shortcut shortcuts[] = {
        #if INVERT_PATCH
        { TERMMOD,              XK_X,           invert,          { 0 } },
        #endif // INVERT_PATCH
-       #if OSC133_PATCH
+       #if OSC133_PATCH && REFLOW_PATCH
        { TERMMOD,              XK_Z,           scrolltoprompt,  {.i = -1}, S_PRI },
        { TERMMOD,              XK_X,           scrolltoprompt,  {.i =  1}, S_PRI },
        #endif // OSC133_PATCH
diff --git a/patch/x_include.c b/patch/x_include.c
index 30b77da..62664b1 100644
--- a/patch/x_include.c
+++ b/patch/x_include.c
@@ -47,6 +47,6 @@
 #if XRESOURCES_PATCH
 #include "xresources.c"
 #endif
-#if OSC133_PATCH
+#if OSC133_PATCH && REFLOW_PATCH
 #include "osc133.c"
 #endif
diff --git a/patch/x_include.h b/patch/x_include.h
index 859a58a..6908792 100644
--- a/patch/x_include.h
+++ b/patch/x_include.h
@@ -41,6 +41,6 @@
 #if XRESOURCES_PATCH
 #include "xresources.h"
 #endif
-#if OSC133_PATCH
+#if OSC133_PATCH && REFLOW_PATCH
 #include "osc133.h"
-#endif // OSC133_PATCH
+#endif
diff --git a/patches.def.h b/patches.def.h
index c4d613c..a0384eb 100644
--- a/patches.def.h
+++ b/patches.def.h
@@ -295,7 +295,7 @@
 #define OPENURLONCLICK_PATCH 0

 /* This patch allows jumping between prompts by utilizing the OSC 133 escape sequence
- * emitted by shells.
+ * emitted by shells. This patch depends on the reflow patch.
  *
  * https://codeberg.org/dnkl/foot#jumping-between-prompts
  */
veltza commented 2 months ago

I'd propose these changes as the patch seems to specifically depend on the reflow patch. I think technically it would be feasible to make it work with the scrollback patch as well, but that can be added later if need be.

True, reflow uses term.histf and scrollback uses term.histn variable. Same purpose, but different name. It's easy to fix:

diff --git a/patch/osc133.c b/patch/osc133.c
index 30c3e35..6d72453 100644
--- a/patch/osc133.c
+++ b/patch/osc133.c
@@ -1,6 +1,10 @@
 void scrolltoprompt(const Arg *arg) {
        int x, y;
+       #if REFLOW_PATCH
        int top = term.scr - term.histf;
+       #else
+       int top = term.scr - term.histn;
+       #endif // REFLOW_PATCH
        int bot = term.scr + term.row-1;
        int dy = arg->i;
        Line line;