TAB character shouldn't move past the end of the line #4423

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

Originally created by @j4james on GitHub (Oct 12, 2019).

Environment

Windows build number: Version 10.0.18362.295
Also tested in a recent conhost build: commit 82dd0b978a

Steps to reproduce

Open a bash shell and execute:

printf "A\e[999C\tB"

This outputs an A, then a CUF sequence to move the cursor position to the end of the line, then a TAB control character, and finally a B.

Expected behavior

When in VT mode, a TAB character should not move the cursor position past the end of the line, so the B should be output on the same line as the A, in the last column.

Here's what the above test case looks like in XTerm:

image

Actual behavior

The TAB moves the cursor position onto the start of the next line, so the B is output below the A.

This is what the test case looks like in the Windows console:

image

Proposed fix

In the SCREEN_INFORMATION::GetForwardTab method, simply get rid of the first condition that checks for the cursor being in the last column. See here:

82dd0b978a/src/host/screenInfo.cpp (L2222-L2230)

That case should be handled by the second condition (any X pos greater than or equal to the last tab stop will be set to the last column).

The change shouldn't have any effect on legacy code, because the GetForwardTab method is only used in VT mode, as far as I can tell - the legacy tab handling is a completely separate implementation.

I'd be happy to provide a PR for this if nobody disagrees with the suggested fix.

Originally created by @j4james on GitHub (Oct 12, 2019). # Environment Windows build number: Version 10.0.18362.295 Also tested in a recent conhost build: commit 82dd0b978ae74771b5e9049bbbc6d5ff6c1581aa # Steps to reproduce Open a bash shell and execute: printf "A\e[999C\tB" This outputs an `A`, then a [`CUF`](https://vt100.net/docs/vt510-rm/CUF.html) sequence to move the cursor position to the end of the line, then a `TAB` control character, and finally a `B`. # Expected behavior When in VT mode, a `TAB` character should not move the cursor position past the end of the line, so the `B` should be output on the same line as the `A`, in the last column. Here's what the above test case looks like in XTerm: ![image](https://user-images.githubusercontent.com/4181424/66706863-75147980-ed30-11e9-849c-57e43a225c01.png) # Actual behavior The `TAB` moves the cursor position onto the start of the next line, so the `B` is output below the `A`. This is what the test case looks like in the Windows console: ![image](https://user-images.githubusercontent.com/4181424/66706870-7a71c400-ed30-11e9-97f5-7774070c1d62.png) # Proposed fix In the `SCREEN_INFORMATION::GetForwardTab` method, simply get rid of the first condition that checks for the cursor being in the last column. See here: https://github.com/microsoft/terminal/blob/82dd0b978ae74771b5e9049bbbc6d5ff6c1581aa/src/host/screenInfo.cpp#L2222-L2230 That case should be handled by the second condition (any X pos greater than or equal to the last tab stop will be set to the last column). The change shouldn't have any effect on legacy code, because the `GetForwardTab` method is only used in VT mode, as far as I can tell - the legacy tab handling is a completely separate implementation. I'd be happy to provide a PR for this if nobody disagrees with the suggested fix.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4423