The CursorTop position within 2 of the BufferHeight limit is incorrect #8032

Closed
opened 2026-01-31 01:19:03 +00:00 by claunia · 3 comments
Owner

Originally created by @rmaclean on GitHub (May 8, 2020).

Environment

Windows build number: 10.0.18363.778
Windows Terminal version (if applicable): 0.11.1251.0

Any other software? Reproducible in a variety of shells within Windows Terminal. Tested with: Fish Shell, cmd and Powershell. Can also test with VT 100 commands

Steps to reproduce

Set the cursor top to within 2 lines of the BufferHeight. For example, if the BufferHeight is 30, you could use echo -e "\e[29;0fHello"

Another option is with C#, this should print Hey on the same line each time:

Console.Clear();
Console.WriteLine($"BufferHeight: {Console.BufferHeight}");
var y = Console.BufferHeight - 1;
for (int i = 0; i < 10; i++)
{
  Console.SetCursorPosition(i, y);
  Console.WriteLine($"Hey {i} - {Console.CursorTop} / {Console.BufferHeight}");
  Thread.Sleep(200);
}

Expected behaviour

It should print to the specified row. In the VT 100 example, it should be printed without moving the screen and with the C# example, it should print Hey on each line, producing this at the end of the code HHHHHHHHHHey 9 - 27 / 30.

This is the behaviour in Command Prompt as well in Terminal on OSX.

Actual behaviour

Moves the content up one and writes to the screen, as if we were exceeding the height of the BufferHeight.

For the C# you will get an output like this:

Hey 0 - 29 / 30
 Hey 1 - 29 / 30
  Hey 2 - 29 / 30
   Hey 3 - 29 / 30
    Hey 4 - 29 / 30
     Hey 5 - 29 / 30
      Hey 6 - 29 / 30
       Hey 7 - 29 / 30
        Hey 8 - 29 / 30
         Hey 9 - 29 / 30

Workaround

Best I have found in my own code is to assume the BufferHeight is 2 shorter than it is and readjust the cursor position that way but it does break other CLI code which does not take this into account.

Originally created by @rmaclean on GitHub (May 8, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: 10.0.18363.778 Windows Terminal version (if applicable): 0.11.1251.0 Any other software? Reproducible in a variety of shells within Windows Terminal. Tested with: Fish Shell, cmd and Powershell. Can also test with VT 100 commands ``` # Steps to reproduce Set the cursor top to within 2 lines of the BufferHeight. For example, if the BufferHeight is 30, you could use `echo -e "\e[29;0fHello"` Another option is with C#, this should print `Hey` on the same line each time: ```csharp Console.Clear(); Console.WriteLine($"BufferHeight: {Console.BufferHeight}"); var y = Console.BufferHeight - 1; for (int i = 0; i < 10; i++) { Console.SetCursorPosition(i, y); Console.WriteLine($"Hey {i} - {Console.CursorTop} / {Console.BufferHeight}"); Thread.Sleep(200); } ``` # Expected behaviour It should print to the specified row. In the VT 100 example, it should be printed without moving the screen and with the C# example, it should print `Hey` on each line, producing this at the end of the code `HHHHHHHHHHey 9 - 27 / 30`. This is the behaviour in Command Prompt as well in Terminal on OSX. # Actual behaviour Moves the content up one and writes to the screen, as if we were exceeding the height of the BufferHeight. For the C# you will get an output like this: ```none Hey 0 - 29 / 30 Hey 1 - 29 / 30 Hey 2 - 29 / 30 Hey 3 - 29 / 30 Hey 4 - 29 / 30 Hey 5 - 29 / 30 Hey 6 - 29 / 30 Hey 7 - 29 / 30 Hey 8 - 29 / 30 Hey 9 - 29 / 30 ``` # Workaround Best I have found in my own code is to assume the BufferHeight is 2 shorter than it is and readjust the cursor position that way but it does break other CLI code which does not take this into account.
claunia added the Needs-TriageNeeds-Tag-FixNeeds-Attention labels 2026-01-31 01:19:03 +00:00
Author
Owner

@DHowett-MSFT commented on GitHub (May 8, 2020):

Doesn’t WriteLine append a newline, thus pushing the contents of the screen up? That seems critically important to avoid if you care about having the buffer stay in the same place...

@DHowett-MSFT commented on GitHub (May 8, 2020): Doesn’t `WriteLine` append a newline, thus pushing the contents of the screen up? That seems critically important to _avoid_ if you care about having the buffer stay in the same place...
Author
Owner

@DHowett-MSFT commented on GitHub (May 8, 2020):

So, it looks like this reproduces on a conhost instance (without Terminal) where the buffer size is the same as the window size. If you fix the C# reproducer to not include the extra newline (which pushes the entire buffer up, unequivocally, as that's what it's supposed to do) it works fine.

Incidentally, if I take the C# repro and run it on Linux inside xterm (our reference implementation for how terminals should work), I get...

image

I'm very close to calling this one "By Design"

@DHowett-MSFT commented on GitHub (May 8, 2020): So, it looks like this reproduces on a conhost instance (without Terminal) where the buffer size is the same as the window size. If you _fix_ the C# reproducer to not include the extra newline (which pushes the entire buffer up, unequivocally, as that's what it's supposed to do) it works fine. Incidentally, if I take the C# repro and run it on Linux inside xterm (our reference implementation for how terminals should work), I get... ![image](https://user-images.githubusercontent.com/14316954/81443187-cf8c8180-9129-11ea-9c02-d22bd9ac31b9.png) I'm very close to calling this one "By Design"
Author
Owner

@rmaclean commented on GitHub (May 10, 2020):

Thanks, that is definitely my misunderstanding then. Thank you

@rmaclean commented on GitHub (May 10, 2020): Thanks, that is definitely my misunderstanding then. Thank you
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8032