CUU and CUD should not move "across" margins #4097

Open
opened 2026-01-30 23:37:53 +00:00 by claunia · 0 comments
Owner

Originally created by @j4james on GitHub (Sep 27, 2019).

Originally assigned to: @zadjii-msft on GitHub.

Environment

Windows build number: Version 10.0.18362.295
Also tested with a recent commit 7faf3342e0

Steps to reproduce

In a conhost WSL shell, execute the following command:

echo -e "\e[6;19r\e[24H\e[99ACUU\e[1H\e[99BCUD\e[r"

This does the following:

  • sets the top and bottom DECSTBM margins to 6 and 19
  • moves to line 24 (i.e. below the bottom margin)
  • executes the CUU sequence with a count of 99, to move up 99 lines
  • writes out CUU
  • moves to line 1 (i.e. above the top margin)
  • executes the CUD sequence with a count of 99, to move down 99 lines
  • writes out CUD

Expected behavior

Quoting from the DEC STD 070 manual:

If the Active Position is at or below the Top Margin when the CUU control is executed, and an attempt is made to move the Active Position above the Top Margin, the control will be executed until the Active Position reaches the Top Margin. The Active Position will not move beyond the Top Margin.

Similarly for the CUD command:

If the Active Position is at or above the Bottom Margin when the CUD control is executed, and an attempt is made to move the Active Position below the Bottom Margin, the control will be executed until the Active Position reaches the Bottom Margin. The Active position will not move beyond the Bottom Margin.

So I would expect the CUU sequence to stop on line 6, the top margin, and the CUB sequence to stop on line 19, the bottom margin.

This is what the output looks like in XTerm:

image

Actual behavior

In the Windows console, the movement isn't constrained by the margins. As a result, the CUU sequences ends up at the top of the viewport, and the CUD sequences ends up at the bottom.

image

Note that this isn't a regression of #170. We do get it right if the initial cursor position was inside the margins. It's just when it starts off outside the margins that it's not being constrained.

The complication is that you sometimes don't want the cursor position constrained. For example, if you're moving up (with CUU), and you started off above the top margin, then there's no need to constrain the position below that margin.

Originally created by @j4james on GitHub (Sep 27, 2019). Originally assigned to: @zadjii-msft on GitHub. # Environment Windows build number: Version 10.0.18362.295 Also tested with a recent commit 7faf3342e0187841d590fd018452c5c69fd52271 # Steps to reproduce In a conhost WSL shell, execute the following command: echo -e "\e[6;19r\e[24H\e[99ACUU\e[1H\e[99BCUD\e[r" This does the following: - sets the top and bottom [`DECSTBM`](https://vt100.net/docs/vt510-rm/DECSTBM.html) margins to 6 and 19 - moves to line 24 (i.e. below the bottom margin) - executes the [`CUU`](https://vt100.net/docs/vt510-rm/CUU.html) sequence with a count of 99, to move up 99 lines - writes out *CUU* - moves to line 1 (i.e. above the top margin) - executes the [`CUD`](https://vt100.net/docs/vt510-rm/CUD.html) sequence with a count of 99, to move down 99 lines - writes out *CUD* # Expected behavior Quoting from the DEC STD 070 manual: > If the Active Position is at or below the Top Margin when the CUU control is executed, and an attempt is made to move the Active Position above the Top Margin, the control will be executed until the Active Position reaches the Top Margin. The Active Position will not move beyond the Top Margin. Similarly for the `CUD` command: > If the Active Position is at or above the Bottom Margin when the CUD control is executed, and an attempt is made to move the Active Position below the Bottom Margin, the control will be executed until the Active Position reaches the Bottom Margin. The Active position will not move beyond the Bottom Margin. So I would expect the `CUU` sequence to stop on line 6, the top margin, and the `CUB` sequence to stop on line 19, the bottom margin. This is what the output looks like in XTerm: ![image](https://user-images.githubusercontent.com/4181424/65733165-3ee6c100-e0c5-11e9-9d53-5490453c6b02.png) # Actual behavior In the Windows console, the movement isn't constrained by the margins. As a result, the `CUU` sequences ends up at the top of the viewport, and the `CUD` sequences ends up at the bottom. ![image](https://user-images.githubusercontent.com/4181424/65733174-473efc00-e0c5-11e9-9bf3-cf3cfb47ec28.png) Note that this isn't a regression of #170. We do get it right if the initial cursor position was inside the margins. It's just when it starts off outside the margins that it's not being constrained. The complication is that you sometimes *don't* want the cursor position constrained. For example, if you're moving up (with `CUU`), and you started off above the top margin, then there's no need to constrain the position below that margin.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4097