0

For example, on vim, when you scroll, it knows to move the cursor up and down, but so far, following this tutorial, scrolling will take you off the page of the editor.

For example, you can note that the following code is unable to catch the scroll action, and the terminal simply scrolls:

#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

struct termios orig_termios;

void
disable_raw_mode (void)
{
  tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios);
}

void
enable_raw_mode (void)
{
  tcgetattr(STDIN_FILENO, &orig_termios);
  atexit(disable_raw_mode);

  struct termios raw = orig_termios;
  raw.c_iflag &= ~(BRKINT | INPCK | PARMRK | INLCR | IGNCR | ISTRIP | ICRNL | IXON);
  raw.c_oflag &= ~(OPOST);
  raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
  raw.c_cflag &= ~(CSIZE | PARENB);
  raw.c_cflag |= (CS8);


  tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
}

int
main (void)
{
  enable_raw_mode();
  
  char c;
  while ( read(STDIN_FILENO,  &c, 1) == 1 )
    {
      if (iscntrl(c))
        printf("%d\n", c);
      else
        printf("%d ('%c')\n", c, c);
    }

  return 0;
}
Y. E.
  • 687
  • 1
  • 10
  • 29
user129393192
  • 797
  • 1
  • 8
  • This looks like it should be helpful: https://stackoverflow.com/questions/46627983/what-is-the-correct-xterm-ansi-sequence-for-mouse-wheel-and-or-scroll-prefera – Barmar Jul 30 '23 at 17:25
  • Let me specify further. I am unable to currently catch them. I'll provide some code. – user129393192 Jul 30 '23 at 17:37
  • As I understand it, it just sends escape sequences similar to the up and down arrows. Can you catch those? – Barmar Jul 30 '23 at 17:37
  • Up down is catchable @Barmar. Try the program I just posted if you'd like to see. Scroll actions and things like `PageUp` and `PageDown` are not. – user129393192 Jul 30 '23 at 17:39
  • I think you may need to go into the alternate screen, so it doesn't just do the scrolling in the terminal emulator's scrollback buffer. – Barmar Jul 30 '23 at 17:39
  • Thanks @Barmar, I'm able to using [this](https://stackoverflow.com/questions/39188508/how-curses-preserves-screen-contents) answer, but scrolling still occurs, despite the alternate screen. – user129393192 Jul 30 '23 at 17:54
  • You can see this yourself by running `tput smcup` and scrolling and the scroll action remains not catchable. If you run `vi`, you can use the scroll bar to scroll away from it, but `vi` itself catches the the scroll action. – user129393192 Jul 30 '23 at 18:00
  • Use `script` to start a transcript, run `vim` or `less`, and do some scrolling. Exit script and view the transcript file with `cat -v transcript`. You'll see the escape sequences that vim or less sends to the terminal to enable this feature. – Barmar Jul 30 '23 at 21:46
  • I wasn't able to find anything @Barmar. What I am finding is that some terminals send key events for mouse scroll in alternate screen, but this is not true for me. – user129393192 Jul 31 '23 at 14:42
  • If it works for `vim` then it has to be sending escape sequences, since it has no direct access to the mouse. – Barmar Jul 31 '23 at 15:19
  • I was finally able to find it [here](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking) @Barmar. Unfortunately, I haven't been able to find anything on a standardized set of escape sequences it would send back. I also can't find the same codes I used anywhere in the `vim` log. – user129393192 Jul 31 '23 at 16:10

0 Answers0