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

Open
opened 2026-01-30 21:45:25 +00:00 by claunia · 0 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#203