]> Sergey Matveev's repositories - st.git/commitdiff
Add support for DSR response "OK" escape sequence
authorAdam Price <komidore64@gmail.com>
Tue, 7 Feb 2023 18:54:29 +0000 (19:54 +0100)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Tue, 7 Feb 2023 18:57:34 +0000 (19:57 +0100)
"VT100 defines an escape sequence [1] called Device Status Report (DSR). When
the DSR sequence received is `csi 5n`, an "OK" response `csi 0n` is returned.
This patch adds that "OK" response.

I encountered this missing sequence when I noticed that fzf [2] would clobber
my prompt whenever completing a find.

To test that ST doesn't currently respond to `csi 5n`, use fzf's shell
extension in ST's repo to complete the path for a file.

    my-fancy-prompt $ vim **<tab>
    <select a file>
    st.c

Select a file with <enter>, and notice that fzf clobbers some or all of your
prompt.

After applying this patch, do the same test as above and notice that fzf has no
longer clobbered your prompt by placing the file name in the correct position
in your command.

    my-fancy-prompt $ vim **<tab>
    <select a file>
    my-fancy prompt $ vim st.c

Thank you for considering my first patch submission.

[1] https://www.xfree86.org/current/ctlseqs.html#VT100%20Mode
[2] https://github.com/junegunn/fzf
"

Patch slightly adapted with input from the mailinglist,

st.c

diff --git a/st.c b/st.c
index 34c27adf3f755bd60cc6b45f1c34af8bb48c98bb..49357cc9d11b1ad6bd8a954ee626f3a5d309877b 100644 (file)
--- a/st.c
+++ b/st.c
@@ -1769,11 +1769,18 @@ csihandle(void)
        case 'm': /* SGR -- Terminal attribute (color) */
                tsetattr(csiescseq.arg, csiescseq.narg);
                break;
-       case 'n': /* DSR – Device Status Report (cursor position) */
-               if (csiescseq.arg[0] == 6) {
+       case 'n': /* DSR -- Device Status Report */
+               switch (csiescseq.arg[0]) {
+               case 5: /* Status Report "OK" `0n` */
+                       ttywrite("\033[0n", sizeof("\033[0n") - 1, 0);
+                       break;
+               case 6: /* Report Cursor Position (CPR) "<row>;<column>R" */
                        len = snprintf(buf, sizeof(buf), "\033[%i;%iR",
-                                       term.c.y+1, term.c.x+1);
+                                      term.c.y+1, term.c.x+1);
                        ttywrite(buf, len, 0);
+                       break;
+               default:
+                       goto unknown;
                }
                break;
        case 'r': /* DECSTBM -- Set Scrolling Region */