st-flexipatch icon indicating copy to clipboard operation
st-flexipatch copied to clipboard

osc133: initial patch implementation

Open UtkarshVerma opened this issue 11 months ago • 3 comments

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.

UtkarshVerma avatar Mar 18 '24 02:03 UtkarshVerma

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.

veltza avatar Mar 21 '24 09:03 veltza

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
  */

bakkeby avatar Jul 05 '24 19:07 bakkeby

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;

veltza avatar Jul 06 '24 11:07 veltza

@bakkeby @veltza I have incorporated your changes and have tested it with both scrollback and reflow patches. It works. Please let me know if anything else is required.

UtkarshVerma avatar Sep 30 '24 08:09 UtkarshVerma

I just noticed that ctrl+shift+x clashes with the invert patch. So, maybe we should change the default keys to ctrl+shift+a/z?

veltza avatar Sep 30 '24 14:09 veltza

Fine with me. I'll wait for bakkeby.

UtkarshVerma avatar Sep 30 '24 15:09 UtkarshVerma

Ok, let him decide. But either way, I give this the green light.

veltza avatar Sep 30 '24 17:09 veltza

I am not too concerned about what the default keybindings are. Using A/Z may be suitable for QUERTY and AZERTY, while less so for QUERTZ. Probably not something to think too much about.

Alternatively one could use Ctrl+XK_Page_Up / XK_Page_Down as the default and users can optimise as they please in their own configuration.

Being able to scroll to the previous prompt(s) is a really cool feature.

bakkeby avatar Oct 01 '24 07:10 bakkeby

Since everyone is onboard. Please feel free to merge the PR @bakkeby.

UtkarshVerma avatar Oct 01 '24 13:10 UtkarshVerma

Having given it some thought I think that it makes sense to move the default configuration to use Ctrl + PgUp/Down for this scroll feature. It aligns well with the scrollback's keybindings of Shift + PgUp/Down.

I'll merge and apply that.

bakkeby avatar Oct 01 '24 19:10 bakkeby

Thanks a lot to both of you. This is a really handy feature!

UtkarshVerma avatar Oct 02 '24 07:10 UtkarshVerma