Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Console CursorTop is not calculated as same as native windows cmd #10063

Closed
MohammadMD1383 opened this issue May 9, 2021 · 7 comments
Closed
Labels
Issue-Question For questions or discussion Product-Terminal The new Windows Terminal. Resolution-By-Design It's supposed to be this way. Sometimes for compatibility reasons. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@MohammadMD1383
Copy link

Windows Terminal version (or Windows build number)

Windows10 - 20H2 - 19042.964

Other Software

No response

Steps to reproduce

  1. write this program in c#
using System;
using static System.Console;

namespace ConsoleApp
{
	internal static class Program
	{
		public static void Main()
		{
			Write("Hello World");
			ClearLine(CursorTop);
			SetCursorPosition(0, CursorTop - 1); // exception here
		}

		private static void ClearLine(int lineNumber)
		{
			SetCursorPosition(0, lineNumber);
			Write("".PadRight(WindowWidth));
		}
	}
}
  1. compile
  2. run it from windows terminal powershell using .\ConsoleApp.exe

Expected Behavior

it should fill the current line with white space and then because the white spaces count is equal to windows width, after the last white space the cursor should move to next line
then by setting cursor top to cursor top - 1 it shouldn't throw any exception.

I tested this in cmd and powershell and there was no problem.

Actual Behavior

after last white space cursor doesn't go to next line so it throws exception.
image

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels May 9, 2021
@LuanVSO
Copy link
Contributor

LuanVSO commented May 9, 2021

then by setting cursor top to cursor top - 1 it shouldn't throw any exception.

it should if cursortop ==0

reflow only enters in action if you print WindowWidth+1 [1], if you print only windowWidth the cursor will remain in the same line, and if that line is 0, you will try to decrement it, which will result in -1 which is not a valid line number hence the error.

[1]: if console reflow is actually enabled that is

@MohammadMD1383
Copy link
Author

@LuanVSO I tested in cmd and powershell (their own window) and after printing space in count of windowWidth the cursor moved to next line

@zadjii-msft zadjii-msft added Product-Terminal The new Windows Terminal. Issue-Question For questions or discussion labels May 10, 2021
@LuanVSO
Copy link
Contributor

LuanVSO commented May 10, 2021

ok so, for me if i print WindowWidth in windows terminal the line doesn't wrap, but on conhost it does.

@j4james
Copy link
Collaborator

j4james commented May 10, 2021

This is probably because Windows Terminal has ENABLE_VIRTUAL_TERMINAL_PROCESSING on by default, while conhost has it disabled. So in Windows Terminal you get the delayed wrap effect expected by VT applications, while in conhost the wrap will occur as soon as a character is output in the last column.

@DHowett
Copy link
Member

DHowett commented May 13, 2021

Yep, James has the right of it here. For an application that relies on specific console modes being set (sorry- line wrapping behavior unfortunately requires specific modes) our recommendation is that it set those modes on startup.

@DHowett DHowett closed this as completed May 13, 2021
@DHowett DHowett added Resolution-By-Design It's supposed to be this way. Sometimes for compatibility reasons. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels May 13, 2021
@DHowett
Copy link
Member

DHowett commented May 13, 2021

OH, And there's a great discussion about this in /dup #8312

@ghost
Copy link

ghost commented May 13, 2021

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Tag-Fix Doesn't match tag requirements labels May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question For questions or discussion Product-Terminal The new Windows Terminal. Resolution-By-Design It's supposed to be this way. Sometimes for compatibility reasons. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

5 participants