[PR #260] Add csharp conpty sample #24096

Open
opened 2026-01-31 09:01:22 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/260

State: closed
Merged: Yes


As I mentioned in https://github.com/Microsoft/console/issues/251, I've been working on a basic C# terminal that uses the new PseudoConsole APIs. It's at a point where I've fixed all the known bugs, and I think it could be a useful sample in this repo.

The demo is similar to the existing EchoCon example in that it uses the virtual terminal processing feature, starts up a pseudoconsole, and runs a command. It also handles ctrl-c and window exit.

I'd appreciate some advice on ways to improve it as I'm fairly inexperienced when it comes to writing terminals and pinvoking Windows APIs. The following areas might need some attention:

  • Handling when the user types exit. Right now it exits the terminal, when the user might just want to exit whatever the currently running process is. There's a TODO marking that area. Completed this, now we wait for the top-level process to exit.
  • I've used the .NET SafeFileHandle class in place of some of the IntPtrs normally found in PInvoke signatures. I'm not sure what the best practice is here.

I've split this PR into three commits, the final commit will be the most interesting to review.

I've tested this with the following versions:

  • OS: Windows 10 Pro Build 17744
  • SDK: Windows_InsiderPreview_SDK_en-us_17749

Thanks!

**Original Pull Request:** https://github.com/microsoft/terminal/pull/260 **State:** closed **Merged:** Yes --- As I mentioned in https://github.com/Microsoft/console/issues/251, I've been working on a basic C# terminal that uses the new PseudoConsole APIs. It's at a point where I've fixed all the known bugs, and I think it could be a useful sample in this repo. The demo is similar to the existing EchoCon example in that it uses the virtual terminal processing feature, starts up a pseudoconsole, and runs a command. It also handles ctrl-c and window exit. I'd appreciate some advice on ways to improve it as I'm fairly inexperienced when it comes to writing terminals and pinvoking Windows APIs. The following areas might need some attention: - [x] ~Handling when the user types `exit`. Right now it exits the terminal, when the user might just want to exit whatever the currently running process is. There's a TODO marking that area.~ Completed this, now we wait for the top-level process to exit. - [ ] I've used the .NET SafeFileHandle class in place of some of the IntPtrs normally found in PInvoke signatures. I'm not sure what the best practice is here. I've split this PR into three commits, the final commit will be the most interesting to review. I've tested this with the following versions: - OS: Windows 10 Pro Build 17744 - SDK: Windows_InsiderPreview_SDK_en-us_17749 Thanks!
claunia added the pull-request label 2026-01-31 09:01:22 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#24096