Strange behaviour of Delete Line and Insert Line when used above the top margin #206

Closed
opened 2026-01-30 21:45:31 +00:00 by claunia · 5 comments
Owner

Originally created by @j4james on GitHub (Mar 28, 2018).

Originally assigned to: @zadjii-msft on GitHub.

  • Your Windows build number:

Microsoft Windows [Version 10.0.16299.309]

  • What you're doing and what's happening:

I was curious to see how the Delete Line (\033[M) and Insert Line (\033[L) escape sequences would behave when applied above the top margin of the scrolling region. So as a test, I labelled the first 8 lines of the screen with the numbers 1 to 8, set the top margin to line 4, then attempted to delete line 1.

This was the command I used:

printf "\033c1\n2\n3\n4\n5\n6\n7\n8\033[4r\033[H\033[M\033[r" && read -n 1

And this was the output I saw:

1
2
3
8

Instead of 1 row being deleted from line 1, I got 4 rows deleted from line 4.

I then tried the same thing with the Insert Line sequence:

printf "\033c1\n2\n3\n4\n5\n6\n7\n8\033[4r\033[H\033[L\033[r" && read -n 1

And the output this time was:

1
2
3
6
7
8

Instead of 1 row being inserted at line 1, I got 2 rows deleted from line 4!

  • What's wrong / what should be happening instead:

I don't think there is necessarily a "correct" behaviour in this situation, but I do think the current Windows behaviour is probably a bug.

One possible option would be to ignore these commands when used outside the defined margins (which I think is what XTerm does). Another option would be to handle the insert and delete as if the top margin had not been set, but still constrain the scrolling region within the bottom margin (which is how the Linux console behaves). Either choice would be preferable to the current behaviour.

Originally created by @j4james on GitHub (Mar 28, 2018). Originally assigned to: @zadjii-msft on GitHub. * Your Windows build number: Microsoft Windows [Version 10.0.16299.309] * What you're doing and what's happening: I was curious to see how the _Delete Line_ (`\033[M`) and _Insert Line_ (`\033[L`) escape sequences would behave when applied above the top margin of the scrolling region. So as a test, I labelled the first 8 lines of the screen with the numbers 1 to 8, set the top margin to line 4, then attempted to delete line 1. This was the command I used: printf "\033c1\n2\n3\n4\n5\n6\n7\n8\033[4r\033[H\033[M\033[r" && read -n 1 And this was the output I saw: 1 2 3 8 Instead of 1 row being deleted from line 1, I got 4 rows deleted from line 4. I then tried the same thing with the _Insert Line_ sequence: printf "\033c1\n2\n3\n4\n5\n6\n7\n8\033[4r\033[H\033[L\033[r" && read -n 1 And the output this time was: 1 2 3 6 7 8 Instead of 1 row being inserted at line 1, I got 2 rows **deleted** from line 4! * What's wrong / what should be happening instead: I don't think there is necessarily a "correct" behaviour in this situation, but I do think the current Windows behaviour is probably a bug. One possible option would be to ignore these commands when used outside the defined margins (which I think is what XTerm does). Another option would be to handle the insert and delete as if the top margin had not been set, but still constrain the scrolling region within the bottom margin (which is how the Linux console behaves). Either choice would be preferable to the current behaviour.
Author
Owner

@zadjii-msft commented on GitHub (Mar 28, 2018):

Boy I do love bugs with great straightforward repros. I also really love x forwarding working in WSL, because this becomes a really easy question to answer:

image

Clearly, we're not doing the right thing here. Even if there isn't a documented "right" way to do something, we're treating whatever xterm does as the right way

Filing a bug to address this.

@zadjii-msft commented on GitHub (Mar 28, 2018): Boy I do love bugs with great straightforward repros. I also really love x forwarding working in WSL, because this becomes a really easy question to answer: ![image](https://user-images.githubusercontent.com/18356694/38047838-82d09bf4-3278-11e8-8d11-957e0bf9079f.png) Clearly, we're not doing the right thing here. Even if there isn't a documented "right" way to do something, we're treating whatever xterm does as the right way Filing a bug to address this.
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 6, 2019):

It looks like we're still doing something strange here, but it's not nearly as strange as it used to be!

first case

(conhost on left, putty on right)
image

second case

image

@DHowett-MSFT commented on GitHub (Feb 6, 2019): It looks like we're still doing something strange here, but it's not nearly as strange as it used to be! ### first case (conhost on left, putty on right) ![image](https://user-images.githubusercontent.com/14316954/52320463-4dd90180-2984-11e9-9dce-b4fa2768aba9.png) ### second case ![image](https://user-images.githubusercontent.com/14316954/52320491-6d702a00-2984-11e9-8d09-df0adc198aab.png)
Author
Owner

@zadjii-msft commented on GitHub (Sep 4, 2019):

@j4james You're kinda going wild on the scrolling margins style bugs right now, you want me to give you this one too?

@zadjii-msft commented on GitHub (Sep 4, 2019): @j4james You're kinda going wild on the scrolling margins style bugs right now, you want me to give you this one too?
Author
Owner

@j4james commented on GitHub (Sep 4, 2019):

Ah yes, I've been meaning to come back to this. I think what we have now is actually the correct behaviour and we can close this issue.

Here's what the DEC STD 070 manual has to say about the Insert Line command:

Only that portion of the display between the top, bottom, left, and right margins is affected. IL is ignored if the Active Position is outside the Scroll Area.

Similarly for the Delete Line command:

Only that portion of the display between the top, bottom, left, and right margins is affected. DL is ignored if the active position is outside the scroll area.

So both of the test cases above should leave the numbers unchanged after the IL or DL since the cursor position is above the top margin. And that's how XTerm interprets it too:

image

So I think putty has probably got this wrong, and if we're matching XTerm then we've got it right.

@j4james commented on GitHub (Sep 4, 2019): Ah yes, I've been meaning to come back to this. I think what we have now is actually the correct behaviour and we can close this issue. Here's what the DEC STD 070 manual has to say about the _Insert Line_ command: > Only that portion of the display between the top, bottom, left, and right margins is affected. IL is ignored if the Active Position is outside the Scroll Area. Similarly for the _Delete Line_ command: > Only that portion of the display between the top, bottom, left, and right margins is affected. DL is ignored if the active position is outside the scroll area. So both of the test cases above should leave the numbers unchanged after the IL or DL since the cursor position is above the top margin. And that's how XTerm interprets it too: ![image](https://user-images.githubusercontent.com/4181424/64282441-565ede00-cf4d-11e9-93a2-a0915d9e794a.png) So I think putty has probably got this wrong, and if we're matching XTerm then we've got it right.
Author
Owner

@DHowett-MSFT commented on GitHub (Sep 4, 2019):

Really happy to hear that. Thank you!

@DHowett-MSFT commented on GitHub (Sep 4, 2019): Really happy to hear that. Thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#206