ConPTY adds extra newlines symbols at soft-wrapped rows #19599

Closed
opened 2026-01-31 06:48:20 +00:00 by claunia · 5 comments
Owner

Originally created by @Mervap on GitHub (Mar 29, 2023).

Windows Terminal version

Not installed

Windows build number

10.0.19045.2788

Other Software

.NET 7.0 x64

Steps to reproduce

  1. Create ConPTY from dotnet (minimized version below, full working code here, based on samples/GUIConsole.ConPTY)
  2. Run powershell.exe
  3. Send 500 'a' charachters to PTY input (as a single row)
  4. Read 500 charachters from PTY output
SafeFileHandle inputRead, inputWrite, outputRead, outputWrite;

CreatePseudoConsole(new COORD { X = 40, Y = 20 }, inputRead, outputWrite, 0, out IntPtr hPC);
ProcessFactory.Start("powershell.exe -nologo", 0x00020016, hPC);

var writer = new StreamWriter(new FileStream(inputWrite, FileAccess.Write)) { AutoFlush = true };
var reader = new StreamReader(new FileStream(outputRead, FileAccess.Read));


// Write long row
writer.Write(new string('a', 500));

// Read output
char[] buf = new char[500];
var bytesRead = reader.ReadBlock(buf, 0, 500);
var output = new string(buf.Take(bytesRead).ToArray());

// Check output
// Expected: zero '\n' characters
// Actual: a lot of '\n' characters
Console.Out.Write(output.Split('\n').Length);

Expected Behavior

Pty output contains zero newlines symbols since only one line was sent

Actual Behavior

PTY adds extra \n to output turning soft-wrapping to hard-wrapping

Originally created by @Mervap on GitHub (Mar 29, 2023). ### Windows Terminal version Not installed ### Windows build number 10.0.19045.2788 ### Other Software .NET 7.0 x64 ### Steps to reproduce 1) Create ConPTY from dotnet (minimized version below, full working code [here](https://github.com/microsoft/terminal/files/11099336/Wrap.zip), based on `samples/GUIConsole.ConPTY`) 2) Run `powershell.exe` 3) Send 500 `'a'` charachters to PTY input (as a single row) 4) Read 500 charachters from PTY output ```c# SafeFileHandle inputRead, inputWrite, outputRead, outputWrite; CreatePseudoConsole(new COORD { X = 40, Y = 20 }, inputRead, outputWrite, 0, out IntPtr hPC); ProcessFactory.Start("powershell.exe -nologo", 0x00020016, hPC); var writer = new StreamWriter(new FileStream(inputWrite, FileAccess.Write)) { AutoFlush = true }; var reader = new StreamReader(new FileStream(outputRead, FileAccess.Read)); // Write long row writer.Write(new string('a', 500)); // Read output char[] buf = new char[500]; var bytesRead = reader.ReadBlock(buf, 0, 500); var output = new string(buf.Take(bytesRead).ToArray()); // Check output // Expected: zero '\n' characters // Actual: a lot of '\n' characters Console.Out.Write(output.Split('\n').Length); ``` ### Expected Behavior Pty output contains **zero** newlines symbols since only one line was sent ### Actual Behavior PTY adds extra `\n` to output turning soft-wrapping to hard-wrapping
claunia added the Resolution-Fix-AvailableArea-OutputIssue-BugProduct-Conpty labels 2026-01-31 06:48:21 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Mar 29, 2023):

Thanks for the report! I suspect this is fixed in main, but I'm gonna leave this open to validate that either there's already a test for it, or if not, to add one.

If it is fixed in main, then I'm betting it's only fixed in >22000 builds of Windows.

If it's not fixed, well, it should be ☺️

@zadjii-msft commented on GitHub (Mar 29, 2023): Thanks for the report! I suspect this is fixed in `main`, but I'm gonna leave this open to validate that either there's already a test for it, or if not, to add one. If it is fixed in `main`, then I'm betting it's only fixed in >22000 builds of Windows. If it's _not_ fixed, well, it should be ☺️
Author
Owner

@Mervap commented on GitHub (Mar 29, 2023):

Ok, thanks!
Any chance that it would be fixed in win10?

@Mervap commented on GitHub (Mar 29, 2023): Ok, thanks! Any chance that it would be fixed in win10?
Author
Owner

@zadjii-msft commented on GitHub (Mar 29, 2023):

Probably not, though, our recommendation is going to be using a nuget package to ingest ConPTY. This nuget package doesn't exist yet1 , but when it does, that'll let you use the latest version of ConPTY regardless of what OS version you're on. That's effectively what the Terminal does today (so that we can use ConPTY fixes even on Windows 10). I think there's other folks that have copied what we've done, but that's firmly in the "not yet officially supported" territory.


  1. Originally, this was tracked in #3577, but apparently we have no thread for "productize the conpty nuget" and we should. I'll take a todo item to create one. ↩︎

@zadjii-msft commented on GitHub (Mar 29, 2023): Probably not, though, our recommendation is going to be using a nuget package to ingest ConPTY. This nuget package doesn't exist yet[^1], but when it does, that'll let you use the latest version of ConPTY regardless of what OS version you're on. That's _effectively_ what the Terminal does today (so that we can use ConPTY fixes even on Windows 10). I think there's other folks that have copied what we've done, but that's firmly in the "not yet officially supported" territory. [^1]: Originally, this was tracked in #3577, but apparently we have no thread for "productize the conpty nuget" and _we should_. I'll take a todo item to create one.
Author
Owner

@zadjii-msft commented on GitHub (Mar 29, 2023):

addenda: now tracking that in #15065

@zadjii-msft commented on GitHub (Mar 29, 2023): addenda: now tracking that in #15065
Author
Owner

@zadjii-msft commented on GitHub (May 5, 2023):

Yep, we definitely already had a test for this one:

10c6206bfe/src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp (L451-L500)

So, I'll just say "fixed in the latest conpty, but that's probably not on Windows 10, so we'll need to start shipping a conpty nuget that folks can consume externally"

@zadjii-msft commented on GitHub (May 5, 2023): Yep, we definitely already had a test for this one: https://github.com/microsoft/terminal/blob/10c6206bfef7d045347327687266832931f47eb6/src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp#L451-L500 So, I'll just say "fixed in the latest conpty, but that's probably not on Windows 10, so we'll need to start shipping a conpty nuget that folks can consume externally"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19599