1

I have been experimenting with the DECSTBM escape sequence in xterm (v353). Although generally working, I had one issue:

I would set the scrolling region to one line less than the window height. When viewing files with less (or the man), it would print lines inside the scroll region, but it generates one line more than would fit. When scrolling back up the status line slips outside the scroll region and scrolling generally seems to break.
Another example is the 'more' completion prompt from readline (bash), it would print as many lines as the window size reports, in my case scrolling the first line off screen.

By digging through code I found that less seems to ask the system directly for window size (using ioctl), therefore bypassing size given by environment variables COLUMNS or LINES. Is there a way to communicate the available scroll region instead of the window size to programs querying the terminal size?

2
  • Try stty rows 25; it will set the value returned by ioctl(TIOCGWINSZ) until you resize the terminal window.
    – mosvy
    Mar 7, 2020 at 22:30
  • argh, so I have been looking in the wrong man pages. stty rows <num> gives me what I want. Can you post this as answer?
    – Loebl
    Mar 7, 2020 at 22:43

1 Answer 1

0

Is there a way to communicate the available scroll region instead of the window size to programs querying the terminal size?

Try stty rows <lines>; it will set (via ioctl(TIOCSWINSZ)) the value returned by the kernel via ioctl(TIOCGWINSZ) to the programs who ask for it.

Your terminal emulator will update it when you resize the window.

This worked for me (in not very thorough testing):

winch(){
    [ "$LINES" = "$winch_l" ] && return
    winch_l=$((LINES-1));
    stty rows "$winch_l"
    printf '\033[S\033[A'     # scroll 1 up, cursor 1 up
    printf '\0337'            # save cursor (DECSC)
    printf '\033[1;%dr' "$winch_l"  # set scroll region (DECSTBM)
    printf '\0338'            # restore cursor (DECRC)
    kill -WINCH "$$"          # force prompt redraw; ymmv
}
trap winch WINCH
winch

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.