tonerdo / readline

A Pure C# GNU-Readline like library for .NET/.NET Core
MIT License
810 stars 77 forks source link

Add option to return CTRL+C (^C) #59

Closed kenbailey closed 4 years ago

kenbailey commented 4 years ago

Add ability to retrieve the console cancel event from ReadLine instead of exiting application.

Latency commented 4 years ago

The official GNU documentation mirrored at a site here does not describe Ctrl+C or Ctrl+Break being a feature of the ReadLine library.

This is typical of bash/(t)csh/sh/etc. shells on POSIX based platforms which use VT100/VT102 emulation. Hence, Ctrl+Z suspends the process and reverts back to the shell typically if launched from console.

For C# according to MSDN found here the Ctrl+Z returns null, enabling the user to prevent further keyboard input when the ReadLine method is called in a loop.

However, our implementation uses ReadKey() to loop each character within its input rather than process the whole line as a string. The functionality would need to revert to the documentation for ReadKey(), which to prevent ending if CTL+C is pressed Console.TreatControlCAsInput = true;

In conclusion, overriding any of these features would be contingent upon platform specific use and the terminals used to control the process.

'RuntimeInformation' for determining operating systems was integrated after .NET v4.7 and Core 2.x / STD and would need explicit handling to support target builds prior to these versions.

However, I will see what I can do with the feature request, but it appears I may only be curring in Ctrl+Z in for its use case in which case Ctrl+C would be redundant.

As it stands, TreatControlCAsInput is default and should behave as described below:


The value of the TreatControlCAsInput property is false and Ctrl+C is pressed, the pressed keys are not stored in the input buffer and the operating system terminates the currently executing process. This is the default value.

Caution

Use this property judiciously because setting it to true has such a dramatic effect. Most users expect Ctrl+C to terminate a console application. If you disable the effect of Ctrl+C, the user must remember to use Ctrl+Break to terminate the application, which is a less familiar key combination.

Latency commented 4 years ago

Patched v2.1.3

kenbailey commented 4 years ago

Thanks @Latency, good information. It looks like what I was trying to do might be able to be covered by TreatControlCAsInput. I'll close this pull request as it isn't a good fit.

I'll check out your fork though. Are you publishing a public NuGet package with your fork? I'm only seeing @tonerdo and @rubberduck203 on NuGet.

Latency commented 4 years ago

Correct.. the NuGet package is found within the "\Artifacts\" folder on my fork. Only Tonerdo can merge the PR's and hasn't turned over privileges for me to take over this repo.

For me to publish the repo on my own, would mean that I would need to create a new name for the same repo. This is a community project and there is no need be another rubberduck.

rubberduck203 commented 4 years ago

I take extreme offense at your comment. I needed a feature that was not available, so I added it and published the fix for consumption. That is the heart and soul of libre software.

Latency commented 4 years ago

@rubberduck203

Your changes were added into my fork way back when. I do my best to help the community.