[PR #260] [MERGED] Add csharp conpty sample #24091

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/260
Author: @waf
Created: 9/20/2018
Status: Merged
Merged: 10/4/2018
Merged by: @miniksa

Base: masterHead: add-csharp-conpty-sample


📝 Commits (6)

  • 0884a1b add project infrastructure (sln, csproj, readme, etc)
  • e093591 add pinvoke signatures
  • 637c574 add c# files
  • bf32b8d implement dispose pattern
  • 3a1ee61 fix exit behavior
  • 08b436f move Process and ProcessFactory classes into separate files

📊 Changes

14 files changed (+740 additions, -0 deletions)

View changed files

samples/ConPTY/MiniTerm/MiniTerm.sln (+25 -0)
samples/ConPTY/MiniTerm/MiniTerm/App.config (+6 -0)
samples/ConPTY/MiniTerm/MiniTerm/MiniTerm.csproj (+60 -0)
samples/ConPTY/MiniTerm/MiniTerm/Native/ConsoleApi.cs (+38 -0)
samples/ConPTY/MiniTerm/MiniTerm/Native/ProcessApi.cs (+86 -0)
samples/ConPTY/MiniTerm/MiniTerm/Native/PseudoConsoleApi.cs (+33 -0)
samples/ConPTY/MiniTerm/MiniTerm/Processes/Process.cs (+74 -0)
samples/ConPTY/MiniTerm/MiniTerm/Processes/ProcessFactory.cs (+98 -0)
samples/ConPTY/MiniTerm/MiniTerm/Program.cs (+35 -0)
samples/ConPTY/MiniTerm/MiniTerm/Properties/AssemblyInfo.cs (+36 -0)
samples/ConPTY/MiniTerm/MiniTerm/PseudoConsole.cs (+39 -0)
samples/ConPTY/MiniTerm/MiniTerm/PseudoConsolePipe.cs (+46 -0)
samples/ConPTY/MiniTerm/MiniTerm/Terminal.cs (+145 -0)
samples/ConPTY/MiniTerm/README.md (+19 -0)

📄 Description

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!


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/260 **Author:** [@waf](https://github.com/waf) **Created:** 9/20/2018 **Status:** ✅ Merged **Merged:** 10/4/2018 **Merged by:** [@miniksa](https://github.com/miniksa) **Base:** `master` ← **Head:** `add-csharp-conpty-sample` --- ### 📝 Commits (6) - [`0884a1b`](https://github.com/microsoft/terminal/commit/0884a1bb1da8af789977c18631c0715f00441929) add project infrastructure (sln, csproj, readme, etc) - [`e093591`](https://github.com/microsoft/terminal/commit/e09359138ee3c8abe4854224db26771c484c38cf) add pinvoke signatures - [`637c574`](https://github.com/microsoft/terminal/commit/637c57473e923e5185c79c0b7d72beacf894be62) add c# files - [`bf32b8d`](https://github.com/microsoft/terminal/commit/bf32b8d48f16b238aa5cb2044efc4b612f1ade2d) implement dispose pattern - [`3a1ee61`](https://github.com/microsoft/terminal/commit/3a1ee614764ab31732df1823aeb719b3c4d2eae5) fix exit behavior - [`08b436f`](https://github.com/microsoft/terminal/commit/08b436f1a5a59533b3852e93b68f1777c28c7b18) move Process and ProcessFactory classes into separate files ### 📊 Changes **14 files changed** (+740 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `samples/ConPTY/MiniTerm/MiniTerm.sln` (+25 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/App.config` (+6 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/MiniTerm.csproj` (+60 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/Native/ConsoleApi.cs` (+38 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/Native/ProcessApi.cs` (+86 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/Native/PseudoConsoleApi.cs` (+33 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/Processes/Process.cs` (+74 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/Processes/ProcessFactory.cs` (+98 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/Program.cs` (+35 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/Properties/AssemblyInfo.cs` (+36 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/PseudoConsole.cs` (+39 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/PseudoConsolePipe.cs` (+46 -0) ➕ `samples/ConPTY/MiniTerm/MiniTerm/Terminal.cs` (+145 -0) ➕ `samples/ConPTY/MiniTerm/README.md` (+19 -0) </details> ### 📄 Description 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! --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:01:21 +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#24091