0

While trying to make vim work correctly on my operating system's console, I noticed it writes to stdout the following escape sequence before scrolling: \x1b[?1c.

The problem is I wasn't able to find anywhere what that specific sequence means. I've checked:

Can anybody help me solve this mystery?

P.S. In case some additional context might help, the sequence is used in the following context:

\x1b[?25l\x1b[?1c\x1b[3;24r\x1b[3;1H\x1b[L

vvaltchev
  • 609
  • 3
  • 20
  • That's an example of ANSI escape sequences. The nice thing about ANSI sequences is they have a well defined format, so it's easy to ignore if the software or device doesn't recognize it. – Mark Ransom Jan 21 '20 at 19:52
  • @MarkRansom I totally agree. The problem is that if you want a beast like `vim` to work, you have to implement pretty much everything it wants to use (otherwise visual problems will occur). The sad story is that in theory `vim` does not really *need* more what my console already supports (~90% of the stuff), but it uses some sophisticated escape sequences as an optimization in order to reduce the screen redraws. It's a powerful application, but with a lot of demands too. – vvaltchev Jan 21 '20 at 21:33
  • 1
    Moderators: it is **unfair** and **inconsistent** to close this question as off-topic for StackOverflow while tens of other questions on the very same topic (escape sequences) exist here and have not been closed. Either close them all, or re-open this. I got my answer, but that's not the point. See: [1] https://stackoverflow.com/questions/29939026/ [2] https://stackoverflow.com/questions/4842424/ [3] https://stackoverflow.com/questions/9949315/ [4] https://stackoverflow.com/questions/15682537/ [5] https://stackoverflow.com/questions/42072092/ The list goes on and on. – vvaltchev Jan 25 '20 at 14:20
  • Consistency is not a feature of StackOverflow, get used to it. The "moderators" in this case are just people who have been around long enough to collect a lot of reputation points. Be happy you got an answer, many aren't so lucky. – Mark Ransom Jan 25 '20 at 16:53

1 Answers1

2

Use the source. Linux kernel handles \x1b[?1c in this chunk:

    case 'c':
        if (vc->vc_ques) {
            if (vc->vc_par[0])
                vc->vc_cursor_type = vc->vc_par[0] | (vc->vc_par[1] << 8) | (vc->vc_par[2] << 16);
            else
                vc->vc_cursor_type = cur_default;
            return;
        }
        break;

and from context, you may understand that vc_par is an array of the parameters (which is only 1 in this case). So it is setting vc_cursor_type to 1. According to the documentation for Linux soft cursor, that makes the cursor invisible:

first Parameter

    specifies cursor size:

    0=default
    1=invisible
    2=underline,
    ...
    8=full block
    + 16 if you want the software cursor to be applied
    + 32 if you want to always change the background color
    + 64 if you dislike having the background the same as the
         foreground.

In context, vim is doing this right after \x1b[?25l (make the cursor hidden) and before changing the scrolling region \x1b[3;24r (which would move the cursor), and this sequence is just added insurance that there will be no cursor flashing as the sequence is executed on the Linux console.

Of the links cited in the example, only console_codes(4) is relevant. It does not appear there because the soft cursor feature was added later than the original manual page, and it did not occur to others later when revising the manual page. (Actually no one's done any recent improvements to it, as noted in a recent discussion).

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • Thanks, man! You solved the "mystery" providing also some historical background. I just wanted to add that the other links were kind of relevant to me because a program can use escape sequences that are available only on some consoles and get completely ignored on the others. Since I didn't know `console_codes(4)` was incomplete, it sounded like a valid theory :-) – vvaltchev Jan 23 '20 at 23:25