Ruben Hamers
Ruben Hamers

Reputation: 293

How exactly does the scroll region work in xterm terminals?

I'm implementing a custom pseudo-terminal and currently I'm implementing the ANSI control sequence that sets the scroll region

Using the following command:

CSI Ps ; Ps r
      Set Scrolling Region [top;bottom] (default = full size of
      window) (DECSTBM), VT100.

As described here.

I'm trying to understand how the scrolling region works exactly and my friendly AI assistants don't seem to provide me with meaningful information. So, my question is: how does the scrolling region impact the rest of the buffer? As far as I understand, any rows on the screen, outside of the scroll region are unaffected by edits etc. Let me explain:

Lets say we have a screen of 5 rows, and 5 columns and a buffer of 10 rows, all cells populated with the character x the screen would look like this:

------------------- <-- top edge of screen
line 1 : xxxxx
line 2 : xxxxx
line 3 : xxxxx
line 4 : xxxxx
line 5 : xxxxx
------------------ <-- bottom edge of screen
line 6 : xxxxx
line 7 : xxxxx
line 8 : xxxxx
line 9 : xxxxx
line 10: xxxxx

So lines 6 to 10 are in the buffer.

Now when I execute the sequence CSI 2;4r the scrolling region will be set to line 2 to 4.

Now lets say I insert a line at line 3, containing only y characters. Would the terminal look like this?

------------------- <-- top edge of screen
line 1 : xxxxx
line 2 : xxxxx -- scoll region
line a : yyyyy
line 3 : xxxxx -- scroll
line 5 : xxxxx
------------------ <-- bottom edge of screen
line 4 : xxxxx 
line 6 : xxxxx
line 7 : xxxxx
line 8 : xxxxx
line 9 : xxxxx
line 10: xxxxx

And what happens when I reset the scroll region to default (full-screen). How will line 4 be treated? I have the same difficulty to understand when I scroll (using control sequences) the screen like so:

line 2 : xxxxx
line 3 : xxxxx
line 4 : xxxxx
------------------- <-- top edge of screen
line 1 : xxxxx
line 5 : xxxxx -- scroll region
line 6 : xxxxx
line 7 : xxxxx -- scroll region
line 5 : xxxxx
------------------ <-- bottom edge of screen
line 9 : xxxxx
line 10: xxxxx

What happens when I now insert a line at row 3, and then reset the scroll area again. What would be the state of the buffer exactly?

I'm probably making this far more difficult than it should be but I'm trying to understand how this works.

Thanks for the support,

Ruben

Upvotes: 2

Views: 126

Answers (0)

Related Questions