tonerdo / readline

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

ReadLine.Read is not working in MingW64 #55

Open signityvivek opened 5 years ago

signityvivek commented 5 years ago

I tried to use the our tool on Windows 7 system in a MINGW64 terminal (that is installed when I installed Git client to access github).

Unhandled Exception: System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.
   at System.ConsolePal.ReadKey(Boolean intercept)
   at System.ReadLine.GetText(KeyHandler keyHandler)
   at System.ReadLine.Read(String prompt, String default)
   at Campaign.Program.RunAddAndReturnExitCode(Options options)

A little googling efforts directed me to run it on the default command prompt and it worked like a charm.

Please guide, if there is any configuration required for the same. Thanks

webmaster442 commented 4 years ago

MinGW64's MinTTTY is a TTY emulator. It doesn't support Windows console API's out of the box. You need to run your program wrapped in winpty. Example:

winpty yourexe.exe
Latency commented 4 years ago

The console emulators will vary across platforms. We will NOT support emulation related issues.

This API uses Console.ReadKey() for its internals which essentially does what Console.Read() does anyway minus a few things windows platform specific. These are from the .NET framework and should be compatible where supported versions of the .NET run-times exist.

You can try using the API within a project targeting .NET Core and run it from the console. This should be universal across platforms. Let me know your feedback.